rest to soap

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

rest to soap

miri eyni
This post was updated on .
 public void configure() throws Exception {
   
   
    from("jetty:http://localhost:8080/json?matchOnUriPrefix=true").process(new Processor() {
                       
                        @Override
                        public void process(Exchange exchange) throws Exception {
                                BeanInvocation beanInvocation = new BeanInvocation();
                                beanInvocation.setMethod(PolicySOAPServices.class.getMethod("findPolicy",
    RequestPolicyView.class));
                                RequestPolicyView requestPolicyView = new RequestPolicyView();
                                requestPolicyView.setPolicyNo(1079);
                                Object[] args = new Object[] {requestPolicyView};
                                beanInvocation.setArgs(args);
                                exchange.getIn().setBody(beanInvocation);
                               
                        }
                }).to("http://localhost:9060/ws/policyServices/findPolicy?bridgeEndpoint=true");

 i got the following error :


016-05-16 09:13:19.359 ERROR 19624 --- [qtp302783055-16] o.a.camel.processor.DefaultErrorHandler  : Failed delivery for (MessageId: ID-HLLT-PC0A4F7B-50009-1463379165007-0-2 on ExchangeId: ID-HLLT-PC0A4F7B-50009-1463379165007-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: BeanInvocation public abstract com.camel.policy.ResponsePolicyView com.camel.policy.PolicySOAPServices.findPolicy(com.camel.policy.RequestPolicyView) with [com.camel.policy.RequestPolicyView@5796fabe]] of type: org.apache.camel.component.bean.BeanInvocation on: HttpMessage@0x7927fcde. Caused by: No type converter available to convert from type: org.apache.camel.component.bean.BeanInvocation to the required type: java.io.InputStream with value BeanInvocation public abstract com.camel.policy.ResponsePolicyView com.camel.policy.PolicySOAPServices.findPolicy(com.camel.policy.RequestPolicyView) with [com.camel.policy.RequestPolicyView@5796fabe]]. Exchange[ID-HLLT-PC0A4F7B-50009-1463379165007-0-1]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.component.bean.BeanInvocation to the required type: java.io.InputStream with value BeanInvocation public abstract com.camel.policy.ResponsePolicyView com.camel.policy.PolicySOAPServices.findPolicy(com.camel.policy.RequestPolicyView) with [com.camel.policy.RequestPolicyView@5796fabe]]]

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route1            ] [route1            ] [jetty:http://localhost:8080/json?matchOnUriPrefix=true                        ] [       189]
[route1            ] [process1          ] [Processor@0x6f08589b                                                          ] [        26]
[route1            ] [to1               ] [http://localhost:9060/ws/policyServices/findPolicy?bridgeEndpoin] [       160]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------

org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: BeanInvocation public abstract com.camel.policy.ResponsePolicyView com.camel.soap.interfaces.policy.PolicySOAPServices.findPolicy(com.camel.policy.RequestPolicyView) with [com.camel.policy.RequestPolicyView@5796fabe]] of type: org.apache.camel.component.bean.BeanInvocation on: HttpMessage@0x7927fcde. Caused by: No type converter available to convert from type: org.apache.camel.component.bean.BeanInvocation to the required type: java.io.InputStream with value BeanInvocation public abstract com.camel.policy.ResponsePolicyView com.camel.policy.PolicySOAPServices.findPolicy(com.camel.policy.RequestPolicyView) with [com.camel.policy.RequestPolicyView@5796fabe]]. Exchange[ID-HLLT-PC0A4F7B-50009-1463379165007-0-1]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.component.bean.BeanInvocation to the required type: java.io.InputStream with value BeanInvocation public abstract com.camel.policy.ResponsePolicyView com.camel.policy.PolicySOAPServices.findPolicy(com.camel.policy.RequestPolicyView) with [com.camel.policy.RequestPolicyView@5796fabe]]]
        at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:107) ~[camel-core-2.17.0.jar:2.17.0]
        at org.apache.camel.component.http.HttpProducer.createRequestEntity(HttpProducer.java:460) ~[camel-http-2.17.0.jar:2.17.0]
   

