mule simple web client soap request with wsdl - web-services

I would like to make request to web service from mule flow. So far I got WSDL generate classes (wsdl2java), prepared flow (below), and "successfully" send request. Now, problem is, that even thou I have taken base class from generated class and put it in payload it does not generate required soap.
My flow:
<flow name="flow1" doc:name="flow1">
<quartz:inbound-endpoint jobName="testingJob" repeatInterval="10810000" repeatCount="0" startDelay="5000" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job groupName="g1job" jobGroupName="g1job">
<quartz:payload>a</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<logger message="Starting quartz for testing purpouses" level="INFO" doc:name="Logger"/>
<custom-transformer class="com.example.GenerateSimpleRoutePublish" doc:name="Java"/>
<cxf:simple-client doc:name="SOAP" serviceClass="com.example.ws.MyWebService" operation="send">
</cxf:simple-client>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="9094" path="sync-server-web/services/myws" method="POST" connector-ref="http_internal" doc:name="HTTP"/>
</flow>
GenerateSimpleRoutePublish just put base object into payload and move on.
Result that is sent as soap request:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:send xmlns:ns1="http://somenamespace.si/">
<ns1:arg0>
<ns1:MyRequest>
...
But it should look like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:send xmlns:ns1="http://somenamespace.si/">
<ns1:MyRequest>
...
Notice that is not there anymore in desired xml.
Anyone knows how to achieve that? I did googled a lot but just don't find right solution. If more is required then I can provide info.
Thanks!
EDIT
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="MyWebService" targetNamespace="http://ws.example.com/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://ws.example.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema elementFormDefault="unqualified" targetNamespace="http://ws.example.com/"
version="1.0" xmlns:tns="http://ws.example.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyRequest" type="tns:MyRequest" />
<xs:element name="send" type="tns:send" />
<xs:element name="sendResponse" type="tns:sendResponse" />
<xs:complexType name="send">
<xs:sequence>
<xs:element minOccurs="0" ref="tns:MyRequest" />
</xs:sequence>
</xs:complexType>
<xs:complexType final="extension restriction" name="MyRequest">
<xs:complexContent>
...
Transformer class GenerateSimpleRoutePublish.java:
#Override
public MuleEvent process(MuleEvent event) throws MuleException {
event.setMessage(transformMessage(event.getMessage(), event.getEncoding()));
// TODO Auto-generated method stub
return event;
}
public MuleMessage transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
MyRequest myRequest = new MyRequest();
/**
* some filling of testing data that is formatted correctly when soap is sent.
*/
Send send = new Send();
send.setMSyequest(myRequest);//the only setter method available for Send
message.setPayload(send);
return message;
}
Send.java methods and xml definition:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "send", propOrder = {"myRequest"})
public MyRequest getMyRequest()
public void setMyRequest(MyRequest value)

Instead of using a custom-transformer you could use Groovy script to send SOAP request to webservice client just as Java pojo class... Please check the reference :- https://m-square.com.au/consuming-net-wcf-soap-web-services-from-mule/

Related

Why wsimport tool for generating files from wsdl file not working showing error code 400

