You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Dev <de...@gmail.com> on 2011/07/21 22:19:11 UTC

Question regarding SOAPBody and precreated XML payload

Hi -

My problem definition is as follows: -

I need to create a WS client connecting an WS endpoint using HTTPS and
recover the ServiceName and PortName from WSDL. Once I retrieve the
ServiceName and PortName, I need to send a SOAP message. Here is where I
have run into problem. I already have a pre-created XML which will go into
the SOAP body, but I am unable to determine how to add that to the SOAPBody.

So far my code looks like this I have commented the section where I want to
insert the xml: -

                 ServiceInfo serviceInfo = getServices(wsdlUrl).get(0);
		QName serviceName = serviceInfo.getName();		
		QName portName = serviceInfo.getBindings().iterator().next().getName();

		System.out.println(serviceName.getLocalPart() + " "
				+ portName.getLocalPart());

		Service service = Service.create(serviceName);
		service.addPort(portName, SOAPBinding.SOAP12HTTP_BINDING,
"https://someaddr");

		/** Create a Dispatch instance from a service. **/
		Dispatch<SOAPMessage> dispatch = service.createDispatch(portName,
				SOAPMessage.class, Service.Mode.MESSAGE);

		/** Create SOAPMessage request. **/
		// compose a request message
		MessageFactory mf = MessageFactory
				.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);

		// Create a message. This example works with the SOAPPART.
		SOAPMessage request = mf.createMessage();
		SOAPPart part = request.getSOAPPart();

		// Obtain the SOAPEnvelope and header and body elements.
		SOAPEnvelope env = part.getEnvelope();
		SOAPHeader header = env.getHeader();
		SOAPBody body = env.getBody();
		
		// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

		//QUESTIOn - HOW DO I ADD PRECREATED XML INSIDE SOAPBody??

		// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

		
		request.saveChanges();
		
		/** Invoke the service endpoint. **/
		SOAPMessage response = dispatch.invoke(request);



Can anyone provide some insight?

Best Regards-
Dev

--
View this message in context: http://cxf.547215.n5.nabble.com/Question-regarding-SOAPBody-and-precreated-XML-payload-tp4620842p4620842.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Re: Question regarding SOAPBody and precreated XML payload

Posted by Dev <de...@gmail.com>.
I managed to get over that problem. Next issue I have run into is signing the
message. Since we are using JDK1.5 and the keytool doesn't provide commands
to import private keys, I had to use OpenSSL and extract the private key
from .pfx file and convert the key into .DER extension and add it to the
keystore using JDK keytool. However the code now bombs with the following
complain: -

rg.apache.cxf.binding.soap.SoapFault: Security processing failed.
	at
org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:272)
	at
org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:134)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:546)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:295)
	at org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:330)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:332)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:218)
	at com.luminant.relay.app.xfs.ws.WSDispatcher.main(WSDispatcher.java:204)
Caused by: org.apache.ws.security.WSSecurityException: Error during
Signature: ; nested exception is: 
	org.apache.ws.security.WSSecurityException: General security error (No
certificates for user TESTUSER were found for signature)
	at
org.apache.ws.security.action.SignatureAction.execute(SignatureAction.java:68)
	at
org.apache.ws.security.handler.WSHandler.doSenderAction(WSHandler.java:206)

I believe this is occurring because private keys are not getting picked up
by the application. My WS client code has added the following code to enable
signing: -



		outProps.put(WSHandlerConstants.ACTION, "Signature");
		outProps.put(WSHandlerConstants.USER, "TESTUSER");
		outProps.put("signaturePropFile", "crypto.properties");
		outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, 
				ClientPasswordCallback.class.getName());

I am wondering if there is something I am missing out here. In my keystore I
have 'TESTUSER' as alias to the private key.

--
View this message in context: http://cxf.547215.n5.nabble.com/Question-regarding-SOAPBody-and-precreated-XML-payload-tp4620842p4632376.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Re: Question regarding SOAPBody and precreated XML payload

Posted by Daniel Kulp <dk...@apache.org>.
Is this something that you can possibly create a test case for?   That's a 
very strange test case.   The only thing I can think of is if CXF thinks it's 
in MESSAGE mode, but the data is coming in PAYLOAD.   Not really sure though.

Dan