why is expected to get java.io.InputStream ?
what i did wrong?
Reply | Threaded
Open this post in threaded view
|

Re: rest to soap

yogu13
Looks like you are not reading the request body which has come in as part of the  from("jetty:http://localhost:8080/json?matchOnUriPrefix=true")

try reading it and convert it to the datatype that the route would use.


Regards,
-Yogesh
Reply | Threaded
Open this post in threaded view
|

Re: rest to soap

miri eyni
This post was updated on .
 now i process the request :

public void process(Exchange exchange) throws Exception {
                                 String payload = exchange.getIn().getBody(String.class);
                                 JSONObject jsonObj = JSONObject.fromObject(payload);

                               
                                BeanInvocation beanInvocation = new BeanInvocation();
                                beanInvocation.setMethod(PolicySOAPServices.class.getMethod("findPolicy",
    RequestPolicyView.class));
                                RequestPolicyView requestPolicyView = new RequestPolicyView();
                                requestPolicyView.setPolicyNo( (Integer)jsonObj.get("policyNo"));
                                Object[] args = new Object[] {requestPolicyView};
                                beanInvocation.setArgs(args);
                               
                                exchange.getIn().setBody(beanInvocation);
                               
                        }
                }).to("http://localhost:9060/ws/policyServices/findPolicy?bridgeEndpoint=true");

but i still get the same error ,what i did wrong?
   
Reply | Threaded
Open this post in threaded view
|

Re: rest to soap

yogu13
try setting the body of in message with the jsonObj

exchange.getIn().setBody(jsonObj);

and set the bean invocation to out as follows

exchange.getOut.setBody(beanInvocation)


Regards,
-Yogesh
Reply | Threaded
Open this post in threaded view
|

Re: rest to soap

miri eyni
the same error.

i am also tested :

         from("jetty:http://localhost:8080/json?matchOnUriPrefix=true").
    process(new Processor() {
                       
                        @Override
                        public void process(Exchange exchange) throws Exception {
                                String payload = exchange.getIn().getBody(String.class);
                                JSONObject jsonObj = JSONObject.fromObject(payload);
                                BeanInvocation beanInvocation = new BeanInvocation();
                                beanInvocation.setMethod(PolicySOAPServices.class.getMethod("findPolicy",
    RequestPolicyView.class));
                                RequestPolicyView requestPolicyView = new RequestPolicyView();
                                requestPolicyView.setPolicyNo( (Integer)jsonObj.get("policyNo"));
                                Object[] args = new Object[] {requestPolicyView};
                                beanInvocation.setArgs(args);
                                exchange.getIn().setBody(beanInvocation);
                        }
                }).marshal().xstream().to("localhost:9060/ws/policyServices/findPolicy?bridgeEndpoint=true");

and  i got :
HTTP operation failed invoking http://localhost:9060/ws/policyServices/findPolicy with statusCode: 403
   

i try to routing from rest to soap ,
Reply | Threaded
Open this post in threaded view
|

Re: rest to soap

yogu13
Status code 403 means its forbidden to access the url.

is the url protected ? if yes then you might have to provide authentication details

Regards,
-Yogesh
Reply | Threaded
Open this post in threaded view
|

Re: rest to soap

miri eyni
thanks, i fixed the url

but now i got status code :500

i check the server.log

and its look like the request is a rest request instead of soap.request


