You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by James Talbut <jt...@tardis.spudsoft> on 2011/09/15 12:13:30 UTC

How can I call a web service with no parameters via a producerTemplate?

Hi,

I have to call a web service with an operation that maps to:
public java.lang.String ping();

When I try to call it using a productTemplate I keep getting:
Get the wrong parameter size to invoke the out service, Expect size 0, Parameter size 1. Please check if the message body matches the CXFEndpoint POJO Dataformat request.

I've tried calling with a null body and without specifying a body at all, but it still generates the same error.
Is there any way I can call this operation?

Thanks

Jim

Re: How can I call a web service with no parameters via a producerTemplate?

Posted by "viral.patel69" <vi...@algorhythm.co.in>.
If i remove that part then it will give me error " Service class not found"

So what to do.



--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-call-a-web-service-with-no-parameters-via-a-producerTemplate-tp4806257p5745619.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I call a web service with no parameters via a producerTemplate?

Posted by "Willem.Jiang" <wi...@gmail.com>.
You set a wrong url, please remove the option of dataFormat=MESSAGE because
you just invocation the web service with a string instead of SOAP message
output stream.



--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-call-a-web-service-with-no-parameters-via-a-producerTemplate-tp4806257p5745618.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I call a web service with no parameters via a producerTemplate?

Posted by "viral.patel69" <vi...@algorhythm.co.in>.
Please any one suggest solution for my problem.





--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-call-a-web-service-with-no-parameters-via-a-producerTemplate-tp4806257p5745580.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I call a web service with no parameters via a producerTemplate?

Posted by "viral.patel69" <vi...@algorhythm.co.in>.
Dear William,

Actually Web method contains single argument, so I have passed
"Hello"(*exchange.getIn().setBody("Hello"); *). Can u tell me what is the
problem of bellow code.

*Web Service Method:*
         public String getApplication(String data) { 
                System.out.println("getApplication"); 
                return "GetApplication Method Call :"; 
         } 

*Calling Code.*
static CamelContext context; 

        public static void main(String args[]) throws Exception { 
                CamelContext context = new DefaultCamelContext(); 
                ProducerTemplate template =
context.createProducerTemplate(0); 
                context.start(); 
                String url =
"cxf://http://localhost:8081/buzzor-service/services/ApplicationService?" 
                                +
"wsdlURL=http://localhost:8081/buzzor-service/services/ApplicationService?wsdl&" 
                                +
"serviceName={http://service.application.buzzor.atpl.com}ApplicationService&" 
                                +
"portName={http://service.application.buzzor.atpl.com}ApplicationServiceHttpPort&" 
                                + "dataFormat=MESSAGE"; 
                Exchange reply = sendSimpleMessage(template, url); 
                org.apache.camel.Message out = reply.getOut(); 
                String result = out.getBody(String.class); 

                System.out.println(reply); 
                Thread.sleep(10000); 
                context.stop(); 
        } 

private static Exchange sendSimpleMessage(ProducerTemplate template, 
                        String endpointUri) { 

                Exchange exchange = template.request(endpointUri, new
Processor() { 
                        public void process(final Exchange exchange) { 
                                exchange.getIn().setBody("Hello"); 
                               
exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, 
                                                "getApplication"); 
                               
exchange.getIn().setHeader(CxfConstants.OPERATION_NAMESPACE, 
                                               
"http://service.application.buzzor.atpl.com"); 
                               
exchange.getIn().setHeader(Exchange.FILE_NAME, "testFile"); 
                                exchange.getIn().setHeader("requestObject", 
                                                new DefaultCxfBinding()); 
                         } 
                }); 
                return exchange; 

        } 

*After Executing this code. no error thrown by this code but web service
also not called. 

in result variable Bellow Message has been received 

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>ParseError
at [row,col]:[1,1] 
Message: Content is not allowed in
prolog.</faultstring></soap:Fault></soap:Body></soap:Envelope>*



--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-call-a-web-service-with-no-parameters-via-a-producerTemplate-tp4806257p5745433.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I call a web service with no parameters via a producerTemplate?

