You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by santhosh <ra...@gmail.com> on 2012/12/07 09:13:48 UTC

apache Camel cxf proxy doesnt work with http endpoint

My requirement is to have a proxy web service which will receive the request
from clients and then route through camel,enrich it and forward it to real
webservice at other clients place ,get response and send it back to the
original requestor.

i basically looked at camel-cxf-proxy example
(http://camel.apache.org/cxf-proxy-example.html) and camel-cxf-example in
camel distribution.Its exactly similar to camel-cxf-proxyand came up with
this route

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

where endpoints are

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

As you can see the second service is http endpoint.And first is the
camel-cxf proxy.I just have the wsdl and at this point there is no need for
impl.the dataformat is MESSAGE as i need the entire soap envelope to be sent
to second web service and there are some useful headers in request from
client.But when i run this route with a sample soap envelope it always comes
up with 500 response.I am thinking that message sent to real webservice is
not what it expects.I even tried the bridgeOption in httpendpoint.

I tried trace on camel route but it didnt show much.I was hoping it will
show real request to http endpoint.i tried to configure interceptor but that
didnt work either.Trace only shows following

 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

i even tried

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

I got a soap envelope and couldnt find anything wrong.

should i use wireshark and sniff the message that is actually sent??

I also tried the following which seems to be working.

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

callRemoteWS (callRemoteMethod) gets the soapenvelope as string and makes a
HTTPPost request to above endpoint , returns back the response.

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) {}
            }

          }

I am confused why the simple camel-cxf proxy with http webservice didnt work
and the second one works (it should and it does :P).Is the code i have ok.It
doesnt seem right to me.I am pretty sure some exchange property is set wrong
or content sent to real webservice is wrong.The content got from the proxy
is used to make the Httppost call in second route.so the content from proxy
cannot be wrong.when it is got from exchange and send to real webservice
something goes wrong. Can anybody throw some light on it.




--
View this message in context: http://camel.465427.n5.nabble.com/apache-Camel-cxf-proxy-doesnt-work-with-http-endpoint-tp5723753.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: apache Camel cxf proxy doesnt work with http endpoint

Posted by santhosh <ra...@gmail.com>.
My mistake.I figured what the problem was.I was sending the message to wrong
operation.I didnt notice the soap:action.So wrong data resulted in 500 error
from the server.But thanks guys ,aki and williem for taking time to read
such a long post.Much appreciated.I am starting to love the camel forum.



--
View this message in context: http://camel.465427.n5.nabble.com/apache-Camel-cxf-proxy-doesnt-work-with-http-endpoint-tp5723753p5723781.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: apache Camel cxf proxy doesnt work with http endpoint

Posted by Willem jiang <wi...@gmail.com>.
You need to use the Stream cache [1] when you route the input stream across the route before you route the message to log endpoint.
[1]http://camel.apache.org/stream-caching.html


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Friday, December 7, 2012 at 4:13 PM, santhosh wrote:

>  
> My requirement is to have a proxy web service which will receive the request
> from clients and then route through camel,enrich it and forward it to real
> webservice at other clients place ,get response and send it back to the
> original requestor.
>  
> i basically looked at camel-cxf-proxy example
> (http://camel.apache.org/cxf-proxy-example.html) and camel-cxf-example in
> camel distribution.Its exactly similar to camel-cxf-proxyand came up with
> this route
>  
> <from uri="cxf:bean:soapMessageEndpoint?dataFormat=MESSAGE" />
> <camel:convertBodyTo type="java.lang.String"></camel:convertBodyTo>
> <to ref="XService"></to>
>  
> where endpoints are
>  
> <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"/>
>  
> As you can see the second service is http endpoint.And first is the
> camel-cxf proxy.I just have the wsdl and at this point there is no need for
> impl.the dataformat is MESSAGE as i need the entire soap envelope to be sent
> to second web service and there are some useful headers in request from
> client.But when i run this route with a sample soap envelope it always comes
> up with 500 response.I am thinking that message sent to real webservice is
> not what it expects.I even tried the bridgeOption in httpendpoint.
>  
> I tried trace on camel route but it didnt show much.I was hoping it will
> show real request to http endpoint.i tried to configure interceptor but that
> didnt work either.Trace only shows following
>  
> 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
>  
> i even tried
>  
> <from uri="cxf:bean:soapMessageEndpoint?dataFormat=MESSAGE" />
> <to uri="log:input">
> <camel:convertBodyTo type="java.lang.String"></camel:convertBodyTo>
> <to ref="XService"></to>
>  
> I got a soap envelope and couldnt find anything wrong.
>  
> should i use wireshark and sniff the message that is actually sent??
>  
> I also tried the following which seems to be working.
>  
> <from uri="cxf:bean:soapMessageEndpoint?dataFormat=MESSAGE" />
> <camel:convertBodyTo type="java.lang.String"></camel:convertBodyTo>
> <to uri="bean:callRemoteWS"></to>
>  
> callRemoteWS (callRemoteMethod) gets the soapenvelope as string and makes a
> HTTPPost request to above endpoint , returns back the response.
>  
> 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) {}
> }
>  
> }
>  
> I am confused why the simple camel-cxf proxy with http webservice didnt work
> and the second one works (it should and it does :P).Is the code i have ok.It
> doesnt seem right to me.I am pretty sure some exchange property is set wrong
> or content sent to real webservice is wrong.The content got from the proxy
> is used to make the Httppost call in second route.so the content from proxy
> cannot be wrong.when it is got from exchange and send to real webservice
> something goes wrong. Can anybody throw some light on it.
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/apache-Camel-cxf-proxy-doesnt-work-with-http-endpoint-tp5723753.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: apache Camel cxf proxy doesnt work with http endpoint

