4
votes

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

1

1 Answers

0
votes

I think it was a silly mistake on my part .Soap action header had a different operation and the payload was for a different method.I was invoking the wrong operation with the payload