Posted by Willem Jiang <wi...@gmail.com>.
As you set the invocation parameter as POJO list, you need to set the dataFormate to be POJO.
Because camel-cxf default data format is POJO, removing the endpointUri option of dataFormat should work for you.


--  
Willem Jiang

Red Hat, Inc.
Web: 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 January 2, 2014 at 5:51:07 PM, viral.patel69 (viral.patel@algorhythm.co.in) wrote:
>  
> Done Required changes still have some issue.
> String endpointUri=
> "cxf://http://localhost:8081/buzzor-service/services/ApplicationService?"  
> +
> "wsdlURL=http://localhost:8081/buzzor-service/services/ApplicationService?wsdl&"  
> +
> "serviceName={http://service.application.buzzor.atpl.com}ApplicationService&"  
> +
> "portName={http://service.application.buzzor.atpl.com}ApplicationServiceHttpPort&"  
> + "dataFormat=MESSAGE";
>  
> Exchange exchange = template.request(endpointUri, new Processor()  
> {
> public void process(final Exchange exchange) {
> List oList = new ArrayList();
> oList.add("Hello");
> exchange.getIn().setBody(oList);
> exchange.getIn().setHeader(CxfConstants.OPERATION_NAME,  
> "getApplication");
> exchange.getIn().setHeader(CxfConstants.OPERATION_NAMESPACE,  
> "http://service.application.buzzor.atpl.com");
> exchange.getIn().setHeader(Exchange.FILE_NAME, "testFile");  
> exchange.getIn().setHeader("requestObject",
> new DefaultCxfBinding());
> SOAPMessage message = processSOAP(exchange);
> System.out.println(message);
>  
> }
> });
>  
>  
> *Now i got an same error
>  
> org.apache.camel.InvalidPayloadException: No body available  
> of type:
> java.io.InputStream but has value: [Hello] of type: java.util.ArrayList  
> on:
> Message: [Hello]. Caused by: No type converter available to  
> convert from
> type: java.util.ArrayList to the required type: java.io.InputStream  
> with
> value [Hello]. Exchange[Message: [Hello]]. Caused by:
> [org.apache.camel.NoTypeConversionAvailableException  
> - No type converter
> available to convert from type: java.util.ArrayList to the  
> required type:
> java.io.InputStream with value [Hello]]*
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-call-a-web-service-with-no-parameters-via-a-producerTemplate-tp4806257p5745425.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.  
>  


Re: How can I call a web service with no parameters via a producerTemplate?

Posted by "viral.patel69" <vi...@algorhythm.co.in>.
Done Required changes still have some issue.
String endpointUri=
"cxf://http://localhost:8081/buzzor-service/services/ApplicationService?"
				+
"wsdlURL=http://localhost:8081/buzzor-service/services/ApplicationService?wsdl&"
				+
"serviceName={http://service.application.buzzor.atpl.com}ApplicationService&"
				+
"portName={http://service.application.buzzor.atpl.com}ApplicationServiceHttpPort&"
				+ "dataFormat=MESSAGE";

Exchange exchange = template.request(endpointUri, new Processor() {
			public void process(final Exchange exchange) {
				List<String> oList = new ArrayList<String>();
				oList.add("Hello");
				exchange.getIn().setBody(oList);
				exchange.getIn().setHeader(CxfConstants.OPERATION_NAME,
						"getApplication");
				exchange.getIn().setHeader(CxfConstants.OPERATION_NAMESPACE,
						"http://service.application.buzzor.atpl.com");
				exchange.getIn().setHeader(Exchange.FILE_NAME, "testFile");
				exchange.getIn().setHeader("requestObject",
						new DefaultCxfBinding());
				SOAPMessage message = processSOAP(exchange);
				System.out.println(message);

			}
		});


*Now i got an same error

