Hi all,
I read a lot of information in this excellent mail list about Axis2 and OFBiz. I know that it is possible to expose OFBiz services using Axis2, but is it possible to call external services in Axis2 from OFBiz? Thanks in advance, Mario. |
Yes, it is possible to call external services using Axis2 in Ofbiz, Use the
following steps for the same 1) Generate Java Client using the WSDL of the external service 2) Calling the Webservice Java Client is as easy as calling any java class; Call the generated webservice client (generated from the WSDL) from your ofbiz just like calling any other java class. YOKEPOWER On Mon, Sep 7, 2009 at 9:38 AM, MarioF <[hidden email]> wrote: > > Hi all, > > I read a lot of information in this excellent mail list about Axis2 and > OFBiz. I know that it is possible to expose OFBiz services using Axis2, but > is it possible to call external services in Axis2 from OFBiz? > > Thanks in advance, > Mario. > -- > View this message in context: > http://www.nabble.com/Is-it-possible-to-call-external-services-from-OFBiz-to-Axis2--tp25330704p25330704.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > > |
In reply to this post by MarioF
Yes, I have recently dropped the spring-ws 1.5.7 libraries into framework/base/lib and created a POX client to call an external webservice. No more messing with wsdl2java for simple services, just xpath expressions to get the data:
package uk.co.dh.hpi; import java.io.StringReader; import java.util.Map; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.stream.StreamSource; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.ServiceUtil; import org.springframework.ws.client.core.WebServiceTemplate; public class WebServiceClient { public static final String customerCode = UtilProperties.getPropertyValue("DHConfig.properties", "hpi.CustomerCode"); public static final String initials = UtilProperties.getPropertyValue("DHConfig.properties", "hpi.Initials"); public static final String password = UtilProperties.getPropertyValue("DHConfig.properties", "hpi.Password"); public static final String uri = UtilProperties.getPropertyValue("DHConfig.properties", "hpi.URI"); private static String makeMessage(String vrm, String vin) { String vrmElement = ""; String vinElement = ""; if (vrm != null && !(vrm.trim().length() == 0)) vrmElement = "<hpi:Vrm>" + vrm + "</hpi:Vrm>"; if (vin != null && !(vin.trim().length() == 0)) vinElement = "<hpi:Vin>" + vin + "</hpi:Vin>"; return "<hpi:enquire xmlns:hpi=\"urn:enquiry\">" + "<hpi:Authentication>" + "<hpi:CustomerDetails>" + "<hpi:CustomerCode>" + customerCode + "</hpi:CustomerCode>" + "<hpi:Initials>" + initials + "</hpi:Initials>" + "<hpi:Password>" + password + "</hpi:Password>" + "</hpi:CustomerDetails>" + "</hpi:Authentication>" + "<hpi:Request>" + "<hpi:Asset>" + vrmElement + vinElement + "</hpi:Asset>" + "<hpi:Product>" + "<hpi:Code>HPI01</hpi:Code>" + "</hpi:Product>" + "</hpi:Request>" + "</hpi:enquire>"; } public static Map doHPI01(DispatchContext ctx, Map context) { String vrm = (String) context.get("vrm"); String vin = (String) context.get("vin"); Map resultMap = ServiceUtil.returnSuccess(); DOMResult result; try { WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); StreamSource source = new StreamSource(new StringReader(makeMessage(vrm, vin))); result = new DOMResult(); webServiceTemplate.sendSourceAndReceiveToResult(uri, source, result); XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression expr; expr = xPath.compile("/EnquiryResponse/RequestResults/Asset/AssetIdentification/Vrm/text()"); resultMap.put("responseVrm", expr.evaluate(result.getNode())); expr = xPath.compile("/EnquiryResponse/RequestResults/Asset/AssetIdentification/Vin/text()"); resultMap.put("responseVin", expr.evaluate(result.getNode())); ... ... ... } catch (XPathExpressionException e) { Debug.logError(e, "Error running Hpi Lookup - ", WebServiceClient.class.getName()); return ServiceUtil.returnError("Error running Hpi Lookup" + e); } resultMap.put("responseXml", DOMWriter.printNode(result.getNode(), true)); return resultMap; } }
|
Free forum by Nabble | Edit this page |