Content-Type: application/soap+xml
Headers: {alis-datasource-key=[1], breadcrumbId=[ID-HLLT-PC0A4F7B-53348-1463390080537-0-2], Content-Length=[686], content-type=[application/soap+xml], Host=[localhost:8888], User-Agent=[Jakarta Commons-HttpClient/3.1]}
Payload: <?xml version='1.0' encoding='UTF-8'?><org.apache.camel.component.bean.BeanInvocation><org.apache.camel.component.bean.MethodBean><name>findPolicy</name><type>com.camel.policy.PolicySOAPServices</type><parameterTypes><java-class>com.camel.policy.RequestPolicyView</java-class></parameterTypes></org.apache.camel.component.bean.MethodBean><object-array><com.camel.policy.RequestPolicyView><policyNo>1079</policyNo></com.sapiens.alis.foundation.external.model.entities.dto.policy.RequestPolicyView></object-array></org.apache.camel.component.bean.BeanInvocation>
--------------------------------------
[2016-05-16 12:14:49.114],[WARN ],[LogUtils.java:452],[],Interceptor for {http://policy.camel.com/}PolicyGenericServicesImplService has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: HTTP verb was not GET or POST

Do you know what is wrong ?
Reply | Threaded
Open this post in threaded view
|

Re: rest to soap

yogu13
You need to transform the data which your SOAP endpoint can understand.

Looks like you are missing that piece of code.

BTW I see your payload is XML instead of JSON from the logs you added.

Regards,
-Yogesh
Reply | Threaded
Open this post in threaded view
|

Re: rest to soap

miri eyni
i converted the json to xml
i try to send soap request from rest , on the process method i converted the body to xml
but i think i am missing somethings ,

from - is rest url
to - is webService url (soap)


from("jetty:http://localhost:8080/json?matchOnUriPrefix=true")

public void process(Exchange exchange) throws Exception {
                                String payload = exchange.getIn().getBody(String.class);
                                JSONObject jsonObj = JSONObject.fromObject(payload);
                                BeanInvocation beanInvocation = new BeanInvocation();
                                beanInvocation.setMethod(PolicySOAPServices.class.getMethod("findPolicy",
    RequestPolicyView.class));
                                RequestPolicyView requestPolicyView = new RequestPolicyView();
                                requestPolicyView.setPolicyNo( (Integer)jsonObj.get("policyNo"));
                                Object[] args = new Object[] {requestPolicyView};
                                beanInvocation.setArgs(args);
                                exchange.getIn().setBody(beanInvocation);
                        }
                }).marshal().xstream().to("http://localhost:6090/ws/policyServices?bridgeEndpoint=true&soapAction=http://policy.camel.com&wsAddressingAction=http://policy.camel.com");
Reply | Threaded
Open this post in threaded view
|

Re: rest to soap

yogu13
A simpler way would be to use camel-cxf see if your can use this http://camel.apache.org/cxf.html

Regards,
-Yogesh

On Mon, May 16, 2016 at 5:14 PM, miri eyni [via Camel] <[hidden email]> wrote:
i converted the json to xml
i try to send soap request from rest , on the process method i converted the body to xml
but i think i am missing somethings ,

from - is rest url
to - is webService url (soap)


from("jetty:http://localhost:8080/json?matchOnUriPrefix=true")

public void process(Exchange exchange) throws Exception {
                                String payload = exchange.getIn().getBody(String.class);
                                JSONObject jsonObj = JSONObject.fromObject(payload);
                                BeanInvocation beanInvocation = new BeanInvocation();
                                beanInvocation.setMethod(PolicySOAPServices.class.getMethod("findPolicy",
    RequestPolicyView.class));
                                RequestPolicyView requestPolicyView = new RequestPolicyView();
                                requestPolicyView.setPolicyNo( (Integer)jsonObj.get("policyNo"));
                                Object[] args = new Object[] {requestPolicyView};
                                beanInvocation.setArgs(args);
                                exchange.getIn().setBody(beanInvocation);
                        }
                }).marshal().xstream().to("http://localhost:6090/ws/policyServices?bridgeEndpoint=true&soapAction=http://policy.camel.com&wsAddressingAction=http://policy.camel.com");


If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/rest-to-soap-tp5782601p5782665.html
To unsubscribe from rest to soap, click here.
NAML