Hello,
I am using ofbiz 12.04.02 I tried to create services (java,groovy...) and I was perfectly able to call them and use them. I was also able to call services from other services. Everything is fine and I am able to run them from web tools as well as accessing them through a uri (defined in a request-map). My only problem is with calling external SOAP services from Ofbiz. I am defining my service like that: <service name="jadGeoIP" engine="soap" export="true" location="http://www.webservicex.net/geoipservice.asmx?WSDL" invoke="GetGeoIP"> <description>A service to invoke the GeoIP web service</description> <namespace>http://www.webservicex.net/</namespace> <attribute name="IPAddress" type="String" mode="IN"/> <attribute name="CountryName" type="String" mode="OUT"/> </service> But it's not working. I am trying to run it through web tool, and giving it the required input but the error I get is the following: "Service dispatcher threw an exception:Service did not return expected result" I tried calling the web service from SoapUI, and I it is perfectly working! I am now sure that when using Ofbiz, my SOAP message is being sent. Because at least I am receiving back the following message: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <Response xmlns="http://ofbiz.apache.org/service/"> <map-Map> <map-Entry> <map-Key> <std-String value="responseMessage"/> </map-Key> <map-Value> <std-String value="error"/> </map-Value> </map-Entry> <map-Entry> <map-Key> <std-String value="errorMessage"/> </map-Key> <map-Value> <std-String value="Problem processing the service"/> </map-Value> </map-Entry> </map-Map> </Response> </soapenv:Body> </soapenv:Envelope> which means that the problem is with the SOAP message content that is being sent from Ofbiz. Now my question is: is there a way to see the SOAP message contents that are being sent from ofbiz? If yes this would help me a lot in comparing the message with the one being sent from SoapUI.
|
Note: in my controller.xml, I am including this handler
<handler name="soap" type="request" class="org.ofbiz.webapp.event.SOAPEventHandler"/> Thank you for any help!
Jad El Omeiri
|
I believe service should have engine="java" ? export="true" exposes it as
soap implicitly On Tue, Dec 3, 2013 at 2:48 PM, jadelomeiri <[hidden email]>wrote: > Note: in my controller.xml, I am including this handler > *<handler name="soap" type="request" > class="org.ofbiz.webapp.event.SOAPEventHandler"/>* > > Thank you for any help! > > > > -- > View this message in context: > http://ofbiz.135035.n4.nabble.com/calling-external-SOAP-service-from-Ofbiz-tp4646036p4646037.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > -- Thanks, Deepak Agarwal, Mobile: +91 9501190044 |
Administrator
|
In reply to this post by Jad El Omeiri
Actually if you look into services_test.xml you will see that there are issues calling "external" SOAP services.
Though calling testRemoteSoap works calling testRemoteSoap1 and sequel don't. I did not get a chance to continue to work on this and for now I rather call "external" SOAP services directly from source code Jacques On Tuesday, December 03, 2013 10:18 AM jadelomeiri <[hidden email]> wrote: > Note: in my controller.xml, I am including this handler > *<handler name="soap" type="request" > class="org.ofbiz.webapp.event.SOAPEventHandler"/>* > > Thank you for any help! |
Administrator
|
In reply to this post by Jad El Omeiri
BTW forgot, you might be interested by http://hessian.caucho.com/
Jacques On Tuesday, December 03, 2013 11:13 AM Jacques Le Roux <[hidden email]> wrote: > Actually if you look into services_test.xml you will see that there are issues calling "external" SOAP services. > Though calling testRemoteSoap works calling testRemoteSoap1 and sequel don't. > I did not get a chance to continue to work on this and for now I rather call "external" SOAP services directly from source code > > Jacques > > On Tuesday, December 03, 2013 10:18 AM jadelomeiri <[hidden email]> wrote: >> Note: in my controller.xml, I am including this handler >> *<handler name="soap" type="request" >> class="org.ofbiz.webapp.event.SOAPEventHandler"/>* >> >> Thank you for any help! |
In reply to this post by Deepak Agarwal-2
Dear Deapak,
What you are saying is true if you're creating a service and want it to be accessible via SOAP to other clients. But in my case I only want to consume a web service. Thanks anyways! Regards Jad
Jad El Omeiri
|
In reply to this post by Jacques Le Roux
Dear Jacques,
Thanks a lot for your reply. I was thinking about writing a separate java code using axis2, test it, and then integrate it in Ofbiz. Because of your reply I am convinced to go with that solution. Another thank you also for the link you provided me with. I will also check it. Hopefully I will post my solution when it works. Cheers, Jad
Jad El Omeiri
|
In reply to this post by Jacques Le Roux
Hello,
This is the solution I finally got. I hope it will be helpful for people having the same problem as I had. 1) In my events java class I wrote the following code (which is an event calling the method that deals with SOAP): public static String callMySoap(HttpServletRequest request,HttpServletResponse response) { request.setAttribute("_EVENT_MESSAGE_", "You received this SOAP response:" + MySoapClient()); return "success"; } public static SOAPMessage MySoapClient() { try { // Create SOAP Connection SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // Send SOAP Message to SOAP Server String url = "http://www.webservicex.net/geoipservice.asmx"; SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url); soapConnection.close(); return soapResponse; } catch (Exception e) { System.err.println("Error occurred while sending SOAP Request to Server"); e.printStackTrace(); return null; } } private static SOAPMessage createSOAPRequest() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = "http://www.webservicex.net/"; // SOAP Envelope SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("web", serverURI); /* Constructed SOAP Request Message: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://www.webservicex.net/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <web:GetGeoIP> <web:IPAddressl>192.168.1.2</web:IPAddress> </web:GetGeoIP> </SOAP-ENV:Body> </SOAP-ENV:Envelope> */ // SOAP Body SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("GetGeoIP", "web"); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("IPAddress", "web"); soapBodyElem1.addTextNode("192.168.1.2"); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", serverURI + "GetGeoIP"); soapMessage.saveChanges(); /* Print the request message */ System.out.print("Request SOAP Message = "); soapMessage.writeTo(System.out); System.out.println(); return soapMessage; } 2) I added the following request-map to point to my event: <request-map uri="callMySoap"> <event type="java" path="org.ofbiz.testapp.testapp.LearningEvents" invoke="callMySoap"/> <response name="success" type="view" value="FeedbackMessages"/> </request-map> 3) I added the following view-map: <view-map name="FeedbackMessages" type="screen" page="component://testapp/widget/TestAppScreens.xml#FeedbackMessages"/> which points to the following screen widget: <screen name="FeedbackMessages"> <section> <widgets> <decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}"> <decorator-section name="title"> <label text="Exploring all placeholders for Feedback"/> </decorator-section> <decorator-section name="body"> </decorator-section> </decorator-screen> </widgets> </section> </screen> Note:step 3 is not necessary. I only used it to see something on my screen.Result:I can now see in real time the SOAP message that is being sent & the response that is received.and I can also this screen: Now:the only thing I still need to do is some parsing on the SOAP response message to be able to deal with the variables that interest me in that message. I also need to enhance my code to make it more "generic" so that it becomes somewhat dynamic and works with not only that specific Web Service that I had to hardcode.Do you have any suggestions for that? I do not want to be reinventing the wheel!
Jad El Omeiri
|
Administrator
|
Inline ...
On Tuesday, December 03, 2013 5:24 PM jadelomeiri <[hidden email]> wrote: > Hello, > > This is the solution I finally got. I hope it will be helpful for people > having the same problem as I had. > > 1) In my events java class I wrote the following code (which is an event > calling the method that deals with SOAP): > > * > public static String callMySoap(HttpServletRequest > request,HttpServletResponse response) > { > request.setAttribute("_EVENT_MESSAGE_", "You received this SOAP > response:" + MySoapClient()); > return "success"; > } > > > > public static SOAPMessage MySoapClient() > { > try { > // Create SOAP Connection > SOAPConnectionFactory soapConnectionFactory = > SOAPConnectionFactory.newInstance(); > SOAPConnection soapConnection = > soapConnectionFactory.createConnection(); > > // Send SOAP Message to SOAP Server > String url = "http://www.webservicex.net/geoipservice.asmx"; > SOAPMessage soapResponse = > soapConnection.call(createSOAPRequest(), url); > > soapConnection.close(); > return soapResponse; > } catch (Exception e) { > System.err.println("Error occurred while sending SOAP Request to > Server"); > e.printStackTrace(); > return null; > } > > } > > private static SOAPMessage createSOAPRequest() throws Exception { > MessageFactory messageFactory = MessageFactory.newInstance(); > SOAPMessage soapMessage = messageFactory.createMessage(); > SOAPPart soapPart = soapMessage.getSOAPPart(); > > String serverURI = "http://www.webservicex.net/"; > > // SOAP Envelope > SOAPEnvelope envelope = soapPart.getEnvelope(); > envelope.addNamespaceDeclaration("web", serverURI); > > /* > Constructed SOAP Request Message: > <SOAP-ENV:Envelope > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:example="http://www.webservicex.net/"> > <SOAP-ENV:Header/> > <SOAP-ENV:Body> > <web:GetGeoIP> > <web:IPAddressl>192.168.1.2</web:IPAddress> > </web:GetGeoIP> > </SOAP-ENV:Body> > </SOAP-ENV:Envelope> > */ > > // SOAP Body > SOAPBody soapBody = envelope.getBody(); > SOAPElement soapBodyElem = soapBody.addChildElement("GetGeoIP", > "web"); > SOAPElement soapBodyElem1 = > soapBodyElem.addChildElement("IPAddress", "web"); > soapBodyElem1.addTextNode("192.168.1.2"); > > > MimeHeaders headers = soapMessage.getMimeHeaders(); > headers.addHeader("SOAPAction", serverURI + "GetGeoIP"); > > soapMessage.saveChanges(); > > /* Print the request message */ > System.out.print("Request SOAP Message = "); > soapMessage.writeTo(System.out); > System.out.println(); > > return soapMessage; > } > * > > 2) I added the following request-map to point to my event: > > * > <request-map uri="callMySoap"> > <event type="java" path="org.ofbiz.testapp.testapp.LearningEvents" > invoke="callMySoap"/> > <response name="success" type="view" value="FeedbackMessages"/> > </request-map> > * > > 3) I added the following view-map: > > * > <view-map name="FeedbackMessages" type="screen" > page="component://testapp/widget/TestAppScreens.xml#FeedbackMessages"/> > * > > which points to the following screen widget: > * > <screen name="FeedbackMessages"> > <section> > <widgets> > <decorator-screen name="main-decorator" > location="${parameters.mainDecoratorLocation}"> > <decorator-section name="title"> > <label text="Exploring all placeholders for Feedback"/> > </decorator-section> > <decorator-section name="body"> > > </decorator-section> > </decorator-screen> > </widgets> > </section> > </screen> > * > > > Note: > step 3 is not necessary. I only used it to see something on my screen. > > > Result: > I can now see in real time the SOAP message that is being sent & the > response that is received. > and I can also this screen: > <http://ofbiz.135035.n4.nabble.com/file/n4646047/result.png> > > > Now: > the only thing I still need to do is some parsing on the SOAP response > message to be able to deal with the variables that interest me in that > message. I also need to enhance my code to make it more "generic" so that it > becomes somewhat dynamic and works with not only that specific Web Service > that I had to hardcode. > > Do you have any suggestions for that? I do not want to be reinventing the > wheel! I did not look into the details and did not use SOAPConnection yet. But yes most of the time you need to handle yourself the SOAP response. Another solution could be to use an ESB (ServiceMix for instance) to do the transformations of the SOAP envelopes. Disclaimer: I did not go that way yet.. Maybe it will be easier than trying to generalise by yourself. This said having a generalisation embedded in OFBiz would be great! Jacques |
In reply to this post by Jad El Omeiri
Hi,
I use Smooks to deal with conversion xml -> Java objects when consuming a webservice. Hope it helps. Regards, Fairuz -----Original Message----- From: jadelomeiri [mailto:[hidden email]] Sent: Wednesday, December 04, 2013 12:24 AM To: [hidden email] Subject: Re: calling external SOAP service from Ofbiz Hello, This is the solution I finally got. I hope it will be helpful for people having the same problem as I had. 1) In my events java class I wrote the following code (which is an event calling the method that deals with SOAP): * public static String callMySoap(HttpServletRequest request,HttpServletResponse response) { request.setAttribute("_EVENT_MESSAGE_", "You received this SOAP response:" + MySoapClient()); return "success"; } public static SOAPMessage MySoapClient() { try { // Create SOAP Connection SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // Send SOAP Message to SOAP Server String url = "http://www.webservicex.net/geoipservice.asmx"; SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url); soapConnection.close(); return soapResponse; } catch (Exception e) { System.err.println("Error occurred while sending SOAP Request to Server"); e.printStackTrace(); return null; } } private static SOAPMessage createSOAPRequest() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = "http://www.webservicex.net/"; // SOAP Envelope SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("web", serverURI); /* Constructed SOAP Request Message: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://www.webservicex.net/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <web:GetGeoIP> <web:IPAddressl>192.168.1.2</web:IPAddress> </web:GetGeoIP> </SOAP-ENV:Body> </SOAP-ENV:Envelope> */ // SOAP Body SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("GetGeoIP", "web"); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("IPAddress", "web"); soapBodyElem1.addTextNode("192.168.1.2"); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", serverURI + "GetGeoIP"); soapMessage.saveChanges(); /* Print the request message */ System.out.print("Request SOAP Message = "); soapMessage.writeTo(System.out); System.out.println(); return soapMessage; } * 2) I added the following request-map to point to my event: * <request-map uri="callMySoap"> <event type="java" path="org.ofbiz.testapp.testapp.LearningEvents" invoke="callMySoap"/> <response name="success" type="view" value="FeedbackMessages"/> </request-map> * 3) I added the following view-map: * <view-map name="FeedbackMessages" type="screen" page="component://testapp/widget/TestAppScreens.xml#FeedbackMessages"/> * which points to the following screen widget: * <screen name="FeedbackMessages"> <section> <widgets> <decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}"> <decorator-section name="title"> <label text="Exploring all placeholders for Feedback"/> </decorator-section> <decorator-section name="body"> </decorator-section> </decorator-screen> </widgets> </section> </screen> * Note: step 3 is not necessary. I only used it to see something on my screen. Result: I can now see in real time the SOAP message that is being sent & the response that is received. and I can also this screen: <http://ofbiz.135035.n4.nabble.com/file/n4646047/result.png> Now: the only thing I still need to do is some parsing on the SOAP response message to be able to deal with the variables that interest me in that message. I also need to enhance my code to make it more "generic" so that it becomes somewhat dynamic and works with not only that specific Web Service that I had to hardcode. Do you have any suggestions for that? I do not want to be reinventing the wheel! -- View this message in context: http://ofbiz.135035.n4.nabble.com/calling-external-SOAP-service-from-Ofbiz-t p4646036p4646047.html Sent from the OFBiz - User mailing list archive at Nabble.com. |
Administrator
|
Funny, I just stumbled upon it while estimating a project today :)
Note that Smooks can't be embedded in OFBiz due to a license issue: http://www.smooks.org/mediawiki/index.php?title=Licensing Jacques On Tuesday, December 03, 2013 9:24 PM Fairuz Wan Ismail <[hidden email]> wrote: > Hi, > > I use Smooks to deal with conversion xml -> Java objects when consuming a > webservice. Hope it helps. > > Regards, > Fairuz > > -----Original Message----- > From: jadelomeiri [mailto:[hidden email]] > Sent: Wednesday, December 04, 2013 12:24 AM > To: [hidden email] > Subject: Re: calling external SOAP service from Ofbiz > > Hello, > > This is the solution I finally got. I hope it will be helpful for people > having the same problem as I had. > > 1) In my events java class I wrote the following code (which is an event > calling the method that deals with SOAP): > > * > public static String callMySoap(HttpServletRequest > request,HttpServletResponse response) > { > request.setAttribute("_EVENT_MESSAGE_", "You received this SOAP > response:" + MySoapClient()); > return "success"; > } > > > > public static SOAPMessage MySoapClient() > { > try { > // Create SOAP Connection > SOAPConnectionFactory soapConnectionFactory = > SOAPConnectionFactory.newInstance(); > SOAPConnection soapConnection = > soapConnectionFactory.createConnection(); > > // Send SOAP Message to SOAP Server > String url = "http://www.webservicex.net/geoipservice.asmx"; > SOAPMessage soapResponse = > soapConnection.call(createSOAPRequest(), url); > > soapConnection.close(); > return soapResponse; > } catch (Exception e) { > System.err.println("Error occurred while sending SOAP Request to > Server"); > e.printStackTrace(); > return null; > } > > } > > private static SOAPMessage createSOAPRequest() throws Exception { > MessageFactory messageFactory = MessageFactory.newInstance(); > SOAPMessage soapMessage = messageFactory.createMessage(); > SOAPPart soapPart = soapMessage.getSOAPPart(); > > String serverURI = "http://www.webservicex.net/"; > > // SOAP Envelope > SOAPEnvelope envelope = soapPart.getEnvelope(); > envelope.addNamespaceDeclaration("web", serverURI); > > /* > Constructed SOAP Request Message: > <SOAP-ENV:Envelope > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:example="http://www.webservicex.net/"> > <SOAP-ENV:Header/> > <SOAP-ENV:Body> > <web:GetGeoIP> > <web:IPAddressl>192.168.1.2</web:IPAddress> > </web:GetGeoIP> > </SOAP-ENV:Body> > </SOAP-ENV:Envelope> > */ > > // SOAP Body > SOAPBody soapBody = envelope.getBody(); > SOAPElement soapBodyElem = soapBody.addChildElement("GetGeoIP", > "web"); > SOAPElement soapBodyElem1 = > soapBodyElem.addChildElement("IPAddress", "web"); > soapBodyElem1.addTextNode("192.168.1.2"); > > > MimeHeaders headers = soapMessage.getMimeHeaders(); > headers.addHeader("SOAPAction", serverURI + "GetGeoIP"); > > soapMessage.saveChanges(); > > /* Print the request message */ > System.out.print("Request SOAP Message = "); > soapMessage.writeTo(System.out); > System.out.println(); > > return soapMessage; > } > * > > 2) I added the following request-map to point to my event: > > * > <request-map uri="callMySoap"> > <event type="java" path="org.ofbiz.testapp.testapp.LearningEvents" > invoke="callMySoap"/> > <response name="success" type="view" value="FeedbackMessages"/> > </request-map> > * > > 3) I added the following view-map: > > * > <view-map name="FeedbackMessages" type="screen" > page="component://testapp/widget/TestAppScreens.xml#FeedbackMessages"/> > * > > which points to the following screen widget: > * > <screen name="FeedbackMessages"> > <section> > <widgets> > <decorator-screen name="main-decorator" > location="${parameters.mainDecoratorLocation}"> > <decorator-section name="title"> > <label text="Exploring all placeholders for Feedback"/> > </decorator-section> > <decorator-section name="body"> > > </decorator-section> > </decorator-screen> > </widgets> > </section> > </screen> > * > > > Note: > step 3 is not necessary. I only used it to see something on my screen. > > > Result: > I can now see in real time the SOAP message that is being sent & the > response that is received. > and I can also this screen: > <http://ofbiz.135035.n4.nabble.com/file/n4646047/result.png> > > > Now: > the only thing I still need to do is some parsing on the SOAP response > message to be able to deal with the variables that interest me in that > message. I also need to enhance my code to make it more "generic" so that it > becomes somewhat dynamic and works with not only that specific Web Service > that I had to hardcode. > > Do you have any suggestions for that? I do not want to be reinventing the > wheel! |
Administrator
|
In reply to this post by Fairuz Wan Ismail
BTW, what are the advantages of Smooks vs wsdl2java?
Something simpler than https://axis.apache.org/axis/java/user-guide.html#What_Axis_can_not_send_via_SOAP ? Jacques On Tuesday, December 03, 2013 9:24 PM Fairuz Wan Ismail <[hidden email]> wrote: > Hi, > > I use Smooks to deal with conversion xml -> Java objects when consuming a > webservice. Hope it helps. > > Regards, > Fairuz > > -----Original Message----- > From: jadelomeiri [mailto:[hidden email]] > Sent: Wednesday, December 04, 2013 12:24 AM > To: [hidden email] > Subject: Re: calling external SOAP service from Ofbiz > > Hello, > > This is the solution I finally got. I hope it will be helpful for people > having the same problem as I had. > > 1) In my events java class I wrote the following code (which is an event > calling the method that deals with SOAP): > > * > public static String callMySoap(HttpServletRequest > request,HttpServletResponse response) > { > request.setAttribute("_EVENT_MESSAGE_", "You received this SOAP > response:" + MySoapClient()); > return "success"; > } > > > > public static SOAPMessage MySoapClient() > { > try { > // Create SOAP Connection > SOAPConnectionFactory soapConnectionFactory = > SOAPConnectionFactory.newInstance(); > SOAPConnection soapConnection = > soapConnectionFactory.createConnection(); > > // Send SOAP Message to SOAP Server > String url = "http://www.webservicex.net/geoipservice.asmx"; > SOAPMessage soapResponse = > soapConnection.call(createSOAPRequest(), url); > > soapConnection.close(); > return soapResponse; > } catch (Exception e) { > System.err.println("Error occurred while sending SOAP Request to > Server"); > e.printStackTrace(); > return null; > } > > } > > private static SOAPMessage createSOAPRequest() throws Exception { > MessageFactory messageFactory = MessageFactory.newInstance(); > SOAPMessage soapMessage = messageFactory.createMessage(); > SOAPPart soapPart = soapMessage.getSOAPPart(); > > String serverURI = "http://www.webservicex.net/"; > > // SOAP Envelope > SOAPEnvelope envelope = soapPart.getEnvelope(); > envelope.addNamespaceDeclaration("web", serverURI); > > /* > Constructed SOAP Request Message: > <SOAP-ENV:Envelope > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:example="http://www.webservicex.net/"> > <SOAP-ENV:Header/> > <SOAP-ENV:Body> > <web:GetGeoIP> > <web:IPAddressl>192.168.1.2</web:IPAddress> > </web:GetGeoIP> > </SOAP-ENV:Body> > </SOAP-ENV:Envelope> > */ > > // SOAP Body > SOAPBody soapBody = envelope.getBody(); > SOAPElement soapBodyElem = soapBody.addChildElement("GetGeoIP", > "web"); > SOAPElement soapBodyElem1 = > soapBodyElem.addChildElement("IPAddress", "web"); > soapBodyElem1.addTextNode("192.168.1.2"); > > > MimeHeaders headers = soapMessage.getMimeHeaders(); > headers.addHeader("SOAPAction", serverURI + "GetGeoIP"); > > soapMessage.saveChanges(); > > /* Print the request message */ > System.out.print("Request SOAP Message = "); > soapMessage.writeTo(System.out); > System.out.println(); > > return soapMessage; > } > * > > 2) I added the following request-map to point to my event: > > * > <request-map uri="callMySoap"> > <event type="java" path="org.ofbiz.testapp.testapp.LearningEvents" > invoke="callMySoap"/> > <response name="success" type="view" value="FeedbackMessages"/> > </request-map> > * > > 3) I added the following view-map: > > * > <view-map name="FeedbackMessages" type="screen" > page="component://testapp/widget/TestAppScreens.xml#FeedbackMessages"/> > * > > which points to the following screen widget: > * > <screen name="FeedbackMessages"> > <section> > <widgets> > <decorator-screen name="main-decorator" > location="${parameters.mainDecoratorLocation}"> > <decorator-section name="title"> > <label text="Exploring all placeholders for Feedback"/> > </decorator-section> > <decorator-section name="body"> > > </decorator-section> > </decorator-screen> > </widgets> > </section> > </screen> > * > > > Note: > step 3 is not necessary. I only used it to see something on my screen. > > > Result: > I can now see in real time the SOAP message that is being sent & the > response that is received. > and I can also this screen: > <http://ofbiz.135035.n4.nabble.com/file/n4646047/result.png> > > > Now: > the only thing I still need to do is some parsing on the SOAP response > message to be able to deal with the variables that interest me in that > message. I also need to enhance my code to make it more "generic" so that it > becomes somewhat dynamic and works with not only that specific Web Service > that I had to hardcode. > > Do you have any suggestions for that? I do not want to be reinventing the > wheel! |
In reply to this post by Jacques Le Roux
OFBiz uses XStream for object serialization.
Adrian Crum Sandglass Software www.sandglass-software.com On 12/3/2013 3:49 PM, Jacques Le Roux wrote: > Funny, I just stumbled upon it while estimating a project today :) > Note that Smooks can't be embedded in OFBiz due to a license issue: http://www.smooks.org/mediawiki/index.php?title=Licensing > > Jacques > > On Tuesday, December 03, 2013 9:24 PM Fairuz Wan Ismail <[hidden email]> wrote: >> Hi, >> >> I use Smooks to deal with conversion xml -> Java objects when consuming a >> webservice. Hope it helps. >> >> Regards, >> Fairuz >> >> -----Original Message----- >> From: jadelomeiri [mailto:[hidden email]] >> Sent: Wednesday, December 04, 2013 12:24 AM >> To: [hidden email] >> Subject: Re: calling external SOAP service from Ofbiz >> >> Hello, >> >> This is the solution I finally got. I hope it will be helpful for people >> having the same problem as I had. >> >> 1) In my events java class I wrote the following code (which is an event >> calling the method that deals with SOAP): >> >> * >> public static String callMySoap(HttpServletRequest >> request,HttpServletResponse response) >> { >> request.setAttribute("_EVENT_MESSAGE_", "You received this SOAP >> response:" + MySoapClient()); >> return "success"; >> } >> >> >> >> public static SOAPMessage MySoapClient() >> { >> try { >> // Create SOAP Connection >> SOAPConnectionFactory soapConnectionFactory = >> SOAPConnectionFactory.newInstance(); >> SOAPConnection soapConnection = >> soapConnectionFactory.createConnection(); >> >> // Send SOAP Message to SOAP Server >> String url = "http://www.webservicex.net/geoipservice.asmx"; >> SOAPMessage soapResponse = >> soapConnection.call(createSOAPRequest(), url); >> >> soapConnection.close(); >> return soapResponse; >> } catch (Exception e) { >> System.err.println("Error occurred while sending SOAP Request to >> Server"); >> e.printStackTrace(); >> return null; >> } >> >> } >> >> private static SOAPMessage createSOAPRequest() throws Exception { >> MessageFactory messageFactory = MessageFactory.newInstance(); >> SOAPMessage soapMessage = messageFactory.createMessage(); >> SOAPPart soapPart = soapMessage.getSOAPPart(); >> >> String serverURI = "http://www.webservicex.net/"; >> >> // SOAP Envelope >> SOAPEnvelope envelope = soapPart.getEnvelope(); >> envelope.addNamespaceDeclaration("web", serverURI); >> >> /* >> Constructed SOAP Request Message: >> <SOAP-ENV:Envelope >> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" >> xmlns:example="http://www.webservicex.net/"> >> <SOAP-ENV:Header/> >> <SOAP-ENV:Body> >> <web:GetGeoIP> >> <web:IPAddressl>192.168.1.2</web:IPAddress> >> </web:GetGeoIP> >> </SOAP-ENV:Body> >> </SOAP-ENV:Envelope> >> */ >> >> // SOAP Body >> SOAPBody soapBody = envelope.getBody(); >> SOAPElement soapBodyElem = soapBody.addChildElement("GetGeoIP", >> "web"); >> SOAPElement soapBodyElem1 = >> soapBodyElem.addChildElement("IPAddress", "web"); >> soapBodyElem1.addTextNode("192.168.1.2"); >> >> >> MimeHeaders headers = soapMessage.getMimeHeaders(); >> headers.addHeader("SOAPAction", serverURI + "GetGeoIP"); >> >> soapMessage.saveChanges(); >> >> /* Print the request message */ >> System.out.print("Request SOAP Message = "); >> soapMessage.writeTo(System.out); >> System.out.println(); >> >> return soapMessage; >> } >> * >> >> 2) I added the following request-map to point to my event: >> >> * >> <request-map uri="callMySoap"> >> <event type="java" path="org.ofbiz.testapp.testapp.LearningEvents" >> invoke="callMySoap"/> >> <response name="success" type="view" value="FeedbackMessages"/> >> </request-map> >> * >> >> 3) I added the following view-map: >> >> * >> <view-map name="FeedbackMessages" type="screen" >> page="component://testapp/widget/TestAppScreens.xml#FeedbackMessages"/> >> * >> >> which points to the following screen widget: >> * >> <screen name="FeedbackMessages"> >> <section> >> <widgets> >> <decorator-screen name="main-decorator" >> location="${parameters.mainDecoratorLocation}"> >> <decorator-section name="title"> >> <label text="Exploring all placeholders for Feedback"/> >> </decorator-section> >> <decorator-section name="body"> >> >> </decorator-section> >> </decorator-screen> >> </widgets> >> </section> >> </screen> >> * >> >> >> Note: >> step 3 is not necessary. I only used it to see something on my screen. >> >> >> Result: >> I can now see in real time the SOAP message that is being sent & the >> response that is received. >> and I can also this screen: >> <http://ofbiz.135035.n4.nabble.com/file/n4646047/result.png> >> >> >> Now: >> the only thing I still need to do is some parsing on the SOAP response >> message to be able to deal with the variables that interest me in that >> message. I also need to enhance my code to make it more "generic" so that it >> becomes somewhat dynamic and works with not only that specific Web Service >> that I had to hardcode. >> >> Do you have any suggestions for that? I do not want to be reinventing the >> wheel! |
Administrator
|
Interesting comparison for custom projects http://www.smooks.org/mediawiki/index.php?title=Performance
Jacques On Wednesday, December 04, 2013 12:21 AM Adrian Crum <[hidden email]> wrote: > OFBiz uses XStream for object serialization. > > Adrian Crum > Sandglass Software > www.sandglass-software.com > > On 12/3/2013 3:49 PM, Jacques Le Roux wrote: >> Funny, I just stumbled upon it while estimating a project today :) >> Note that Smooks can't be embedded in OFBiz due to a license issue: http://www.smooks.org/mediawiki/index.php?title=Licensing >> >> Jacques >> >> On Tuesday, December 03, 2013 9:24 PM Fairuz Wan Ismail <[hidden email]> wrote: >>> Hi, >>> >>> I use Smooks to deal with conversion xml -> Java objects when consuming a >>> webservice. Hope it helps. >>> >>> Regards, >>> Fairuz >>> >>> -----Original Message----- >>> From: jadelomeiri [mailto:[hidden email]] >>> Sent: Wednesday, December 04, 2013 12:24 AM >>> To: [hidden email] >>> Subject: Re: calling external SOAP service from Ofbiz >>> >>> Hello, >>> >>> This is the solution I finally got. I hope it will be helpful for people >>> having the same problem as I had. >>> >>> 1) In my events java class I wrote the following code (which is an event >>> calling the method that deals with SOAP): >>> >>> * >>> public static String callMySoap(HttpServletRequest >>> request,HttpServletResponse response) >>> { >>> request.setAttribute("_EVENT_MESSAGE_", "You received this SOAP >>> response:" + MySoapClient()); >>> return "success"; >>> } >>> >>> >>> >>> public static SOAPMessage MySoapClient() >>> { >>> try { >>> // Create SOAP Connection >>> SOAPConnectionFactory soapConnectionFactory = >>> SOAPConnectionFactory.newInstance(); >>> SOAPConnection soapConnection = >>> soapConnectionFactory.createConnection(); >>> >>> // Send SOAP Message to SOAP Server >>> String url = "http://www.webservicex.net/geoipservice.asmx"; >>> SOAPMessage soapResponse = >>> soapConnection.call(createSOAPRequest(), url); >>> >>> soapConnection.close(); >>> return soapResponse; >>> } catch (Exception e) { >>> System.err.println("Error occurred while sending SOAP Request to >>> Server"); >>> e.printStackTrace(); >>> return null; >>> } >>> >>> } >>> >>> private static SOAPMessage createSOAPRequest() throws Exception { >>> MessageFactory messageFactory = MessageFactory.newInstance(); >>> SOAPMessage soapMessage = messageFactory.createMessage(); >>> SOAPPart soapPart = soapMessage.getSOAPPart(); >>> >>> String serverURI = "http://www.webservicex.net/"; >>> >>> // SOAP Envelope >>> SOAPEnvelope envelope = soapPart.getEnvelope(); >>> envelope.addNamespaceDeclaration("web", serverURI); >>> >>> /* >>> Constructed SOAP Request Message: >>> <SOAP-ENV:Envelope >>> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" >>> xmlns:example="http://www.webservicex.net/"> >>> <SOAP-ENV:Header/> >>> <SOAP-ENV:Body> >>> <web:GetGeoIP> >>> <web:IPAddressl>192.168.1.2</web:IPAddress> >>> </web:GetGeoIP> >>> </SOAP-ENV:Body> >>> </SOAP-ENV:Envelope> >>> */ >>> >>> // SOAP Body >>> SOAPBody soapBody = envelope.getBody(); >>> SOAPElement soapBodyElem = soapBody.addChildElement("GetGeoIP", >>> "web"); >>> SOAPElement soapBodyElem1 = >>> soapBodyElem.addChildElement("IPAddress", "web"); >>> soapBodyElem1.addTextNode("192.168.1.2"); >>> >>> >>> MimeHeaders headers = soapMessage.getMimeHeaders(); >>> headers.addHeader("SOAPAction", serverURI + "GetGeoIP"); >>> >>> soapMessage.saveChanges(); >>> >>> /* Print the request message */ >>> System.out.print("Request SOAP Message = "); >>> soapMessage.writeTo(System.out); >>> System.out.println(); >>> >>> return soapMessage; >>> } >>> * >>> >>> 2) I added the following request-map to point to my event: >>> >>> * >>> <request-map uri="callMySoap"> >>> <event type="java" path="org.ofbiz.testapp.testapp.LearningEvents" >>> invoke="callMySoap"/> >>> <response name="success" type="view" value="FeedbackMessages"/> >>> </request-map> >>> * >>> >>> 3) I added the following view-map: >>> >>> * >>> <view-map name="FeedbackMessages" type="screen" >>> page="component://testapp/widget/TestAppScreens.xml#FeedbackMessages"/> >>> * >>> >>> which points to the following screen widget: >>> * >>> <screen name="FeedbackMessages"> >>> <section> >>> <widgets> >>> <decorator-screen name="main-decorator" >>> location="${parameters.mainDecoratorLocation}"> >>> <decorator-section name="title"> >>> <label text="Exploring all placeholders for Feedback"/> >>> </decorator-section> >>> <decorator-section name="body"> >>> >>> </decorator-section> >>> </decorator-screen> >>> </widgets> >>> </section> >>> </screen> >>> * >>> >>> >>> Note: >>> step 3 is not necessary. I only used it to see something on my screen. >>> >>> >>> Result: >>> I can now see in real time the SOAP message that is being sent & the >>> response that is received. >>> and I can also this screen: >>> <http://ofbiz.135035.n4.nabble.com/file/n4646047/result.png> >>> >>> >>> Now: >>> the only thing I still need to do is some parsing on the SOAP response >>> message to be able to deal with the variables that interest me in that >>> message. I also need to enhance my code to make it more "generic" so that it >>> becomes somewhat dynamic and works with not only that specific Web Service >>> that I had to hardcode. >>> >>> Do you have any suggestions for that? I do not want to be reinventing the >>> wheel! |
In reply to this post by Adrian Crum-3
Thank you all for your help. Thank you Jacques for pointing out the Smooks licensing issue. As a conclusion JiBX looks like it's the best way to go?
BTW before I continue working on my code, I think I will try to look at the SOAPClientEngine.java class in Ofbiz to see if the exceptions that are being thrown can be fixed. Wouldn't it be a wiser way to go in finding a solution?
Jad El Omeiri
|
Administrator
|
For the license issue, it's only in the context of redistributing with an incompatible license, like OFBiz with ASL2. As Adrian said we use XStream in OFBiz.
I believe it should be possible to go with the SOAPClientEngine class way. But it will never be possible to handle all cases. As I see it, depending of the order of magnitude (number of external SOAP services) and their complexity, here are the solutions in increased order: 1) Improve SOAPClientEngine if your services are not too complex 2) Generate Stub from WSDL using wsdl2Java and use cover OFBiz services to handle call to external SOAP services and possible mappings. 3) Use a tool like XStream or Smooks for transformations 4) Use an ESB or a complete solution with Camel + ServiceMix bundles (if necessary) HTH Jacques On Wednesday, December 04, 2013 10:10 AM jadelomeiri <[hidden email]> wrote: > Thank you all for your help. Thank you Jacques for pointing out the Smooks > licensing issue. As a conclusion JiBX looks like it's the best way to go? > > BTW before I continue working on my code, I think I will try to look at the > SOAPClientEngine.java class in Ofbiz to see if the exceptions that are being > thrown can be fixed. Wouldn't it be a wiser way to go in finding a solution? |
Thanks a lot Jacques!
What happened is that I spent most of my time debugging and trying to solve SOAPClientEngine. Unfortunately, I didn't get to any result. I then tried to work on the solution with Camel. I also found a project previously made which already integrates Ofbiz & Camel (that's the project link: https://github.com/bibryam/ofbiz-camel ) I also had few problems with it. BTW did anyone use it before? Which got me to finally try to use XStream. I spent some time reading tutorials about it... ==>I will continue with XStream and my previous code tomorrow. As soon as I have a solution, I will be posting it. Cheers,
Jad El Omeiri
|
Free forum by Nabble | Edit this page |