I am working on webservices to integrate with the application and as a newbee needs more input.
Can any anyone tell me the issue why wsimport throws error on console : Server returned HTTP response code: 400 for URL:
http://localhost:8084/service/HelloWorld.wsdl
Following is my code below :
HelloWorld.java
//Service Endpoint Interface
#WebService
#SOAPBinding(style = Style.RPC)
public interface HelloWorld {
#WebMethod String getHelloWorldAsString(String msg);
}
HelloWorldImpl.java
#WebService(endpointInterface = "com.pack.service.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
#Override
public String getHelloWorldAsString(String msg) {
return "Hello, "+msg+ " How are you ?" ;
}
}
HelloWorldPublisher.java
//Endpoint Publisher
public class HelloWorldPublisher {
public static void main(String[] args){
System.out.println("Webservice Running ... ");
Endpoint.publish("http://localhost:8084/service/HelloWorld", new HelloWorldImpl());
}
}
Now, when i want to generate stub files from wsdl file. It gives the following error :
Note : Using command prompt and entering the following on command line :
wsimport -keep http://localhost:8084/service/HelloWorld?wsdl
At command line it shows >>
D:\Personal\WebService>wsimport -keep http://localhost:8084/service/HelloWorld?wsdl
parsing WSDL...
[ERROR] Server returned HTTP response code: 400 for URL: http://localhost:8084/service/HelloWorld?wsdl
Failed to read the WSDL document: http://localhost:8084/service/HelloWorld?wsdl, because 1) could not find the document; /2) the document could not be read; 3) the root element of the document is not
<wsdl:definitions>.
[ERROR] failed.noservice=Could not find wsdl:service in the provided WSDL(s):
At least one WSDL with at least one service definition needs to be provided.
Failed to parse the WSDL.
D:\Personal\WebService>
wsdl file >>.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-. -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-. -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.pack.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service.pack.com/" name="HelloWorldImplService">
<types/>
<message name="getHelloWorldAsString">
<part name="arg0" type="xsd:string"/>
</message>
<message name="getHelloWorldAsStringResponse">
<part name="return" type="xsd:string"/>
</message>
<portType name="HelloWorld">
<operation name="getHelloWorldAsString">
<input wsam:Action="http://service.pack.com/HelloWorld/getHelloWorldAsStringRequest" message="tns:getHelloWorldAsString"/>
<output wsam:Action="http://service.pack.com/HelloWorld/getHelloWorldAsStringResponse" message="tns:getHelloWorldAsStringResponse"/>
</operation>
</portType>
<binding name="HelloWorldImplPortBinding" type="tns:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="getHelloWorldAsString">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://service.pack.com/"/>
</input>
<output>
<soap:body use="literal" namespace="http://service.pack.com/"/>
</output>
</operation>
</binding>
<service name="HelloWorldImplService">
<port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding">
<soap:address location="http://localhost:8084/service/HelloWorld"/>
</port>
</service>
</definitions>
I had the exact same issue when trying to generate the client side from the command line. After switching of my proxy settings, the error went away and I successfully generated the client files.
Disable Proxy Settings.

To consume a web service with multiple input arguments in mule

I'm a beginner, I have a mule flow, in which i would like to call SOAP web service operation which has 4 input arguments
"public double calculateInterest(double principal, double year, double rate, int appid)".
I tried using a file or http endpoint where i end up in String array, or object array while using set payload.
the exception thrown is
cannot be cast to java.lang.Double. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: String[]
Could somebody suggest the best way to do it.
you can configure file or http inbound, write a java component (remove cxf component), extract parameters from payload, cast in the required type and call web-service method from the component.
see here is an example of a simple webservice :-
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.3.0" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
<flow name="getCalculationFlow1" doc:name="getCalculationFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="getCalculation" doc:name="HTTP"/>
<cxf:jaxws-service serviceClass="com.services.getcalculation.v1.GetCalculation" doc:name="SOAP"/>
<component class="com.services.schema.getcalculation.v1.GetCalculationImpl" doc:name="Java"/>
</flow>
</mule>
where com.services.getcalculation.v1.GetCalculation is the webservice class which is generated using Apache CXF from WSDL files and com.services.schema.getcalculation.v1.GetCalculationImpl is the implemantation class of webservice ... hope this help

how to prevent parsing webservice response string

how can I prevent string argument from beeing parsed as xml ?
<s:element name="MyResponse">
<s:complexType>
<s:sequence>
<s:element type="s:string" name="xmlResultWithStringType" minOccurs="0" maxOccurs="1" />
</s:sequence>
</s:complexType>
</s:element>
in log I have a correct answer -
Hello xmlStart <foo>in foo<bar>in bar</bar> end foo</foo> xmlEnd
full log :
---[HTTP request - http://localhost:8080/mockXXX]---
Accept: application/soap+xml, multipart/related
Content-Type: application/soap+xml; charset=utf-8;action="http://xxx"
User-Agent: JAX-WS RI 2.2.7-b01 svn-revision#13316
<?xml version="1.0" ?><S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"><S:Body><MyRequest xmlns="http://fff"><xmlRequest>req do webserwisu</xmlRequest></MyRequest></S:Body></S:Envelope>--------------------
---[HTTP response - http://localhost:8080/mockXXX - 200]---
null: HTTP/1.1 200 OK
Content-Type: application/soap+xml;charset=UTF-8
Server: Jetty(6.1.x)
Transfer-Encoding: chunked
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:fff="http://fff">
<soap:Header/>
<soap:Body>
<fff:MyResponse>
<!--Optional:-->
<fff:XmlResultWithStringType>Hello xmlStart <foo>in foo<bar>in bar</bar> end foo</foo> xmlEnd</fff:XmlResultWithStringType>
</fff:MyResponse>
</soap:Body>
</soap:Envelope>--------------------
but webservice call returns only
xmlEnd2
whole beginning is lost, the content of XmlResultWithStringType is parsed by xml parser,
but it should not,
how can I prevent it from beeing parsed ?
I use jax-ws-RI implementation,
it should be but into CDATA section
<![CDATA[ any xml possible here, it won't be treated as xml but as string ]]>
otherwise, without CDATA, it is treated as xml not as string.

ReplyTo property missing in SOAPHeader

I have created a WS-BPEL workflow that would call an asynchronous web service and wait for a callback response. The carbon application is successfully deployed into BPS as well.
Details on my external Asynchronous web service
1. It requires basic authentication over http.
2. It requires the soap header to be available in the soap envelope.
3. It would process the request and send a callback to the ReplyTo address it receives in the soap header and use the MessageID to correlate the callback.
My deploy.xml file for the BPEL process looks like this ...
<?xml version="1.0" encoding="UTF-8"?>
<deploy xmlns="http://www.apache.org/ode/schemas/dd/2007/03"
xmlns:callback.integration.service="http://callback.integration.service/"
xmlns:epr="http://wso2.org/bps/bpel/endpoint/config"
xmlns:sample="http://wso2.org/bps/sample"
xmlns:ws.integration.service="http://ws.integration.service/">
<process name="sample:Test">
<active>true</active>
<retired>false</retired>
<process-events generate="all"/>
<provide partnerLink="client">
<service name="sample:Test" port="TestPort"/>
</provide>
<provide partnerLink="IntegrationService">
<service name="callback.integration.service:IntegrationCallback" port="IntegrationResponsePort"/>
</provide>
<invoke partnerLink="IntegrationService">
<service name="ws.integration.service:IntegrationService" port="IntegrationRequestPort">
<epr:endpoint endpointReference="IntegrationService.epr"/>
</service>
</invoke>
</process>
</deploy>
The IntegrationService.epr file looks like this ...
<wsa:EndpointReference
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com uep_schema.xsd"
xmlns:wsa="http://www.w3.org/2005/08/addressing"
xmlns:wsdl11="http://schemas.xmlsoap.org/wsdl/">
<wsa:Address>http://http://server:8080/integration/IntegrationService</wsa:Address>
<wsa:Metadata>
<id>SInvokeEPR</id>
<qos>
<enableAddressing />
</qos>
<transport type="http">
<authorization-username>username</authorization-username>
<authorization-password>password</authorization-password>
</transport>
</wsa:Metadata>
</wsa:EndpointReference>
Now when I test the bpel process from carbon service management console, I do get a request to my asynchronous web service. However the soap envelope looks as followed and it is missing a proper ReplyTo address to send the callback.
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://server:8080/integration/IntegrationService</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/none</wsa:Address>
</wsa:ReplyTo>
<wsa:MessageID>urn:uuid:91ac4ebd-b100-440e-a01d-c4a5c0d8a56f</wsa:MessageID>
<wsa:Action>http://ws.integration.service/IntegrationRequestPortType/createTask</wsa:Action>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
Now my need is to reply to this request with a callback. The callback soap envelope would contain this MessageID so that the callback correlates with the correct process instance.
How do you get the proper ReplyTo address appended to the soap header?
If I assume correctly you use the WSO2 BPS (or something with Apache ODE), you can use this copy in an assign to set the Header by hand. (http://ode.apache.org/extensions/headers-handling.html)
<bpel:copy>
<bpel:from>
<bpel:literal>
<wsa:ReplyTo xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Address>http://localhost:9763/services/SIServerCallback</Address>
</wsa:ReplyTo>
</bpel:literal>
</bpel:from>
<bpel:to variable="ServiceInvokerIARequest" header="ReplyTo">
</bpel:to>
</bpel:copy>

Calling Webservice from adobe process

I am calling Webservice from adobe process .
my wsdl contains web method "storeDocument" which takes Document as input.
<xs:element name="storeDocument">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:java="java:org.w3c.dom" name="req" type="java:Document"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="storeDocumentResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
but when i generate request in webservice setting. it shows
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:res="http://resourceusage.resource.domain.services.nyss.ktv.tdc.com" xmlns:java="java:org.w3c.dom">
<soapenv:Header/>
<soapenv:Body>
<res:storeDocument>
<res:req>
<java:XmlStandalone>?</java:XmlStandalone>
<java:XmlVersion>?</java:XmlVersion>
<java:StrictErrorChecking>?</java:StrictErrorChecking>
<java:DocumentURI>?</java:DocumentURI>
</res:req>
</res:storeDocument>
</soapenv:Body>
</soapenv:Envelope>
I dont have idea how to invoke this service , i tried to give
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:res="http://resourceusage.resource.domain.services.nyss.ktv.tdc.com" xmlns:java="java:org.w3c.dom">
<soapenv:Header/>
<soapenv:Body>
<res:storeDocument>
<res:req>
<java:StrictErrorChecking>false</java:StrictErrorChecking>
<java:DocumentURI>{$ /process_data/#outputForm $}</java:DocumentURI>
</res:req>
</res:storeDocument>
</soapenv:Body>
</soapenv:Envelope>
But it is not working
it gives me error
<bea_fault:stacktrace xmlns:bea_fault="http://www.bea.com/servers/wls70/webservice/fault/1.0.0">com.bea.xml.XmlRuntimeException: java.lang.InstantiationException: org.w3c.dom.Document
at com.bea.staxb.runtime.internal.ClassLoadingUtils.newInstance(ClassLoadingUtils.java:137)
at com.bea.staxb.runtime.internal.ByNameRuntimeBindingType.createIntermediary(ByNameRuntimeBindingType.java:207)
at com.bea.staxb.runtime.internal.AttributeUnmarshaller.unmarshal(AttributeUnmarshaller.java:36)
at com.bea.staxb.runtime.internal.UnmarshalResult.unmarshalBindingType(UnmarshalResult.java:174)
at com.bea.staxb.runtime.internal.UnmarshalResult.unmarshalType(UnmarshalResult.java:212)
at com.bea.staxb.runtime.internal.UnmarshallerImpl.unmarshalType(UnmarshallerImpl.java:127)
at weblogic.wsee.bind.runtime.internal.LiteralDeserializerContext.unmarshalType(LiteralDeserializerContext.java:70)
at weblogic.wsee.bind.runtime.internal.BaseDeserializerContext.internalDeserializeType(BaseDeserializerContext.java:170)
at weblogic.wsee.bind.runtime.internal.BaseDeserializerContext.deserializeType(BaseDeserializerContext.java:87)
at weblogic.wsee.bind.runtime.internal.BaseDeserializerContext.deserializeWrappedElement(BaseDeserializerContext.java:133)
at weblogic.wsee.codec.soap11.SoapDecoder.decodePart(SoapDecoder.java:407)
at weblogic.wsee.codec.soap11.SoapDecoder.decodeParams(SoapDecoder.java:245)
at weblogic.wsee.codec.soap11.SoapDecoder.decodeParts(SoapDecoder.java:164)
at weblogic.wsee.codec.soap11.SoapDecoder.decode(SoapDecoder.java:117)
at weblogic.wsee.codec.soap11.SoapCodec.decode(SoapCodec.java:139)
at weblogic.wsee.ws.dispatch.server.CodecHandler.decode(CodecHandler.java:138)
at weblogic.wsee.ws.dispatch.server.CodecHandler.handleRequest(CodecHandler.java:39)
at weblogic.wsee.handler.HandlerIterator.handleRequest(HandlerIterator.java:127)
at weblogic.wsee.ws.dispatch.server.ServerDispatcher.dispatch(ServerDispatcher.java:85)
at weblogic.wsee.ws.WsSkel.invoke(WsSkel.java:80)
at weblogic.wsee.server.servlet.SoapProcessor.handlePost(SoapProcessor.java:66)
at weblogic.wsee.server.servlet.SoapProcessor.process(SoapProcessor.java:44)
at weblogic.wsee.server.servlet.BaseWSServlet$AuthorizedInvoke.run(BaseWSServlet.java:173)
at weblogic.wsee.server.servlet.BaseWSServlet.service(BaseWSServlet.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3231)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2002)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1908)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1362)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
Caused by: java.lang.InstantiationException: org.w3c.dom.Document
at java.lang.Class.newInstance0(Class.java:335)
at java.lang.Class.newInstance(Class.java:303)
at com.bea.staxb.runtime.internal.ClassLoadingUtils.newInstance(ClassLoadingUtils.java:135)
... 36 more
Caused by: java.lang.InstantiationException: org.w3c.dom.Document
at java.lang.Class.newInstance0(Class.java:335)
at java.lang.Class.newInstance(Class.java:303)
at com.bea.staxb.runtime.internal.ClassLoadingUtils.newInstance(ClassLoadingUtils.java:135)
at com.bea.staxb.runtime.internal.ByNameRuntimeBindingType.createIntermediary(ByNameRuntimeBindingType.java:207)
at com.bea.staxb.runtime.internal.AttributeUnmarshaller.unmarshal(AttributeUnmarshaller.java:36)
at com.bea.staxb.runtime.internal.UnmarshalResult.unmarshalBindingType(UnmarshalResult.java:174)
Please help..
With the LiveCycle Workbench you can use the WebServices Service to invoke other webservices.
On this website lctips.wordpress.com
you can find some examples.
You can also call webservice from the form with javascript or dataconnection.
invoking-a-web-service programmatically