如何用Mule创建动态的HTTP代理服务

 我来答
huanglenzhi
2015-03-31 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117525 获赞数:517229
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部
  引入动态http代理的主要目的是在加入新的http代理而不需要重启Mule代理服务。注意,要真正的动态代理,需要注入实现了路径与服务器地址映射的检索服务的Spring的Bean,在enricher位置通过groovy获得Bean的实例进行调用。
  
  实例程序的限制:
  这个例子程序缺乏生产环境中使用处理:
  错误处理
  从数据库检索路径的映射配置信息
  这个例子将HTTP相对路径和目标服务器之间的映射写在XML配置文件里。这当然不能允许动态修改代理配置。
  支持更多的HTTP方法
  只支持HTTP get和post方法
  处理的HTTP参数。
  实例程序没考虑HTTP参数但这些都被认为是在HTTP相对路径的一部分。
  支持HTTPS。
  
  为了能够有一个服务代理,一个简单的SOAP问候服务使用一个Mule配置文件和一个Java类实现。
  Mule配置包含以下配置:
  01.<?xml version="1.0" encoding="UTF-8"?>
  02.<mule
  03.xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
  04.xmlns="http://www.mulesoft.org/schema/mule/core"
  05.xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
  06.xmlns:spring="http://www.springframework.org/schema/beans"
  07.xmlns:test="http://www.mulesoft.org/schema/mule/test"
  08.xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  09.xsi:schemaLocation="
  10.http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
  11.http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
  12.http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
  13.http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd"
  14.
  15.<spring:beans>
  16.<spring:bean id="helloService" class="com.ivan.mule.dynamichttpproxy.HelloService"/>
  17.</spring:beans>
  18.
  19.<flow name="GreetingFlow">
  20.<inbound-endpoint address="http://localhost:8182/services/GreetingService"
  21.exchange-pattern="request-response"/>
  22.
  23.<cxf:jaxws-service serviceClass="com.ivan.mule.dynamichttpproxy.HelloService"/>
  24.<component>
  25.<spring-object bean="helloService"/>
  26.</component>
  27.</flow>
  28.</mule>
  
  服务类:
  01.package com.ivan.mule.dynamichttpproxy;
  02.
  03.import java.util.Date;
  04.import javax.jws.WebParam;
  05.import javax.jws.WebResult;
  06.import javax.jws.WebService;
  07.
  08./**
  09.* SOAP web service endpoint implementation class that implements
  10.* a service that extends greetings.
  11.*
  12.* @author Ivan Krizsan
  13.*/
  14.@WebService
  15.public class HelloService {
  16./**
  17.* Greets the person with the supplied name.
  18.*
  19.* @param inName Name of person to greet.
  20.* @return Greeting.
  21.*/
  22.@WebResult(name = "greeting")
  23.public String greet(@WebParam(name = "inName") final String inName) {
  24.return "Hello " + inName + ", the time is now " + new Date();
  25.}
  26.}
  
  
  服务器信息Bean,用于存储原始HTTP请求路径与对应目标服务器ip端口的映射信息:
  01.package com.ivan.mule.dynamichttpproxy;
  02.
  03./**
  04.* Holds information about a server which to forward requests to.
  05.*
  06.* @author Ivan Krizsan
  07.*/
  08.public class ServerInformationBean {
  09.private String serverAddress;
  10.private String serverPort;
  11.private String serverName;
  12.
  13./**
  14.* Creates an instance holding information about a server with supplied
  15.* address, port and name.
  16.*
  17.* @param inServerAddress
  18.* @param inServerPort
  19.* @param inServerName
  20.*/
  21.public ServerInformationBean(final String inServerAddress,
  22.final String inServerPort, final String inServerName) {
  23.serverAddress = inServerAddress;
  24.serverPort = inServerPort;
  25.serverName = inServerName;
  26.}
  27.
  28.public String getServerAddress() {
  29.return serverAddress;
  30.}
  31.
  32.public String getServerPort() {
  33.return serverPort;
  34.}
  35.
  36.public String getServerName() {
  37.return serverName;
  38.}
  39.}
  

  
Storm代理
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企... 点击进入详情页
本回答由Storm代理提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式