org.apache.camel.InvalidPayloadException: No body available of type:
java.io.InputStream but has value: [Hello] of type: java.util.ArrayList on:
Message: [Hello]. Caused by: No type converter available to convert from
type: java.util.ArrayList to the required type: java.io.InputStream with
value [Hello]. Exchange[Message: [Hello]]. Caused by:
[org.apache.camel.NoTypeConversionAvailableException - No type converter
available to convert from type: java.util.ArrayList to the required type:
java.io.InputStream with value [Hello]]*



--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-call-a-web-service-with-no-parameters-via-a-producerTemplate-tp4806257p5745425.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I call a web service with no parameters via a producerTemplate?

Posted by Willem Jiang <wi...@gmail.com>.
Please use exchange.getIn() instead of exchange.getOut() in the process method.


--  
Willem Jiang

Red Hat, Inc.
Web: 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 January 2, 2014 at 4:14:40 PM, viral.patel69 (viral.patel@algorhythm.co.in) wrote:
>  
> Dear,
>  
> I also want to call third party web service using camel but i am  
> unable to
> call.
>  
> I have tried two things
>  
> First is:Creating SOAP String manually.
>  
> Exchange exchange = template.request(endpointUri, new Processor()  
> {
> public void process(final Exchange exchange) throws Exception  
> {
>  
> exchange.getIn()
> .setBody(
> "> xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"  
> + "> xmlns:ns1=\"http://service.application.buzzor.atpl.com\">"  
> + "> xmlns=\"http://service.application.buzzor.atpl.com\">hello  
> world"
> + "");  
>  
> }
> });
> return exchange;
>  
> This code will call Web Service but instead of creating manually  
> string when
> i have tried bellow code for calling web service it will give an  
> error
>  
> String url =
> "cxf://http://localhost:8081/buzzor-service/services/ApplicationService?"  
> +
> "wsdlURL=http://localhost:8081/buzzor-service/services/ApplicationService?wsdl&"  
> +
> "serviceName={http://service.application.buzzor.atpl.com}ApplicationService&"  
> +
> "portName={http://service.application.buzzor.atpl.com}ApplicationServiceHttpPort&"  
> + "dataFormat=MESSAGE";
> Exchange exchange = template.request(url, new Processor()  
> {
> public void process(final Exchange exchange) {
>  
> exchange.getOut().setBody("Hello");
> exchange.getOut().setHeader(CxfConstants.OPERATION_NAME,  
> "getApplication");
> exchange.getOut().setHeader(CxfConstants.OPERATION_NAMESPACE,  
> "http://service.application.buzzor.atpl.com");
> exchange.getOut().setHeader(Exchange.FILE_NAME, "testFile");  
> exchange.getOut().setHeader("requestObject",
> new DefaultCxfBinding());
>  
> }
> });
> return exchange;
>  
>  
> *Exception is "org.apache.camel.InvalidPayloadException:  
> No body available
> of type: java.io.InputStream on: Message: [Body is null]. Caused  
> by: No type
> converter available to convert from type: null to the required  
> type:
> java.io.InputStream with value null. Exchange[Message: Hello].  
> Caused by:
> [org.apache.camel.NoTypeConversionAvailableException  
> - No type converter
> available to convert from type: null to the required type:
> java.io.InputStream with value null]"*
>  
> Can any one help me to resolved my problem.
>  
> Thanks in Advance.
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-call-a-web-service-with-no-parameters-via-a-producerTemplate-tp4806257p5745421.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.  
>  


Re: How can I call a web service with no parameters via a producerTemplate?

Posted by "viral.patel69" <vi...@algorhythm.co.in>.
Dear,

I also want to call third party web service using camel but i am unable to
call.

I have tried two things

First is:Creating SOAP String manually.

Exchange exchange = template.request(endpointUri, new Processor() {
			public void process(final Exchange exchange) throws Exception {

				exchange.getIn()
						.setBody(
								"<soap:Envelope
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
										+ "<soap:Body><ns1:getApplication
xmlns:ns1=\"http://service.application.buzzor.atpl.com\">"
										+ "<arg0
xmlns=\"http://service.application.buzzor.atpl.com\">hello world</arg0>"
										+ "</ns1:getApplication></soap:Body></soap:Envelope>");

			}
		});
		return exchange;

