You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by John Baker <jb...@javasystemsolutions.com> on 2009/06/21 13:28:00 UTC
WS client, original message
Hello,
How does one obtain the raw SOAP message returned from a client webservice
call? Ideally, as String or a Document would be nice.
John
Re: WS client, original message
Posted by Daniel Kulp <dk...@apache.org>.
On Wed June 24 2009 1:09:21 pm John Baker wrote:
> Dan,
>
> Do you have any thoughts on how to replace the Axis code:
>
> Service service = new Service();
> Call call = (Call)service.createCall();
> call.setTargetEndpointAddress(new URL(endPoint));
> call.setOperationName(new QName("http://www.xyz.com", method) );
> if (username != null) call.setUsername(username);
> if (password != null) call.setPassword(password);
> String ret = (String)call.invoke(new Object[] { message });
>
> I get a NullPointerException when I execute it, coming from:
>
> at
> org.apache.cxf.service.factory.ReflectionServiceFactoryBean.checkServiceCla
>ssAnnotations(ReflectionServiceFactoryBean.java:2156)
>
> Apparently because I'm not setting a service class. However I don't have a
> service class - this is an anonymous call.
I don't really think there is a way. With JAX-WS (and CXF), you either need
to:
1) Provide a description for how to format the soap body, usually through a
wsdl.
or
2) Handle the entire contents of the soap body yourself (via Dispatch in
PAYLOAD mode). That would require you to create a DOM (or streamsource) or
similar to format the payload.
The authorization stuff is simple. The JAX-WS spec covers that via the
BindingProvider request context. The rest of the code above is not really
migrateable easily.
Dan
>
> Thanks,
>
>
> John
>
> On Monday 22 June 2009 20:03:46 you wrote:
> > I don't think it's QUITE as simple with JAX-WS. The code would look
> > similar to:
> >
> > Service service = Service.create(serviceName);
> > service.addPort(portName, "http://schemas.xmlsoap.org/soap/",
> >
> > "http://localhost:9006/SOAPDispatchService/SoapDispatchPort");
> > (serviceName and portName could be fairly random QNames)
> > Dispatch<DOMSource> disp = service.createDispatch(portName,
> > DOMSource.class, Service.Mode.PAYLOAD);
> > (You can use DOMSource, StreamSource, SAXSource)
> >
> >
> > DOMSource domResMsg = disp.invoke(domReqMsg);
> >
> >
> >
> > Dan
> >
> > On Sun June 21 2009 9:35:17 am John Baker wrote:
> > > Hi,
> > >
> > > Thanks for your response. I've written an interceptor to do it, but
> > > was just looking at the Dispatch API. I've got some old Axis code that
> > > I'm replacing - it does this:
> > >
> > > Service service = new Service();
> > > Call call = (Call)service.createCall();
> > > call.setTargetEndpointAddress(new URL(endPoint));
> > > call.setOperationName(new QName("http://www.xyz.com", method)
> > > ); if (username != null) call.setUsername(username);
> > > if (password != null) call.setPassword(password);
> > > String ret = (String)call.invoke(new Object[] { message });
> > >
> > > Is that easy to replace with the jaxws (dispatch?) api? It did nothing
> > > more than call a WS method, passing one parameter and assuming a String
> > > response. No WSDL involved...
> > >
> > >
> > > John
> > >
> > > P.S. If anyone needs the interceptor then I'm happy to post it.
> > >
> > > On Sunday 21 June 2009 13:19:37 you wrote:
> > > > John Baker wrote:
> > > > > Hello,
> > > > >
> > > > > How does one obtain the raw SOAP message returned from a client
> > > > > webservice call? Ideally, as String or a Document would be nice.
> > > > >
> > > > >
> > > > > John
> > > >
> > > > You can achieve the same in either of two ways:
> > > >
> > > > A. You can use Dispatch API [1] to write your client where you can
> > > > get either Message (Body element) or Payload (entire SOAP Envelope).
> > > > or
> > > > B. You can write and plugin your own interceptor [2] in the
> > > > interceptor chain where you can get the hold of soap message.
> > > >
> > > > With Regards,
> > > > Mayank
> > > >
> > > > [1]. http://cwiki.apache.org/CXF20DOC/jax-ws-dispatch-api.html
> > > > [2]. http://cwiki.apache.org/CXF20DOC/interceptors.html
--
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog
Re: WS client, original message
Posted by John Baker <jb...@javasystemsolutions.com>.
Dan,
Do you have any thoughts on how to replace the Axis code:
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new URL(endPoint));
call.setOperationName(new QName("http://www.xyz.com", method) );
if (username != null) call.setUsername(username);
if (password != null) call.setPassword(password);
String ret = (String)call.invoke(new Object[] { message });
I get a NullPointerException when I execute it, coming from:
at
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.checkServiceClassAnnotations(ReflectionServiceFactoryBean.java:2156)
Apparently because I'm not setting a service class. However I don't have a
service class - this is an anonymous call.
Thanks,
John
On Monday 22 June 2009 20:03:46 you wrote:
> I don't think it's QUITE as simple with JAX-WS. The code would look
> similar to:
>
> Service service = Service.create(serviceName);
> service.addPort(portName, "http://schemas.xmlsoap.org/soap/",
>
> "http://localhost:9006/SOAPDispatchService/SoapDispatchPort"); (serviceName
> and portName could be fairly random QNames)
> Dispatch<DOMSource> disp = service.createDispatch(portName,
> DOMSource.class, Service.Mode.PAYLOAD);
> (You can use DOMSource, StreamSource, SAXSource)
>
>
> DOMSource domResMsg = disp.invoke(domReqMsg);
>
>
>
> Dan
>
> On Sun June 21 2009 9:35:17 am John Baker wrote:
> > Hi,
> >
> > Thanks for your response. I've written an interceptor to do it, but was
> > just looking at the Dispatch API. I've got some old Axis code that I'm
> > replacing - it does this:
> >
> > Service service = new Service();
> > Call call = (Call)service.createCall();
> > call.setTargetEndpointAddress(new URL(endPoint));
> > call.setOperationName(new QName("http://www.xyz.com", method) );
> > if (username != null) call.setUsername(username);
> > if (password != null) call.setPassword(password);
> > String ret = (String)call.invoke(new Object[] { message });
> >
> > Is that easy to replace with the jaxws (dispatch?) api? It did nothing
> > more than call a WS method, passing one parameter and assuming a String
> > response. No WSDL involved...
> >
> >
> > John
> >
> > P.S. If anyone needs the interceptor then I'm happy to post it.
> >
> > On Sunday 21 June 2009 13:19:37 you wrote:
> > > John Baker wrote:
> > > > Hello,
> > > >
> > > > How does one obtain the raw SOAP message returned from a client
> > > > webservice call? Ideally, as String or a Document would be nice.
> > > >
> > > >
> > > > John
> > >
> > > You can achieve the same in either of two ways:
> > >
> > > A. You can use Dispatch API [1] to write your client where you can get
> > > either Message (Body element) or Payload (entire SOAP Envelope).
> > > or
> > > B. You can write and plugin your own interceptor [2] in the interceptor
> > > chain where you can get the hold of soap message.
> > >
> > > With Regards,
> > > Mayank
> > >
> > > [1]. http://cwiki.apache.org/CXF20DOC/jax-ws-dispatch-api.html
> > > [2]. http://cwiki.apache.org/CXF20DOC/interceptors.html
--
John Baker, Java System Solutions.
http://www.javasystemsolutions.com
+44 7736 393822
Re: WS client, original message
Posted by Daniel Kulp <dk...@apache.org>.
I don't think it's QUITE as simple with JAX-WS. The code would look similar
to:
Service service = Service.create(serviceName);
service.addPort(portName, "http://schemas.xmlsoap.org/soap/",
"http://localhost:9006/SOAPDispatchService/SoapDispatchPort");
(serviceName and portName could be fairly random QNames)
Dispatch<DOMSource> disp = service.createDispatch(portName,
DOMSource.class, Service.Mode.PAYLOAD);
(You can use DOMSource, StreamSource, SAXSource)
DOMSource domResMsg = disp.invoke(domReqMsg);
Dan
On Sun June 21 2009 9:35:17 am John Baker wrote:
> Hi,
>
> Thanks for your response. I've written an interceptor to do it, but was
> just looking at the Dispatch API. I've got some old Axis code that I'm
> replacing - it does this:
>
> Service service = new Service();
> Call call = (Call)service.createCall();
> call.setTargetEndpointAddress(new URL(endPoint));
> call.setOperationName(new QName("http://www.xyz.com", method) );
> if (username != null) call.setUsername(username);
> if (password != null) call.setPassword(password);
> String ret = (String)call.invoke(new Object[] { message });
>
> Is that easy to replace with the jaxws (dispatch?) api? It did nothing
> more than call a WS method, passing one parameter and assuming a String
> response. No WSDL involved...
>
>
> John
>
> P.S. If anyone needs the interceptor then I'm happy to post it.
>
> On Sunday 21 June 2009 13:19:37 you wrote:
> > John Baker wrote:
> > > Hello,
> > >
> > > How does one obtain the raw SOAP message returned from a client
> > > webservice call? Ideally, as String or a Document would be nice.
> > >
> > >
> > > John
> >
> > You can achieve the same in either of two ways:
> >
> > A. You can use Dispatch API [1] to write your client where you can get
> > either Message (Body element) or Payload (entire SOAP Envelope).
> > or
> > B. You can write and plugin your own interceptor [2] in the interceptor
> > chain where you can get the hold of soap message.
> >
> > With Regards,
> > Mayank
> >
> > [1]. http://cwiki.apache.org/CXF20DOC/jax-ws-dispatch-api.html
> > [2]. http://cwiki.apache.org/CXF20DOC/interceptors.html
--
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog
Re: WS client, original message
Posted by John Baker <jb...@javasystemsolutions.com>.
So, I've found a thread where someone is doing the same:
http://www.nabble.com/Client-from-ClientFactoryBean-as-a-generic-soap-client--td17700799.html
However, when I try the same it seems to fail because of no service class in
the endpoint:
NullPointerException:
at
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.checkServiceClassAnnotations(ReflectionServiceFactoryBean.java:2156)
at
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.setServiceClass(ReflectionServiceFactoryBean.java:2153)
at
org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.initializeServiceFactory(AbstractWSDLBasedEndpointFactory.java:227)
at
org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:99)
at
org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:52)
My code is trying to invoke a method (by name method), with one String
argument (message), and it allows for a String to be returned. Note, I don't
have the WSDL, I am assuming the method exists as described!
ClientFactoryBean cfb = new ClientFactoryBean();
cfb.setAddress(endPoint);
if (username != null)
{
AuthorizationPolicy authPolicy = new AuthorizationPolicy();
authPolicy.setUserName(username);
authPolicy.setPassword(password);
Map<String,Object> props = new HashMap<String,Object>();
props.put(AuthorizationPolicy.class.getName(), authPolicy);
cfb.setProperties(props);
}
Client client = cfb.create();
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
String ret = null;
logger.debug("Invoking call ... ");
Object[] v = client.invoke(new QName(method), new Object[] {
message } );
if (v != null && v.length>0)
ret = v[0].toString();
Thoughts most welcome!
Re: WS client, original message
Posted by John Baker <jb...@javasystemsolutions.com>.
Hi,
Thanks for your response. I've written an interceptor to do it, but was just
looking at the Dispatch API. I've got some old Axis code that I'm
replacing - it does this:
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new URL(endPoint));
call.setOperationName(new QName("http://www.xyz.com", method) );
if (username != null) call.setUsername(username);
if (password != null) call.setPassword(password);
String ret = (String)call.invoke(new Object[] { message });
Is that easy to replace with the jaxws (dispatch?) api? It did nothing more
than call a WS method, passing one parameter and assuming a String response.
No WSDL involved...
John
P.S. If anyone needs the interceptor then I'm happy to post it.
On Sunday 21 June 2009 13:19:37 you wrote:
> John Baker wrote:
> > Hello,
> >
> > How does one obtain the raw SOAP message returned from a client
> > webservice call? Ideally, as String or a Document would be nice.
> >
> >
> > John
>
> You can achieve the same in either of two ways:
>
> A. You can use Dispatch API [1] to write your client where you can get
> either Message (Body element) or Payload (entire SOAP Envelope).
> or
> B. You can write and plugin your own interceptor [2] in the interceptor
> chain where you can get the hold of soap message.
>
> With Regards,
> Mayank
>
> [1]. http://cwiki.apache.org/CXF20DOC/jax-ws-dispatch-api.html
> [2]. http://cwiki.apache.org/CXF20DOC/interceptors.html
Re: WS client, original message
Posted by Mayank Mishra <ma...@gmail.com>.
John Baker wrote:
> Hello,
>
> How does one obtain the raw SOAP message returned from a client webservice
> call? Ideally, as String or a Document would be nice.
>
>
> John
>
>
You can achieve the same in either of two ways:
A. You can use Dispatch API [1] to write your client where you can get
either Message (Body element) or Payload (entire SOAP Envelope).
or
B. You can write and plugin your own interceptor [2] in the interceptor
chain where you can get the hold of soap message.
With Regards,
Mayank
[1]. http://cwiki.apache.org/CXF20DOC/jax-ws-dispatch-api.html
[2]. http://cwiki.apache.org/CXF20DOC/interceptors.html