Results 1 to 8 of 8
Thread: Axis Response | Write to file?
- 07-03-2012, 11:20 PM #1
Senior Member
- Join Date
- Apr 2012
- Posts
- 127
- Rep Power
- 0
Axis Response | Write to file?
Hello, i've been searching and searching online and can't seem to find anything helpful...
I have used Apache Axis2's wsdl2java program to generate a bunch of code from a wsdl. I can make the call to the API successfully, and in the included log4j output debug I can see the XML response... however I"m having a very tough time figuring out how to work with this XML so that I can parse it and use it in the rest of my program. I really need to either write this response to an actual XML file on my computer, or figure out how to work with it in memory so I can parse it and enter values into my database.
some code:
when I make the System.out.println(); call I just get a partial string that is not relevant nor is it the same output as the logger is spitting out.Java Code:package com._3dcart; import java.rmi.RemoteException; import org.apache.axis2.AxisFault; import org.apache.axis2.databinding.ADBException; import java.io.*; public class GetOrders { public static void main(String[] args) { try { CartAPIStub jdbCart = new CartAPIStub(); CartAPIStub.GetOrder request = new CartAPIStub.GetOrder(); request.setStoreUrl("WEBSITE_URL"); request.setUserKey("ACCESS_KEY"); request.setBatchSize(1); request.setStartNum(1); request.setStartFrom(false); request.setDateFrom("07/01/2012"); CartAPIStub.GetOrderResponse response = jdbCart.getOrder(request); String xmlCallback = response.getGetOrderResult().toString(); System.out.println("Response: " + xmlCallback); } catch (AxisFault e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } } }
Thanks for any assistance or for pointing me in the right direction. If you need some of the code that was auto-generated, just let me know... I didn't post it since its very very long lol (almost 27,000 lines in the Stub Class).
- 07-04-2012, 09:48 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: Axis Response | Write to file?
Why do you need to access the actual XML?
You have a JAXB object that models the data in it in the form of the 'response' surely?
Is there any other data, other than that held by the response, that you want to store?Please do not ask for code as refusal often offends.
- 07-05-2012, 05:09 PM #3
Senior Member
- Join Date
- Apr 2012
- Posts
- 127
- Rep Power
- 0
Re: Axis Response | Write to file?
Tolls to my rescue again! lol...
I'm really not all that familiar with the axis2 process or working with SOAP in general... this is my first. If the data is stored in my response object, how do i access it to extract data I need to permanently store? I'm using eclipse so it gives me some auto-completes, but none of the methods for my response object seem to really pertain to pulling the data out.
the only one that i've seen that looks sort-of relevant is the getOMElement() method that is asking for me to input a "parentQName" and "factory"... although i'm not sure if this is on the right track or not, nor do I know what QName is (is this just a node name?).
Am I on the right track? any guidance is much appreciated!
also, as a side note, if there is any way to pull the XML reponse and write it to a file, that would still be awesome even if i was able to get the data out without needing to do that... would be good for record keeping for a month or two to keep the xml response around.... also for debugging. Although, its sounding more like pulling the entire XML response isn't really possible due to how its being handled (into an object, not just a document in memory) so I'd have to recontruct the XML in memory after extracting data, which would kind of be a waste of time i guess... is my thinking ok here as well? thanks!
- 07-05-2012, 05:45 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: Axis Response | Write to file?
It's been a while since I last did Axis, but there should be a getter there to get whatever top level attribute the response has, under which should be the rest of the structure.
Imagine the response object modelling the XML payload in the SOAP message exactly (down to the names for the elements)...that's all JAXB does.Please do not ask for code as refusal often offends.
- 07-05-2012, 05:47 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: Axis Response | Write to file?
Oh yes, if you want the raw xml then try googling for Handlers.
You can define a handler chain both on the outgoing message and on the incoming one that should allow you to grab the raw xml.
I seem to remember doing that myself in order to do some transforming before the message was turned into a Response object.Please do not ask for code as refusal often offends.
- 07-06-2012, 12:12 AM #6
Senior Member
- Join Date
- Apr 2012
- Posts
- 127
- Rep Power
- 0
Re: Axis Response | Write to file?
hmm... i've been researching all day and still can't seem to make much progress on this (head hurts!). Can't figure out how to work with this JAXB object, if thats what i'm supposed to be working with. When i make hte call to the API, i just issue a command that includes my parameters, but don't see a way to work with it as a response object or anything. I googled the hell out of axis2, axis, parsing axis response, etc. and have read a bunch of things, but nothing seems to quite apply to my situation... possibly since all axis code is different (generated by WSDL).
soooo, this leads me to another question perhaps... is there an easier way to do a simple SOAP client? I really really just need a simple way to work with the response data, either in an actual file written to the hard disk (and read back in as XML and parsed) or work with it easily in memory so i can input values into my database. This axis was supposed to be easy i thiough and so far its driving me up the wall!! lol.
Its double frustrating because I can see in my log4j output that it is making the call correctly and receiving my expected response (all the data in a valid XML format) that I need, but I just smiply cannot figure out how to grab that data (using a handler of some sort) or work with whatever response object has been created...
any suggestions are greatly appreciated... its been a long day for me...
EDIT: oh... and i'm using JDK 7 SE if that matters... A lot of stuff i read pertains to EE but since I can make the API call successfully with SE, my thoughts are the EE isn't needed?
Updated code i'm using:
Java Code:package com._3dcart; import java.rmi.RemoteException; import javax.xml.namespace.QName; import org.apache.axiom.om.OMFactory; import org.apache.axis2.AxisFault; import org.apache.axis2.databinding.ADBException; import java.io.*; public class GetOrders { public static void main(String[] args) { try { CartAPIStub jdbCart = new CartAPIStub(); jdbCart.getOrder("www.WEBSITENAME.com", "ACCESS_KEY", 100, 1, false, "", "", "07/05/2012", "", ""); System.out.println("finished"); } catch (AxisFault e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }Last edited by SnakeDoc; 07-06-2012 at 12:19 AM.
- 07-06-2012, 09:25 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: Axis Response | Write to file?
Presumably getOrder() returns something?
That something would be the response.Please do not ask for code as refusal often offends.
- 07-06-2012, 08:55 PM #8
Senior Member
- Join Date
- Apr 2012
- Posts
- 127
- Rep Power
- 0
Re: Axis Response | Write to file?
finally!!!!!!!
should not have been this difficult to get this result in my opinion... seemed like nobody had a real answer on how to work with the response (which is some strange Type of getOrderResponse_type0 ??? wtf?)... and i guess it was assumed you knew how to work with it... but i guess the wsdl i was working with and generated code from was not standard since a lot of people seemed to be able to just use something like:
but of course that only returned garbage for me... :(Java Code:System.out.println(response.getOrderResult());
final code that now gives me a workable string so i can write to a file for logging/archiving responses and then parse the results and work with data..
Java Code:package jdbGetOrders; import java.rmi.RemoteException; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apache.axiom.soap.SOAPFactory; import org.apache.axis2.AxisFault; import org.apache.axis2.databinding.ADBException; public class FetchOrders { public static void main(String[] args) { try { // constructors com._3dcart.CartAPIStub stub = new com._3dcart.CartAPIStub(); com._3dcart.CartAPIStub.GetOrder request = new com._3dcart.CartAPIStub.GetOrder(); // form request parameters request.setStoreUrl("WEBSITE_URL"); request.setUserKey("ACCESS_KEY"); request.setBatchSize(100); request.setStartNum(1); request.setStartFrom(false); request.setDateFrom("07/05/2012"); // build response com._3dcart.CartAPIStub.GetOrderResponse response = stub.getOrder(request); // THIS IS THE PART THAT CONVERTS TO WORKABLE OBJECT // format response to workable object SOAPFactory factory = OMAbstractFactory.getSOAP12Factory(); OMElement requestElement = response.getOMElement(com._3dcart.CartAPIStub.GetOrderResponse.MY_QNAME, factory); // debug // print on console the result of API call System.out.println(""); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println(requestElement); } catch (AxisFault e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } catch (ADBException e) { e.printStackTrace(); } } }Last edited by SnakeDoc; 07-06-2012 at 08:58 PM.
Similar Threads
-
PDF to JPEG in memory(on the fly)nd write the response stream obj directly on browser
By vipinarora2009 in forum Advanced JavaReplies: 2Last Post: 02-28-2012, 08:49 PM -
multiple response parameters in apache axis are not all not returned
By rude056 in forum Web FrameworksReplies: 4Last Post: 10-01-2010, 10:52 AM -
Reg:How to write xsl for an response soap object of webservice and then transver to h
By narayana@gmail.com in forum New To JavaReplies: 0Last Post: 03-02-2010, 08:07 AM -
write http response into file?
By DaBernie in forum NetworkingReplies: 3Last Post: 10-10-2009, 11:21 PM -
append response to the request from Socket and write to another socket
By vaibhav_singh_vs@yahoo.co in forum NetworkingReplies: 3Last Post: 04-17-2009, 07:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks