fatherazrael
fatherazrael

Reputation: 5957

Mule - How to send SOAP Web Service Request?

Hi i am doing simple POC in mule.

I have a web service and i want to make it's Client.

It is SOAP web service and i want to send request to it but i am not getting wayout. Please give me some idea.

Following is code:

MULE:

<cxf:configuration name="CXF_Configuration" enableMuleSoapHeaders="true" initializeStaticBusInstance="true" doc:name="CXF Configuration"/>

<flow name="prjvm1" doc:name="prjvm1">
    <http:inbound-endpoint address="http://localhost:5678/httpHello" contentType="application/x-www-form-urlencoded" doc:name="HTTP">
        <http:body-to-parameter-map-transformer />
    </http:inbound-endpoint>

    <!-- This logger is just set to show the message accepted from the request -->
    <logger level="INFO" message="#[payload]" doc:name="Logger"/>
        <cxf:jaxws-client doc:name="VimService"    
                      wsdlLocation="file:/C:/Users/gugla/MuleStudio/workspace/prjvm/bin/service/vService.wsdl" 
                      operation="retrieveServiceContent"  
                      clientClass="com.esxclient.VService" 
                      port="VimPort">
        <cxf:jaxb-databinding/>
    </cxf:jaxws-client>
    <outbound-endpoint address="http://localhost:8080/gep-sped/servicos/ServicoDeCadastroEAgendamento" 
                        doc:name="Generic" 
                        exchange-pattern="request-response"/>
    <echo-component doc:name="Echo"/>
</flow>

I am getting exception, but operation is there in WSDL

Message               : No such operation: retrieveServiceContent. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: ManagedObjectReference
Code                  : MULE_ERROR--2

--------------------------------------------------------------------------------
Exception stack is:
1. No such operation: retrieveServiceContent (java.lang.Exception)
  org.mule.module.cxf.CxfOutboundMessageProcessor:282 (null)
2. No such operation: retrieveServiceContent. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: ManagedObjectReference (org.mule.api.transport.DispatchException)
  org.mule.module.cxf.CxfOutboundMessageProcessor:150 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.Exception: No such operation: retrieveServiceContent
    at org.mule.module.cxf.CxfOutboundMessageProcessor.getOperation(CxfOutboundMessageProcessor.java:282)
    at org.mule.module.cxf.CxfOutboundMessageProcessor.getMethodFromOperation(CxfOutboundMessageProcessor.java:322)
    at org.mule.module.cxf.CxfOutboundMessageProcessor.getMethod(CxfOutboundMessageProcessor.java:259)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

Following is WSDL in operation: I am confused and around 4 days on it as i am new to mule.

  <operation name="RetrieveServiceContent">
     <input message="vim2:RetrieveServiceContentRequestMsg" />
     <output message="vim2:RetrieveServiceContentResponseMsg" />
     <fault name="RuntimeFault" message="vim2:RuntimeFaultFaultMsg"/>
  </operation>

Upvotes: 0

Views: 4968

Answers (1)

Richard Willems
Richard Willems

Reputation: 21

There are a couple of ways to do this. I prefer to NOT us the way MuleStudio wants you to do it since I never really got that to work. Basically, whenever I create a webservice client my mule-config looks something like this:

<custom-transformer class="nl.thorax.someprogram.transformers.SomeRequestTransformer
<https:outbound-endpoint ref="someEndpoint" >
   <cxf:jaxws-client 
        clientClass="nl.thorax.someprogram.someclass"
        wsdlLocation="http://somedomain?wsdl
        port="somePort" 
        operation="someOperation"/>
</https:outbound-endpoint>
<custom-transformer class="nl.thorax.someprogram.transformers.SomeResponseTransformer

Where:

  • SomeRequestTransformer: a transformer to create your request.
  • someEndpoint: some endpoint defined in your MuleConfig. In my example, this is https but it could also be plain http.
  • someclass: Important! This is your client class. It can be generated from a WSDL by free tools like Apache's WSDL2Java. Google is your friend on this.
  • somePort: The port in your webservice to use. It can usually be found in the WSDL itself or in the client class you generated. The port more or less specifies what operations you can use.
  • someOperation: The operation you want to use. Make sure it is typed EXACTLY the same as it's definition in the client class. Wrong use of cApItAlS will cause errors!
  • SomeResponseTransformer: a transformer to do something with your response.

Now, the way I configure the call (and parse the response for that matter) is to use POJOs. My first transformer, the SomeRequestTransformer (based on the AbstractMessageTransformer in the Mule library) has a bit of code looking like this:

public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException
{
  RequestObject request = new RequestObject();
  request.setText("Hello!");
  message.setPayload(request);
  return message;
}

I create the request, set the variables and return it to Mule. The RequestObject is a class generated by WSDL2Java and corresponds to some operation in the WSDL. Parsing the response works pretty much the same way.

Now I know from experience that a lot of webservices do not quite work in the same way. Try to implement my example yourself. If that doesn't work, please provide your Mule-Config and any and all Java classes you may be using.

EDIT: I've created an example of my method that actually works. The files can be downloaded at our website. Please see the comments in the files. You have to manually create the Mule project, of course.

Points of note for the example:

  • The XML-representation of the Mule-config can be found in the 'resources' folder in the archive.
  • The 'nl.example.example' folder contains all the generated JAX-WS files.
  • The WSDL location in Mule-config has to be changed since it contains an absolute path.
  • The example creates an endpoint at http://localhost:8088 for you to call. The flow contains a transformer which creates an example call using pre-defined parameters. Then it tries to connect to the webservice. I've used the default address used by SOAPUI when you create a mock service, but this could of course be changed into anything you want. The webservice (supposedly) returns something which is echoed into the user's browser.
  • In this example, the parameters are actually Strings, since the WSDL-request doesn't contain anything. To figure out what object to pass to the cxf:jaxws-client look at the operation definition which can be found in the Port definition in your generated files.

Upvotes: 1

Related Questions