Posted by Aki Yoshida <el...@gmail.com>.
I suppose the call is failing because you are not setting some
required properties (e.g., the http method) to fake the soap call.

      <camel:setHeader headerName="CamelHttpMethod">
        <camel:constant>POST</camel:constant>
      </camel:setHeader>
      <camel:setHeader headerName="Content-Type">
        <camel:constant>text/xml;charset="utf-8"</camel:constant>
      </camel:setHeader>

regards, aki

2012/12/7 santhosh <ra...@gmail.com>:
>
> My requirement is to have a proxy web service which will receive the request
> from clients and then route through camel,enrich it and forward it to real
> webservice at other clients place ,get response and send it back to the
> original requestor.
>
> i basically looked at camel-cxf-proxy example
> (http://camel.apache.org/cxf-proxy-example.html) and camel-cxf-example in
> camel distribution.Its exactly similar to camel-cxf-proxyand came up with
> this route
>
> <from uri="cxf:bean:soapMessageEndpoint?dataFormat=MESSAGE" />
> <camel:convertBodyTo type="java.lang.String"></camel:convertBodyTo>
> <to ref="XService"></to>
>
> where endpoints are
>
> <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"/>
>
> As you can see the second service is http endpoint.And first is the
> camel-cxf proxy.I just have the wsdl and at this point there is no need for
> impl.the dataformat is MESSAGE as i need the entire soap envelope to be sent
> to second web service and there are some useful headers in request from
> client.But when i run this route with a sample soap envelope it always comes
> up with 500 response.I am thinking that message sent to real webservice is
> not what it expects.I even tried the bridgeOption in httpendpoint.
>
> I tried trace on camel route but it didnt show much.I was hoping it will
> show real request to http endpoint.i tried to configure interceptor but that
> didnt work either.Trace only shows following
>
>  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
>
> i even tried
>
> <from uri="cxf:bean:soapMessageEndpoint?dataFormat=MESSAGE" />
> <to uri="log:input">
> <camel:convertBodyTo type="java.lang.String"></camel:convertBodyTo>
> <to ref="XService"></to>
>
> I got a soap envelope and couldnt find anything wrong.
>
> should i use wireshark and sniff the message that is actually sent??
>
> I also tried the following which seems to be working.
>
> <from uri="cxf:bean:soapMessageEndpoint?dataFormat=MESSAGE" />
> <camel:convertBodyTo type="java.lang.String"></camel:convertBodyTo>
> <to uri="bean:callRemoteWS"></to>
>
> callRemoteWS (callRemoteMethod) gets the soapenvelope as string and makes a
> HTTPPost request to above endpoint , returns back the response.
>
> 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) {}
>             }
>
>           }
>
> I am confused why the simple camel-cxf proxy with http webservice didnt work
> and the second one works (it should and it does :P).Is the code i have ok.It
> doesnt seem right to me.I am pretty sure some exchange property is set wrong
> or content sent to real webservice is wrong.The content got from the proxy
> is used to make the Httppost call in second route.so the content from proxy
> cannot be wrong.when it is got from exchange and send to real webservice
> something goes wrong. Can anybody throw some light on it.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/apache-Camel-cxf-proxy-doesnt-work-with-http-endpoint-tp5723753.html
> Sent from the Camel - Users mailing list archive at Nabble.com.