On Friday, July 22, 2011 12:29:43 PM Dev wrote:
> Any idea what this error is and how can we overcome this error?
> 
> HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not
> permitted.
> 	at
> com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(Unknown
> Source)
> 	at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(Unknown
> Source)
> 	at
> com.sun.xml.messaging.saaj.soap.SOAPPartImpl.appendChild(SOAPPartImpl.java:5
> 02) at
> org.apache.cxf.staxutils.W3CDOMStreamWriter.setChild(W3CDOMStreamWriter.java
> :114) at
> org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.java
> :104) at
> org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamWr
> iter.java:132) at
> org.apache.cxf.staxutils.OverlayW3CDOMStreamWriter.writeStartElement(Overlay
> W3CDOMStreamWriter.java:131) at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelope
> Start(SoapOutInterceptor.java:122) at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(Soa
> pOutInterceptor.java:81) at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(Soa
> pOutInterceptor.java:61) at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain
> .java:255) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:546)
> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:295) at
> org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:330) at
> org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:332) at
> org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:218) at
> xxx.WSDispatcher.main(WSDispatcher.java:189)
> Exception in thread "main" javax.xml.ws.soap.SOAPFaultException:
> HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not
> permitted.
> 	at org.apache.cxf.jaxws.DispatchImpl.mapException(DispatchImpl.java:262)
> 	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:339)
> 	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:218)
> 	at xxx.WSDispatcher.main(WSDispatcher.java:189)
> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Question-regarding-SOAPBody-and-precreated-
> XML-payload-tp4620842p4624419.html Sent from the cxf-dev mailing list
> archive at Nabble.com.
-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com

Re: Question regarding SOAPBody and precreated XML payload

Posted by Dev <de...@gmail.com>.
Any idea what this error is and how can we overcome this error?

HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not
permitted. 
	at
com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(Unknown
Source)
	at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(Unknown
Source)
	at
com.sun.xml.messaging.saaj.soap.SOAPPartImpl.appendChild(SOAPPartImpl.java:502)
	at
org.apache.cxf.staxutils.W3CDOMStreamWriter.setChild(W3CDOMStreamWriter.java:114)
	at
org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.java:104)
	at
org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamWriter.java:132)
	at
org.apache.cxf.staxutils.OverlayW3CDOMStreamWriter.writeStartElement(OverlayW3CDOMStreamWriter.java:131)
	at
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:122)
	at
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:81)
	at
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:61)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:546)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:295)
	at org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:330)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:332)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:218)
	at xxx.WSDispatcher.main(WSDispatcher.java:189)
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException:
HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not
permitted. 
	at org.apache.cxf.jaxws.DispatchImpl.mapException(DispatchImpl.java:262)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:339)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:218)
	at xxx.WSDispatcher.main(WSDispatcher.java:189)

--
View this message in context: http://cxf.547215.n5.nabble.com/Question-regarding-SOAPBody-and-precreated-XML-payload-tp4620842p4624419.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Re: Question regarding SOAPBody and precreated XML payload

Posted by Dev <de...@gmail.com>.
Thanks a bunch Daniel your suggestion helped  , I do not get that error
however now I am getting the following error: -

aused by: java.io.IOException: The https URL hostname does not match the
Common Name (CN) on the server certificate.  To disable this check (NOT
recommended for production) set the CXF client TLS configuration property
"disableCNCheck" to true.

I am using the following code: -

		/*
		 * Provide handle to key store for SSL hand shake.
		 */
		System.setProperty("javax.net.ssl.keyStore", "truststore.jks");
		System.setProperty("javax.net.ssl.keyStorePassword", "xxx");
		System.setProperty("javax.net.ssl.trustStore", "truststore.jks");
		System.setProperty("javax.net.ssl.trustStorePassword", "xxx");
		
		
		HostnameVerifier hv = new HostnameVerifier() {
			public boolean verify(String urlHostName, SSLSession session) {
				System.out.println("Warning: URL Host: " + urlHostName
						+ " vs. " + session.getPeerHost());
				return true;
			}
		};
		HttpsURLConnection.setDefaultHostnameVerifier(hv);


This is allowing me to access WSDL from the server and get the service name
and port name using the following API, without the above piece of code I was
getting IOException regarding URL mismatch between certificate all the time:
-

WSDLServiceFactory sf = new WSDLServiceFactory(CXFBusFactory
				.getThreadDefaultBus(), url);

		Definition definition = sf.getDefinition();

		List<ServiceInfo> services;
		services = new com.luminant.relay.app.xfs.ws.WSDLServiceBuilder(
				CXFBusFactory.getThreadDefaultBus()).buildServices(definition);


However when i am actually sending the SOAP request to the server I am
running into the error as I mentioned earlier. The error message seems to
hint the workaround, but with the APIs I am using I don't know if it will
work. Any idea? 

--
View this message in context: http://cxf.547215.n5.nabble.com/Question-regarding-SOAPBody-and-precreated-XML-payload-tp4620842p4621006.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Re: Question regarding SOAPBody and precreated XML payload

Posted by Daniel Kulp <dk...@apache.org>.

On Thursday, July 21, 2011 1:35:25 PM Dev wrote:
> Never mind, I managed to get over it by Creating a XML Document object and
> adding it to SOAPBody. But now I getting following message on dispatch, and
> I am not sure what is that is not working: -
> 
> 1) Is the XML request invalid?
> 2) Is the end point connection refused?

