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
<[email protected]> 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:[email protected]]
Sent: Wednesday, December 04, 2013 12:24 AM
To: [email protected]
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!