MULE ESB:将多个 Web 服务绑定到一个客户端

发布于 2025-01-04 23:38:51 字数 3363 浏览 1 评论 0原文

我有一个连接到 Web 服务以获取一些信息的客户端。我有一个要求,必须使用不同的端口将相同的信息发送到多个服务。为了在不修改客户端代码的情况下解决这个问题,我找到了 MULE ESB,它应该能够完全满足我的需要。

我找到了一份指南,可以使用 MULE ESB 和一个端口将一个客户端连接到一个服务,但我找不到一种链接服务的方法,因此它们都监听一个端口,但它们本身不同。

它应该是这样的: 概念图

更新:

这是我当前的Mule应用程序配置:

<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>

这是WebService:

客户端:

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] : "" ) );
   }
}

服务器:

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;
   }
}

接口:

package miniwebservice;

import javax.jws.*;

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

如果我启动服务器和 Mule 应用程序并尝试访问 http://localhost:4434/miniwebservice?wsdl 拥有 http://localhost:4433/miniwebservice 我在浏览器 (FireFox 8.0) 中收到以下异常:

由于异常,无法创建 SOAP 消息:XML 读取器错误: javax.xml.stream.XMLStreamException:[行,列]处的解析错误:[1,1] 消息:序言中不允许出现内容。

我刚刚开始使用 Mule,所以我认为这足以将 mule 重定向到服务以获取 wsdl,但它看起来有点复杂。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没企图 2025-01-11 23:38:51

免责声明:

  • 这不是整个问题的最终解决方案(包括调度到多个服务和聚合结果),而是朝着正确方向迈出的一步。
  • 这并不代表 Mule 中 Web 服务代理的实现方式(这是 方式更简单),但是是 HTTP 请求路由的准系统方法,因此可以添加聚合。

由于您想要将 HTTP GET 请求转发到 ?wsdl 处理器,并将 HTTP POST SOAP 请求转发到 Web 服务,因此您需要自己处理目标 HTTP 方法并请求 URI 传播:

<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>

(使用 TestWsClient 和 TestWsServer 进行测试和验证)< /em>

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文