You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Frank Ertl <fr...@f-i-solutions-plus.de> on 2013/04/15 13:11:49 UTC

How to Use ProducerTemplate for testing secure CXF-WS?

Hi there,

currently I'm trying to test a route starting with an cxf-endpoint using a
ProducerTemplate.
I add the necessary securityheaders like this:

Document document = message.getSOAPPart();

WSSecHeader securityHeader = new WSSecHeader();
securityHeader.setMustUnderstand(false);
securityHeader.insertSecurityHeader(document);

WSSecUsernameToken usernameToken = new WSSecUsernameToken();
usernameToken.setPasswordType(WSConstants.PASSWORD_TEXT);
usernameToken.setUserInfo("myUser", "######");
usernameToken.addCreated();
usernameToken.addNonce();
usernameToken.build(document, securityHeader);

WSSecTimestamp timestamp = new WSSecTimestamp();
timestamp.build(document, securityHeader);
message.saveChanges();

Printing the resulting message is looks quite like the one send by SoapUI
(which works by the way). Unfortunately when I use this message to call my
endpoint via a ProducerTemplate it fails with the following stacktrace:

Code used to call my route:

Map<String, Object>headers = new Hashtable<String, Object>();
headers.put(CxfConstants.CAMEL_CXF_MESSAGE, message);
String response = producerTemplate.requestBodyAndHeaders(
"cxf:bean:sst_3_3", new Object[1], headers, String.class );

Stacktrace:

2013-04-15 12:57:32,232 [main] WARN 
org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory - Could not find
endpoint/port for {http://adapter.cardprocessing.osplus/SST_3_3}SST_3_3Port
in wsdl. Using {http://adapter.cardprocessing.osplus/SST_3_3}SST_3_3SOAP.
2013-04-15 12:57:32,451 [default-workqueue-1] WARN 
org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor - Request does not
contain Security header, but it's a fault.
Exception in thread "main" org.apache.camel.CamelExecutionException:
Exception occurred during execution on the exchange: Exchange[Message: [Body
is null]]
	at
org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1286)
	at
org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:618)
	at
org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:442)
	at
org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeaders(DefaultProducerTemplate.java:247)
	at
org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:296)
	at
org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:292)
	at
org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:329)
	at
osplus.cardprocessing.adapter.sst_3_3.SOAPTestCaller.sendSOAPCall(SOAPTestCaller.java:78)
	at
osplus.cardprocessing.adapter.sst_3_3.SOAPTestCaller.main(SOAPTestCaller.java:39)
Caused by: org.apache.cxf.binding.soap.SoapFault: An error was discovered
processing the <wsse:Security> header
	at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)
	at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46)
	at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
	at
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:112)
	at
org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
	at
org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
	at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:783)
	at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1694)
	at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1535)
	at
org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:426)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at
org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:351)
	at java.lang.Thread.run(Thread.java:662)

I assume I need to put the security information somewhere else but I don't
have a clue where...

Anybody an idea?




--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Use-ProducerTemplate-for-testing-secure-CXF-WS-tp5730894.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Use ProducerTemplate for testing secure CXF-WS?

Posted by sjfloat <sj...@gmail.com>.
Frank,

Did you have any luck with this? I'm attempting to do something similar.



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Use-ProducerTemplate-for-testing-secure-CXF-WS-tp5730894p5742107.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Use ProducerTemplate for testing secure CXF-WS?

Posted by Willem jiang <wi...@gmail.com>.
Hi  

I don't think you set the right payload message as soap body element is empty.
BTW, if the request doesn't hit the route, you need to check the log file to see if there anything wrong on the ProducerTemplate side.


--  
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 Tuesday, April 16, 2013 at 5:26 PM, Frank Ertl wrote:

> Hi Willem,
>  
> thanks for your response. I'm using PAYLOAD-mode in my cxf consumer. I
> already found the page you referred to and tried to set the headers of the
> CxfPayload-object like this:  
>  
> Processor soapHeaderProcessor = new Processor() {
>  
> public void process(Exchange exchange) throws Exception {
> List<SoapHeader> headers = new ArrayList<SoapHeader>();
> QName qName = new QName("sst");
> headers.add(new SoapHeader(qName, soapMessage));
> CxfPayload<SoapHeader> payload = new
> CxfPayload<SoapHeader>(headers, new ArrayList<Element>());
> exchange.getIn().setBody(payload);
> }
> };
>  
> But when I call /producerTemplate.request("cxf:bean:sst_3_3",
> soapHeaderProcessor);/ the request does not seem to hit the route and there
> is no exception thrown.  
> I admit I'm a little bit confused about this thing. Everything else in Camel
> seems so simple and straight forward, but this looks like I've got to write
> a lot of boilerplate code on my own. So I think I'm heading in the wrong
> direction.  
> By the way: Trying the same thing with HttpClient works quite well, although
> I'd like to stay on the camel's back... :-)
>  
> Regards,
> Frank
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-Use-ProducerTemplate-for-testing-secure-CXF-WS-tp5730894p5730959.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: How to Use ProducerTemplate for testing secure CXF-WS?

