1
votes

I have a client which connects to a Web service to get some information. I have a requirement where I have to send the same information to multiple services using different ports. To solve this without modifying the client code I found MULE ESB, which is supposed to do exactly what I need.

I've found a guide where I could connect one client to one service using MULE ESB and one port, but I cant find a way to chain the services so they all listen to one port but have different themselves.

This is how it's supposed to look like: Conceptual Diagram

UPDATE :

here is my current Mule Applications config :

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.2.1" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
    <flow name="flows1Flow1" doc:name="flows1Flow1">
        <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:4433/miniwebservice" mimeType="text/xml" doc:name="HTTP"/>
        <http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:4434/miniwebservice?wsdl" mimeType="text/xml" doc:name="HTTP"/>
    </flow>
</mule>

Here is the WebService :

Client :

package miniwebservice;

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

public class TestWsClient
{
   public static void main( final String[] args ) throws Throwable
   {
      String url = ( args.length > 0 ) ? args[0] : "http://localhost:4434/miniwebservice";
      Service service = Service.create(
            new URL( url + "?wsdl" ),
            new QName( "http://miniwebservice/", "HalloWeltImplService" ) );
      HalloWelt halloWelt = service.getPort( HalloWelt.class );
      System.out.println( "\n" + halloWelt.hallo( args.length > 1 ? args[1] : "" ) );
   }
}

Server :

package miniwebservice;

import javax.xml.ws.Endpoint;

public class TestWsServer
{
   public static void main( final String[] args )
   {
      String url = ( args.length > 0 ) ? args[0] : "http://localhost:4434/miniwebservice";
      Endpoint.publish( url, new HalloWeltImpl() );
   }
}

InterfaceImpl :

package miniwebservice;

import javax.jws.WebService;

@WebService( endpointInterface="miniwebservice.HalloWelt" )
public class HalloWeltImpl implements HalloWelt
{
   public String hallo( String wer )
   {
      return "Hallo " + wer;
   }
}

interface :

package miniwebservice;

import javax.jws.*;

@WebService
public interface HalloWelt
{
   public String hallo( @WebParam( name = "wer" ) String wer );
}

If I start the Server and the Mule aplication and try to reach http://localhost:4434/miniwebservice?wsdl ower http://localhost:4433/miniwebservice I get the folowing Exception in my Browser (FireFox 8.0) :

Couldn't create SOAP message due to exception: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] Message: Content is not allowed in prolog.

I just started to work with Mule so I thouth that this would be enouth to get redirect mule to the Service to get the wsdl but its seems like its a bit complicatet.

1
What is the nature of these web services? SOAP-style? Also: should Mule aggregate the results from the 3 calls or pick one or use the different remote services as fallback (call 1st, fallback to 2nd if 1st is down...)?David Dossot
@David Dossot I've edited the question added some new infos.Kiesa
Remove the ?wsdl from the target service URL otherwise you pipe all requests to the WSDL generator.David Dossot
Do you think you can perform the remote WS responses aggregation while handling SOAP envelopes (XML) or do you need to deal with POJOs? If XML is OK, you can probably solve your problem with an all routing message processor and XSL-T. Otherwise, you'll need to use CXF to call these services behind an all RMP then have custom code to aggregate the POJOs.David Dossot
XML is ok but , I still cant get one service to work normaly. I've tried lots of diferent things , reading testing the "Consuming Web Services " guide and some tests with a cxf proxy client but i cant get it to work. If I cant get one external service to work with mule i cant try to chain multiple services.Kiesa

1 Answers

1
votes

Disclaimers:

  • This is not the final solution to the whole problem, which includes dispatching to several services and aggregating results, but a step in the right direction.
  • This is not representative of how web service proxying is done in Mule (which is way simpler) but a barebone approach to HTTP request routing so aggregation can be added.

Since you want to forward HTTP GET requests to the ?wsdl processor and HTTP POST SOAP request to the web service, you need to handle the target HTTP method and request URI propagation yourself:

<flow name="flows1Flow1">
    <http:inbound-endpoint exchange-pattern="request-response"
        address="http://localhost:4433/miniwebservice" />
    <message-properties-transformer scope="outbound">
        <add-message-property key="http.method" value="#[header:INBOUND:http.method]" />
    </message-properties-transformer>
    <logger level="INFO" category="ddo" />
    <http:outbound-endpoint exchange-pattern="request-response"
        address="http://localhost:4434#[header:INBOUND:http.request]" />
</flow>

(tested and validated with TestWsClient and TestWsServer)