This code will call Web Service but instead of creating manually string when
i have tried bellow code for calling web service it will give an error

String url =
"cxf://http://localhost:8081/buzzor-service/services/ApplicationService?"
				+
"wsdlURL=http://localhost:8081/buzzor-service/services/ApplicationService?wsdl&"
				+
"serviceName={http://service.application.buzzor.atpl.com}ApplicationService&"
				+
"portName={http://service.application.buzzor.atpl.com}ApplicationServiceHttpPort&"
				+ "dataFormat=MESSAGE";
		Exchange exchange = template.request(url, new Processor() {
			public void process(final Exchange exchange) {

				exchange.getOut().setBody("Hello");
				exchange.getOut().setHeader(CxfConstants.OPERATION_NAME,
						"getApplication");
				exchange.getOut().setHeader(CxfConstants.OPERATION_NAMESPACE,
						"http://service.application.buzzor.atpl.com");
				exchange.getOut().setHeader(Exchange.FILE_NAME, "testFile");
				exchange.getOut().setHeader("requestObject",
						new DefaultCxfBinding());

			}
		});
		return exchange;


*Exception is "org.apache.camel.InvalidPayloadException: No body available
of type: java.io.InputStream on: Message: [Body is null]. Caused by: No type
converter available to convert from type: null to the required type:
java.io.InputStream with value null. Exchange[Message: Hello]. Caused by:
[org.apache.camel.NoTypeConversionAvailableException - No type converter
available to convert from type: null to the required type:
java.io.InputStream with value null]"*

Can any one help me to resolved my problem.

Thanks in Advance.



--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-call-a-web-service-with-no-parameters-via-a-producerTemplate-tp4806257p5745421.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I call a web service with no parameters via a producerTemplate?

Posted by Jim Talbut <jt...@spudsoft.co.uk>.
Thank you Willem, that works.
My call is now:
                 return template.requestBodyAndHeaders( this.groupsUri, 
new Object[0], headers, String.class );
and I get the expected response.

The "ping" operation is just a test one, but now it means I can make my 
test use much more of my main code.

Thanks again.

Jim

On 15/09/2011 14:11, Willem Jiang wrote:
>
> Can you try to set the message with new object array with a length 0 ?
> Like this
> exchange.getIn().setBody(new Object[0]).
>
> On 9/15/11 6:13 PM, James Talbut wrote:
>> Hi,
>>
>> I have to call a web service with an operation that maps to:
>> public java.lang.String ping();
>>
>> When I try to call it using a productTemplate I keep getting:
>> Get the wrong parameter size to invoke the out service, Expect size 
>> 0, Parameter size 1. Please check if the message body matches the 
>> CXFEndpoint POJO Dataformat request.
>>
>> I've tried calling with a null body and without specifying a body at 
>> all, but it still generates the same error.
>> Is there any way I can call this operation?
>>
>> Thanks
>>
>> Jim
>>
>
>


Re: How can I call a web service with no parameters via a producerTemplate?

Posted by Willem Jiang <wi...@gmail.com>.
Can you try to set the message with new object array with a length 0 ?
Like this
exchange.getIn().setBody(new Object[0]).

On 9/15/11 6:13 PM, James Talbut wrote:
> Hi,
>
> I have to call a web service with an operation that maps to:
> public java.lang.String ping();
>
> When I try to call it using a productTemplate I keep getting:
> Get the wrong parameter size to invoke the out service, Expect size 0, Parameter size 1. Please check if the message body matches the CXFEndpoint POJO Dataformat request.
>
> I've tried calling with a null body and without specifying a body at all, but it still generates the same error.
> Is there any way I can call this operation?
>
> Thanks
>
> Jim
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Re: How can I call a web service with no parameters via a producerTemplate?

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

Can you post a snippet of the call you are making with the producerTemplate,
WSDL document and the exact error you get...

Thanks,

Ashwin... 

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-call-a-web-service-with-no-parameters-via-a-producerTemplate-tp4806257p4806394.html
Sent from the Camel - Users mailing list archive at Nabble.com.