Posted by Frank Ertl <fr...@f-i-solutions-plus.de>.
Hi Willem,

thanks for your response. I'm using PAYLOAD-mode in my cxf consumer. I
already found the page you referred to and tried to set the headers of the
CxfPayload-object like this: 

Processor soapHeaderProcessor = new Processor() {

            public void process(Exchange exchange) throws Exception {
                List<SoapHeader> headers = new ArrayList<SoapHeader>();
                QName qName = new QName("sst");
                headers.add(new SoapHeader(qName, soapMessage));
                CxfPayload<SoapHeader> payload = new
CxfPayload<SoapHeader>(headers, new ArrayList<Element>());
                exchange.getIn().setBody(payload);
            }
        };

But when I call /producerTemplate.request("cxf:bean:sst_3_3",
soapHeaderProcessor);/ the request does not seem to hit the route and there
is no exception thrown. 
I admit I'm a little bit confused about this thing. Everything else in Camel
seems so simple and straight forward, but this looks like I've got to write
a lot of boilerplate code on my own. So I think I'm heading in the wrong
direction. 
By the way: Trying the same thing with HttpClient works quite well, although
I'd like to stay on the camel's back... :-)

Regards,
Frank



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Use-ProducerTemplate-for-testing-secure-CXF-WS-tp5730894p5730959.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Use ProducerTemplate for testing secure CXF-WS?

Posted by Willem jiang <wi...@gmail.com>.
Hi,  

If you want to send customer headers through the ProducerTemplate, please check this[1] out.

[1] http://camel.apache.org/cxf.html#CXF-HowtogetandsetSOAPheadersinPOJOmode  

--  
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 Monday, April 15, 2013 at 7:11 PM, Frank Ertl wrote:

> Hi there,
>  
> currently I'm trying to test a route starting with an cxf-endpoint using a
> ProducerTemplate.
> I add the necessary securityheaders like this:
>  
> Document document = message.getSOAPPart();
>  
> WSSecHeader securityHeader = new WSSecHeader();
> securityHeader.setMustUnderstand(false);
> securityHeader.insertSecurityHeader(document);
>  
> WSSecUsernameToken usernameToken = new WSSecUsernameToken();
> usernameToken.setPasswordType(WSConstants.PASSWORD_TEXT);
> usernameToken.setUserInfo("myUser", "######");
> usernameToken.addCreated();
> usernameToken.addNonce();
> usernameToken.build(document, securityHeader);
>  
> WSSecTimestamp timestamp = new WSSecTimestamp();
> timestamp.build(document, securityHeader);
> message.saveChanges();
>  
> Printing the resulting message is looks quite like the one send by SoapUI
> (which works by the way). Unfortunately when I use this message to call my
> endpoint via a ProducerTemplate it fails with the following stacktrace:
>  
> Code used to call my route:
>  
> Map<String, Object>headers = new Hashtable<String, Object>();
> headers.put(CxfConstants.CAMEL_CXF_MESSAGE, message);
> String response = producerTemplate.requestBodyAndHeaders(
> "cxf:bean:sst_3_3", new Object[1], headers, String.class );
>  
> Stacktrace:
>  
> 2013-04-15 12:57:32,232 [main] WARN  
> org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory - Could not find
> endpoint/port for {http://adapter.cardprocessing.osplus/SST_3_3}SST_3_3Port
> in wsdl. Using {http://adapter.cardprocessing.osplus/SST_3_3}SST_3_3SOAP.
> 2013-04-15 12:57:32,451 [default-workqueue-1] WARN  
> org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor - Request does not
> contain Security header, but it's a fault.
> Exception in thread "main" org.apache.camel.CamelExecutionException:
> Exception occurred during execution on the exchange: Exchange[Message: [Body
> is null]]
> at
> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1286)
> at
> org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:618)
> at
> org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:442)
> at
> org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeaders(DefaultProducerTemplate.java:247)
> at
> org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:296)
> at
> org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:292)
> at
> org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:329)
> at
> osplus.cardprocessing.adapter.sst_3_3.SOAPTestCaller.sendSOAPCall(SOAPTestCaller.java:78)
> at
> osplus.cardprocessing.adapter.sst_3_3.SOAPTestCaller.main(SOAPTestCaller.java:39)
> Caused by: org.apache.cxf.binding.soap.SoapFault: An error was discovered
> processing the <wsse:Security> header
> at
> org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)
> at
> org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46)
> at
> org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
> at
> org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:112)
> at
> org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
> at
> org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
> at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:783)
> at
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1694)
> at
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1535)
> at
> org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:426)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> at
> org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:351)
> at java.lang.Thread.run(Thread.java:662)
>  
> I assume I need to put the security information somewhere else but I don't
> have a clue where...
>  
> Anybody an idea?
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-Use-ProducerTemplate-for-testing-secure-CXF-WS-tp5730894.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).