No idea..  I see you are using the sun stax impl:

com.sun.xml.stream.writers.XMLStreamWriterImpl

I would suggest replacing that with woodstox and seeing if a different error 
pops up.

Dan


> 
> And what is that I need to do to get over this issue?
> 
> rg.apache.cxf.interceptor.Fault: Could not write to XMLStreamWriter.
> 	at
> org.apache.cxf.interceptor.StaxOutInterceptor$StaxOutEndingInterceptor.handl
> eMessage(StaxOutInterceptor.java:175) at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain
> .java:255) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:546)
> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:295) at
> org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:330) at
> org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:332) at
> org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:218) at
> xxx.app.xfs.ws.WSDispatcher.main(WSDispatcher.java:112)
> Caused by: javax.xml.stream.XMLStreamException
> 	at
> com.sun.xml.stream.writers.XMLStreamWriterImpl.close(XMLStreamWriterImpl.jav
> a:384) at
> org.apache.cxf.interceptor.StaxOutInterceptor$StaxOutEndingInterceptor.handl
> eMessage(StaxOutInterceptor.java:166) ... 8 more
> Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Could not
> write to XMLStreamWriter.
> 	at org.apache.cxf.jaxws.DispatchImpl.mapException(DispatchImpl.java:262)
> 	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:339)
> 	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:218)
> 	at  xxx.app.xfs.ws.WSDispatcher.main(WSDispatcher.java:112)
> Caused by: org.apache.cxf.interceptor.Fault: Could not write to
> XMLStreamWriter.
> 	at
> org.apache.cxf.interceptor.StaxOutInterceptor$StaxOutEndingInterceptor.handl
> eMessage(StaxOutInterceptor.java:175) at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain
> .java:255) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:546)
> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:295) at
> org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:330) at
> org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:332) ... 2 more
> Caused by: javax.xml.stream.XMLStreamException
> 	at
> com.sun.xml.stream.writers.XMLStreamWriterImpl.close(XMLStreamWriterImpl.jav
> a:384) at
> org.apache.cxf.interceptor.StaxOutInterceptor$StaxOutEndingInterceptor.handl
> eMessage(StaxOutInterceptor.java:166) ... 8 more
> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Question-regarding-SOAPBody-and-precreated-
> XML-payload-tp4620842p4620885.html Sent from the cxf-dev mailing list
> archive at Nabble.com.
-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com

Re: Question regarding SOAPBody and precreated XML payload

Posted by Dev <de...@gmail.com>.
Never mind, I managed to get over it by Creating a XML Document object and
adding it to SOAPBody. But now I getting following message on dispatch, and
I am not sure what is that is not working: -

1) Is the XML request invalid?
2) Is the end point connection refused?

And what is that I need to do to get over this issue?

rg.apache.cxf.interceptor.Fault: Could not write to XMLStreamWriter.
	at
org.apache.cxf.interceptor.StaxOutInterceptor$StaxOutEndingInterceptor.handleMessage(StaxOutInterceptor.java:175)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:546)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:295)
	at org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:330)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:332)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:218)
	at xxx.app.xfs.ws.WSDispatcher.main(WSDispatcher.java:112)
Caused by: javax.xml.stream.XMLStreamException
	at
com.sun.xml.stream.writers.XMLStreamWriterImpl.close(XMLStreamWriterImpl.java:384)
	at
org.apache.cxf.interceptor.StaxOutInterceptor$StaxOutEndingInterceptor.handleMessage(StaxOutInterceptor.java:166)
	... 8 more
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Could not
write to XMLStreamWriter.
	at org.apache.cxf.jaxws.DispatchImpl.mapException(DispatchImpl.java:262)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:339)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:218)
	at  xxx.app.xfs.ws.WSDispatcher.main(WSDispatcher.java:112)
Caused by: org.apache.cxf.interceptor.Fault: Could not write to
XMLStreamWriter.
	at
org.apache.cxf.interceptor.StaxOutInterceptor$StaxOutEndingInterceptor.handleMessage(StaxOutInterceptor.java:175)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:546)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:295)
	at org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:330)
	at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:332)
	... 2 more
Caused by: javax.xml.stream.XMLStreamException
	at
com.sun.xml.stream.writers.XMLStreamWriterImpl.close(XMLStreamWriterImpl.java:384)
	at
org.apache.cxf.interceptor.StaxOutInterceptor$StaxOutEndingInterceptor.handleMessage(StaxOutInterceptor.java:166)
	... 8 more

--
View this message in context: http://cxf.547215.n5.nabble.com/Question-regarding-SOAPBody-and-precreated-XML-payload-tp4620842p4620885.html
Sent from the cxf-dev mailing list archive at Nabble.com.