首页 文章

camel cxf代理不能与http endpoints 一起使用

提问于
浏览
3

我的要求是拥有一个代理Web服务,它将接收来自客户端的请求,然后通过camel路由,丰富它并将其转发到其他客户端的真实webservice,获得响应并将其发送回原始请求者 .

我基本上看了camel-cxf-proxy示例(http://camel.apache.org/cxf-proxy-example.html)和camel-cxf-example in camel distribution.Its与camel-cxf-proxy完全相似并且出现了有这条路线

<from uri="cxf:bean:soapMessageEndpoint?dataFormat=MESSAGE" />
<camel:convertBodyTo type="java.lang.String"></camel:convertBodyTo>
<to ref="XService"></to>

endpoints 在哪里

<endpoint id="XService" uri="http://xx.xx.xxx.xx:8080/X_Service" />

<cxf:cxfEndpoint id="soapMessageEndpoint" address="http://localhost:8181/ProviderInformationDirectoryService"  wsdlURL="wsdl/HPD_ProviderInformationDirectory.wsdl" endpointName="s:ProviderInformationDirectory_Port_Soap" serviceName="s:ProviderInformationDirectory_Service" xmlns:s="urn:ihe:iti:hpd:2010"/>

你可以看到第二个服务是http endpoint.And首先是camel-cxf代理 . 我只有wsdl,此时不需要impl.the dataformat是MESSAGE,因为我需要发送整个soap信封到第二个Web服务,并且在客户端的请求中有一些有用的 Headers . 但是当我使用示例soap信封运行此路由时,它始终会产生500响应 . 我认为发送到真实web服务的消息不是它所期望的 .

我尝试跟踪骆驼路线,但它没有显示太多 . 我希望它将显示真实请求http endpoint.i试图配置拦截器,但也没有工作.Trace只显示以下

Failed delivery for (MessageId: ID-ALHCAN0437-63941-1354828653539-45-2 on ExchangeId: ID-ALHCAN0437-63941-1354828653539-45-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.component.http.HttpOperationFailedException: HTTP operation failed invoking http://X:8080/X_Service with statusCode: 500

我也试过以下似乎工作 .

<from uri="cxf:bean:soapMessageEndpoint?dataFormat=MESSAGE" />
<camel:convertBodyTo type="java.lang.String"></camel:convertBodyTo>
<to uri="bean:callRemoteWS"></to>

callRemoteWS(callRemoteMethod)将soapenvelope作为字符串获取并向上方 endpoints 发出HTTPPost请求,并返回响应 .

public String callRemoteMethod(String request) throws Exception{



            HttpClient client = new HttpClient();

            BufferedReader br = null;

            PostMethod method = new PostMethod("http://x.x.x.x:8080/X_Service");

            RequestEntity entity =new StringRequestEntity(request); 

            method.setRequestEntity(entity);

            try{
              int returnCode = client.executeMethod(method);

              if (returnCode != HttpStatus.SC_OK) {
                  System.err.println("Method failed: " + method.getStatusLine());
                  return "Error";
                }

                // Read the response body.
                byte[] responseBody = method.getResponseBody();

                System.out.println(new String(responseBody));

                // Deal with the response.
                // Use caution: ensure correct character encoding and is not binary data
               return new String(responseBody);
            } finally {
              method.releaseConnection();
              if(br != null) try { br.close(); } catch (Exception fe) {}
            }

          }

我很困惑,为什么简单的camel-cxf代理与http webservice没有工作,第二个工作(它应该和它做:P) . 我的代码我没关系 . 它似乎不对我 . 我很确定一些交换属性设置错误或发送到真正的webservice的内容是错误的 . 从代理获得的内容用于在第二个路由中进行Httppost调用 . 所以来自代理的内容不能是错误的 . 当它从交换获得并发送到真正的webservice出了点问题 . 任何人都可以对此有所了解 .

1 回答

  • 0

    我认为这是一个愚蠢的错误.Soap动作头有一个不同的操作,有效载荷用于不同的方法 . 我用有效载荷调用错误的操作

相关问题