I am trying to invoke a SOAP method from Axis 1.4 client generated by Eclipse as follows :
FNCEWS40ServiceLocator locator = new FNCEWS40ServiceLocator();
ObjectReference sourceSpecification = new ObjectReference();
sourceSpecification.setClassId("Document");
sourceSpecification.setObjectStore("OS");
sourceSpecification.setSerializationDuplicate(false);
sourceSpecification.setObjectId("{93040C0F-285E-4613-BC8E-BBB39136D7EE}");
ElementSpecificationType elementSpecificationType = new ElementSpecificationType();
elementSpecificationType.setElementSequenceNumber(0);
elementSpecificationType.setItemIndex(0);
ContentRequestType contentRequestType = new ContentRequestType();
contentRequestType.setElementSpecification(elementSpecificationType);
contentRequestType.setSourceSpecification(sourceSpecification);
ContentRequestType[] array = { contentRequestType };
ContentResponseType[] response = locator.getFNCEWS40MTOMPort().getContent(array);
getContent method implementation :
public com.filenet.www.ns.fnce._2006._11.ws.schema.ContentResponseType[] getContent(
com.filenet.www.ns.fnce._2006._11.ws.schema.ContentRequestType[] request)
throws java.rmi.RemoteException, com.filenet.www.ns.fnce._2006._11.ws.schema.FaultStackType {
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
org.apache.axis.client.Call _call = createCall();
_call.setOperation(_operations[4]);
_call.setUseSOAPAction(true);
_call.setSOAPActionURI("http://www.filenet.com/ns/fnce/2006/11/ws/MTOM#GetContent");
_call.setEncodingStyle(null);
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
_call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
_call.setProperty(org.apache.axis.AxisEngine.PROP_XML_DECL, Boolean.FALSE);
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
_call.setOperationName(new javax.xml.namespace.QName("", "GetContent"));
setRequestHeaders(_call);
setAttachments(_call);
try {
java.lang.Object _resp = _call.invoke(new java.lang.Object[] { request });
if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException) _resp;
} else {
extractAttachments(_call);
try {
return (com.filenet.www.ns.fnce._2006._11.ws.schema.ContentResponseType[]) _resp;
} catch (java.lang.Exception _exception) {
return (com.filenet.www.ns.fnce._2006._11.ws.schema.ContentResponseType[]) org.apache.axis.utils.JavaUtils
.convert(_resp, com.filenet.www.ns.fnce._2006._11.ws.schema.ContentResponseType[].class);
}
}
} catch (org.apache.axis.AxisFault axisFaultException) {
MessageContext messageContext = _call.getMessageContext();
String requestXML = messageContext.getRequestMessage() != null
? messageContext.getRequestMessage().getSOAPPartAsString()
: null;
String responseXML = messageContext.getResponseMessage() != null
? messageContext.getResponseMessage().getSOAPPartAsString()
: null;
System.out.println("########## requestXML: " + requestXML);
System.out.println("########## responseXML: " + responseXML);
if (axisFaultException.detail != null) {
if (axisFaultException.detail instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException) axisFaultException.detail;
}
if (axisFaultException.detail instanceof com.filenet.www.ns.fnce._2006._11.ws.schema.FaultStackType) {
throw (com.filenet.www.ns.fnce._2006._11.ws.schema.FaultStackType) axisFaultException.detail;
}
}
throw axisFaultException;
}
}
GetContent Operation definition :
oper = new org.apache.axis.description.OperationDesc();
oper.setName("GetContent");
param = new org.apache.axis.description.ParameterDesc(
new javax.xml.namespace.QName("http://www.filenet.com/ns/fnce/2006/11/ws/schema", "GetContentRequest"),
org.apache.axis.description.ParameterDesc.IN,
new javax.xml.namespace.QName("http://www.filenet.com/ns/fnce/2006/11/ws/schema", "GetContentRequest"),
com.filenet.www.ns.fnce._2006._11.ws.schema.ContentRequestType[].class, false, false);
param.setItemQName(
new javax.xml.namespace.QName("http://www.filenet.com/ns/fnce/2006/11/ws/schema", "ContentRequest"));
oper.addParameter(param);
oper.setReturnType(new javax.xml.namespace.QName("http://www.filenet.com/ns/fnce/2006/11/ws/schema",
"GetContentResponse"));
oper.setReturnClass(com.filenet.www.ns.fnce._2006._11.ws.schema.ContentResponseType[].class);
oper.setReturnQName(new javax.xml.namespace.QName("http://www.filenet.com/ns/fnce/2006/11/ws/schema",
"GetContentResponse"));
param = oper.getReturnParamDesc();
param.setItemQName(
new javax.xml.namespace.QName("http://www.filenet.com/ns/fnce/2006/11/ws/schema", "ContentResponse"));
oper.setStyle(org.apache.axis.constants.Style.DOCUMENT);
oper.setUse(org.apache.axis.constants.Use.LITERAL);
oper.addFault(new org.apache.axis.description.FaultDesc(
new javax.xml.namespace.QName("http://www.filenet.com/ns/fnce/2006/11/ws/schema", "ErrorStack"),
"com.filenet.www.ns.fnce._2006._11.ws.schema.FaultStackType",
new javax.xml.namespace.QName("http://www.filenet.com/ns/fnce/2006/11/ws/schema", "FaultStackType"),
true));
_operations[4] = oper;
when invoking the client I get the following exception :
Jan 31, 2023 3:08:33 PM org.apache.axis.client.Call invoke
SEVERE: Exception:
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.filenet.www.ns.fnce._2006._11.ws.MTOM.wsdl.FNCEWS40MTOMBindingStub.getContent(FNCEWS40MTOMBindingStub.java:1268)
at com.filenet.www.ns.fnce._2006._11.ws.MTOM.wsdl.Test.main(Test.java:24)
Exception in thread "main" AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.filenet.www.ns.fnce._2006._11.ws.MTOM.wsdl.FNCEWS40MTOMBindingStub.getContent(FNCEWS40MTOMBindingStub.java:1268)
at com.filenet.www.ns.fnce._2006._11.ws.MTOM.wsdl.Test.main(Test.java:24)
{http://xml.apache.org/axis/}hostname:MY_PC_NAME_HERE
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.client.Call.invoke(Call.java:2470)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.filenet.www.ns.fnce._2006._11.ws.MTOM.wsdl.FNCEWS40MTOMBindingStub.getContent(FNCEWS40MTOMBindingStub.java:1268)
at com.filenet.www.ns.fnce._2006._11.ws.MTOM.wsdl.Test.main(Test.java:24)
Caused by: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
... 4 more
I can see in the logs that the request is sent successfully and received success response
requestXML: <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Header><Security soapenv:mustUnderstand="1" xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext"><UsernameToken><Username>myuser</Username><Password>mypassword</Password></UsernameToken></Security></soapenv:Header><soapenv:Body><GetContentRequest xmlns="http://www.filenet.com/ns/fnce/2006/11/ws/schema"><ContentRequest cacheAllowed="false" maxBytes="0"><SourceSpecification classId="Document" objectId="{93040C0F-285E-4613-BC8E-BBB39136D7EE}" objectStore="os" serializationDuplicate="false"/><ElementSpecification elementSequenceNumber="0" itemIndex="0"/></ContentRequest></GetContentRequest></soapenv:Body></soapenv:Envelope>
responseXML: <?xml version="1.0" encoding="UTF-8"?><e:Envelope xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:fn35="http://www.filenet.com/ns/fnce/2005/02/ws/schema" xmlns:fn40m="http://www.filenet.com/ns/fnce/2006/11/ws/MTOM/schema" xmlns:fn40="http://www.filenet.com/ns/fnce/2006/11/ws/schema" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:e="http://schemas.xmlsoap.org/soap/envelope/"><e:Body><GetContentResponse xmlns="http://www.filenet.com/ns/fnce/2006/11/ws/schema"><ContentResponse i:type="fn40:ContentElementResponse" retrievalName="contract.pdf" totalSize="1453230" bufferedSize="1048576" continueFrom="offset=1048576;id={F3FAE2B3-2781-406F-A40F-D7386DE2C5AC};"><SourceSpecification i:type="fn40:ObjectReference" classId="Document" objectId="{93040C0F-285E-4613-BC8E-BBB39136D7EE}" objectStore="MCIDEV"/><ElementSpecification elementSequenceNumber="0"/><Content i:type="fn40:InlineContent"><Binary><xop:Include href="cid:v1-4f309df492ff50f-18607ba7645#mtom.p8ce.filenet.com"/></Binary></Content></ContentResponse></GetContentResponse></e:Body></e:Envelope>
I was able to get request and response in the catch exception as follows :
MessageContext messageContext = _call.getMessageContext();
String requestXML = messageContext.getRequestMessage() != null
? messageContext.getRequestMessage().getSOAPPartAsString()
: null;
String responseXML = messageContext.getResponseMessage() != null
? messageContext.getResponseMessage().getSOAPPartAsString()
: null;
When I copy the request XML and try it in SOAPUI it works fine with no issues.
Related
I am trying to read data from an API-endpoint using Ktor and getting an IllegalStateException often regarding supposedly null connection. Here´s how the exception looks like:
2021-04-06 11:14:48.407 [Ktor-client-apache] DEBUG o.a.h.i.n.client.InternalIODispatch - http-outgoing-4 [CLOSED] Exception
java.lang.IllegalStateException: Inconsistent state: managed connection is null
at org.apache.http.util.Asserts.check(Asserts.java:34)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.manageConnectionPersistence(AbstractClientExchangeHandler.java:285)
at org.apache.http.impl.nio.client.MainClientExec.responseCompleted(MainClientExec.java:352)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:172)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:448)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:338)
at org.apache.http.impl.nio.client.InternalRequestExecutor.inputReady(InternalRequestExecutor.java:83)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)
at java.lang.Thread.run(Thread.java:748)
Below is my code which causes the exception. I am creating a client on every request to be safe and closing it at the end in addition to checking of it´s active:
suspend fun getData(date: String): MyData? {
val client = HttpClient {
defaultRequest {
contentType(ContentType.Application.Json)
}
install(JsonFeature)
}
var myData: MyData? = null
if (client.isActive) {
try {
val response = client.get<JsonArray> {
url(url)
headers.append("keep-alive", true.toString())
}
val mapper = jacksonObjectMapper()
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
if (response.size() > 0) {
myData =
mapper.readValue(response.get(0).toString(), MyData::class.java)
}
} catch (e: IllegalStateException) {
log.info(e.message)
}
client.close()
}
return myData
}
I need help figuring out the fix for this exception since I wasn´t able to find much documentation about it. Thanks in advance.
I have a web service client which has been used several months, but last days we are getting an error when we execute the invocation to the method.
The error we get is :
[22 mar 2018 09:17:38,828] ERROR com.nisa.sms.EnviarSMS - (EnviarSMS.java:51) - Error al enviar el sms: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
the method is called with axis and this is the code :
public void enviarMensaje(int hospital, java.lang.String telefono, java.lang.String mensaje, javax.xml.rpc.holders.StringHolder respuesta, javax.xml.rpc.holders.StringHolder error) throws java.rmi.RemoteException {
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
org.apache.axis.client.Call _call = createCall();
_call.setOperation(_operations[1]);
_call.setUseSOAPAction(true);
_call.setSOAPActionURI("");
_call.setEncodingStyle(null);
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
_call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
_call.setOperationName(new javax.xml.namespace.QName("http://webservices.nisa.com/", "enviarMensaje"));
setRequestHeaders(_call);
setAttachments(_call);
try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {new java.lang.Integer(hospital), telefono, mensaje});
if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException)_resp;
}
else {
extractAttachments(_call);
java.util.Map _output;
_output = _call.getOutputParams();
try {
respuesta.value = (java.lang.String) _output.get(new javax.xml.namespace.QName("", "respuesta"));
} catch (java.lang.Exception _exception) {
respuesta.value = (java.lang.String) org.apache.axis.utils.JavaUtils.convert(_output.get(new javax.xml.namespace.QName("", "respuesta")), java.lang.String.class);
}
try {
error.value = (java.lang.String) _output.get(new javax.xml.namespace.QName("", "error"));
} catch (java.lang.Exception _exception) {
error.value = (java.lang.String) org.apache.axis.utils.JavaUtils.convert(_output.get(new javax.xml.namespace.QName("", "error")), java.lang.String.class);
}
}
} catch (org.apache.axis.AxisFault axisFaultException) {
throw axisFaultException;
}
}
this method is included in a Java application and we don't have certification problem in it. The certificate is validated and the problem comes in the line:
java.lang.Object _resp = _call.invoke(new java.lang.Object[] {new java.lang.Integer(hospital), telefono, mensaje});
we have the code of the web service too, the application who contains it is right certificated too.
Anyway I was reviewing the certificates and they are not timed out.
Any idea?
Thank you.
I would like to know how would I remove the error in the following code.
My code for client is:
public class TestClient {
public static void main(String [] args) {
try {
String endpoint = "http://localhost:8080//services/HelloWorld";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName("http://example", "sayHelloWorldFrom"));
call.addParameter("from", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
String ret = (String) call.invoke( new Object[] {"aaa"} );
System.out.println("Sent 'Hello!', got '" + ret + "'");
} catch (Exception e) {
e.printStackTrace();
}
}
}
The exception I receive when i run the code is:
log4j:WARN No appenders could be found for logger
(org.apache.axis.i18n.ProjectResourceBundle). log4j:WARN Please
initialize the log4j system properly. AxisFault faultCode:
{http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode: faultString: org.xml.sax.SAXException:
SimpleDeserializer encountered a child element, which is NOT expected,
in something it was trying to deserialize. faultActor: faultNode:
faultDetail: {http://xml.apache.org/axis/}hostname:MAQ
org.xml.sax.SAXException: SimpleDeserializer encountered a child
element, which is NOT expected, in something it was trying to
deserialize. at
org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at
org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at
org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1783)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2970)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:118)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
at
org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696) at
org.apache.axis.Message.getSOAPEnvelope(Message.java:435) at
org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
at
org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at
org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at
org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at
org.apache.axis.client.AxisClient.invoke(AxisClient.java:165) at
org.apache.axis.client.Call.invokeEngine(Call.java:2784) at
org.apache.axis.client.Call.invoke(Call.java:2767) at
org.apache.axis.client.Call.invoke(Call.java:2443) at
org.apache.axis.client.Call.invoke(Call.java:2366) at
org.apache.axis.client.Call.invoke(Call.java:1812) at
example.TestClient.main(TestClient.java:24)
When I try to send an Object[] { } without any parameters I do not get any error.
Here is the code for my webservice:
#WebService
public class HelloWorld {
#WebMethod
public String sayHelloWorldFrom(String from) {
String result = "Hello, world, from " + from;
System.out.println(result);
return result;
}
}
Who can help me, I was going to collapse, so thank you
The client to invoke an error is as follows,error:
The client to invoke an error is as follows,error:
- Exception:
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.hxc.soap.HxcNewsServiceSoap12BindingStub.find(HxcNewsServiceSoap12BindingStub.java:254)
at com.hxc.soap.Test.main(Test.java:11)
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.hxc.soap.HxcNewsServiceSoap12BindingStub.find(HxcNewsServiceSoap12BindingStub.java:254)
at com.hxc.soap.Test.main(Test.java:11)
{http://xml.apache.org/axis/}hostname:geduo_pc
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.client.Call.invoke(Call.java:2470)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.hxc.soap.HxcNewsServiceSoap12BindingStub.find(HxcNewsServiceSoap12BindingStub.java:254)
at com.hxc.soap.Test.main(Test.java:11)
Caused by: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
... 4 more
server code:(axis2+hibernate+spring)
public class HxcNewsService implements IHxcNewsService {
private IDao dao;
public void setDao(IDao dao) {
this.dao = dao;
}
public HxcNews find(int id){
return (HxcNews) dao.find("com.ews.bean.HxcNews",id);
}
}
public class Dao<T> extends HibernateDaoSupport implements IDao<T> {
public T find(String str,int id) {
try {
T t = (T) getHibernateTemplate().get(str, id);
return t;
} catch (RuntimeException re) {
throw re;
}
}
}
client code:
public class Test {
public static void main(String[] args) {
try {
HxcNewsServicePortType hxcNewsServicePortType = new HxcNewsServiceLocator().getHxcNewsServiceHttpSoap12Endpoint();
HxcNews news = hxcNewsServicePortType.find(1);
System.out.println(news.getTitle());
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I think the error is due to the xml output being returned from find() method of your HcxNewsService class. Some XML IS successfully returned, and it is not sufficiently well formed for it to deserialize (re construct an object out of it).
As mentioned in the stack trace...
"encountered a child element, which is NOT expected, in something it was trying to deserialize" (SAXParser did not understand the XML implies that xml is not correctly formed).
Possible debugging options are try to get the xml tied object directly from DAO... Log it...
public class Dao<T> extends HibernateDaoSupport implements IDao<T> {
public T find(String str,int id) {
try {
T t = (T) getHibernateTemplate().get(str, id);
System.out.println.t.toString()); // OR...
LOGGER.info(t.toString());
return t;
} cach (RuntimeException re) {
throw re;
}
}
}
If this fails, do the same approach with calling code in the server...
public class HxcNewsService implements IHxcNewsService {
private IDao dao;
public void setDao(IDao dao) {
this.dao = dao;
}
public HxcNews find(int id){
// before returning, see what is database returning...
LOGGER.log(dao.find("com.ews.bean.HxcNews",id));
return (HxcNews) dao.find("com.ews.bean.HxcNews",id);
}
}
Let us know how you solved it finally.
I'm in the process of creating a client for a web service. I keep getting the following error:
AxisFault
faultCode: {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}InvalidSecurity
faultSubcode:
faultString:
Security Data : General security error (WSSecurityEngine: Callback supplied no password for: TestMerchant)
faultActor:
faultNode:
faultDetail: {http://xml.apache.org/axis/}
stackTrace:
Security Data : General security error (WSSecurityEngine: Callback supplied no password for: TestMerchant)
This is my environment here:
Intellij IDEA IDE
Apache Axis
Apache WSS4J 1.5.1
Apache XML Security 1.4.0
JDK 1.6
Max OS X
Although searching on the internet provides a lot of examples of how the security header can be added to the request via XML configuration, my requirement is to do this dynamically via the program. So here is my code:
public class AxisClient implements CallbackHandler {
ServerEnvironment environment;
AxisClient(ServerEnvironment environment) {
this.environment = environment;
}
public enum ServerEnvironment {
LIVE("https://ics2ws.ic3.com/commerce/1.x/transactionProcessor"),
TEST("https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor");
String url;
ServerEnvironment (String url) {
this.url = url;
}
public String getUrl() {
return url;
}
}
public enum Merchant {
TestMerchant ("testpassword");
private String transactionKey;
Merchant(String transactionKey) {
this.transactionKey = transactionKey;
}
public String getTransactionKey() {
return transactionKey;
}
}
public static void main(String[] argv) {
String ani = "7162502800";
String zipCode = "14221";
String ccNum ="5555555555554444";
String expMonth = "01";
String expYear = "15";
String cvv = "123";
String unitPrice = "9.99";
String qty = "2";
try {
new AxisClient(ServerEnvironment.TEST).doAuth(Merchant.TestMerchant, ani, zipCode, ccNum, expMonth, expYear, cvv, String.valueOf(new Date().getTime()), unitPrice, qty);
}
catch (Exception e) {
e.printStackTrace();
}
}
public Boolean doAuth(Merchant merchant, String ani, String zipCode, String ccNum, String expMonth, String expYear, String cvv, String id, String unitPrice, String qty) throws Exception {
Boolean result = false;
RequestMessage request;
BillTo billTo;
Card card;
PurchaseTotals purchaseTotals;
Item item;
Item[] items;
ReplyMessage reply;
try {
// billing info
billTo = new BillTo();
billTo.setPhoneNumber(ani);
billTo.setPostalCode(zipCode);
// card info
card = new Card();
card.setAccountNumber(ccNum);
card.setExpirationMonth(new BigInteger(expMonth));
card.setExpirationYear(new BigInteger(expYear));
card.setCvNumber(cvv);
// currency info
purchaseTotals = new PurchaseTotals();
purchaseTotals.setCurrency("USD");
// item
item = new Item();
item.setId(new BigInteger(id));
item.setUnitPrice(unitPrice);
item.setQuantity(new BigInteger(qty));
// add item to items array
items = new Item[1];
items[0] = item;
// create our request
request = new RequestMessage();
request.setMerchantID(merchant.toString());
request.setCcAuthService(new CCAuthService());
request.getCcAuthService().setRun("true");
// add request specific params
request.setBillTo(billTo);
request.setCard(card);
request.setPurchaseTotals(purchaseTotals);
request.setItem(items);
reply = post(merchant, request);
if (reply != null) {
System.out.println(ReflectionToStringBuilder.toString(reply, ToStringStyle.MULTI_LINE_STYLE));
}
}
catch (Exception e) {
throw e;
}
return result;
}
public EngineConfiguration createConfigurationWithSecurityHeaders(Merchant merchant) throws Exception {
SimpleProvider result;
Handler securityHandler;
SimpleChain requestHandler;
SimpleChain responseHandler;
Handler pivot;
Handler transport;
try {
result = new SimpleProvider();
securityHandler = new WSDoAllSender();
securityHandler.setOption(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
securityHandler.setOption(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PASSWORD_TEXT);
securityHandler.setOption(WSHandlerConstants.PW_CALLBACK_REF, this);
securityHandler.setOption(WSHandlerConstants.USER, merchant.toString());
securityHandler.setOption(WSHandlerConstants.MUST_UNDERSTAND, "false");
requestHandler = new SimpleChain();
requestHandler.addHandler(securityHandler);
responseHandler = new SimpleChain();
responseHandler.addHandler(securityHandler);
pivot = new HTTPSender();
transport = new SimpleTargetedChain(requestHandler, pivot, responseHandler);
result.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME, transport);
}
catch (Exception e) {
throw e;
}
return result;
}
public ReplyMessage post (Merchant merchant, RequestMessage request) throws Exception {
ReplyMessage result;
TransactionProcessorLocator locator;
URL endPoint;
ITransactionProcessorStub stub;
EngineConfiguration configuration;
try {
locator = new TransactionProcessorLocator();
// use client config
configuration = createConfigurationWithSecurityHeaders(merchant);
locator.setEngineConfiguration(configuration);
locator.setEngine(new org.apache.axis.client.AxisClient(configuration));
endPoint = new URL(environment.getUrl());
stub = (ITransactionProcessorStub) locator.getportXML(endPoint);
stub._setProperty(WSHandlerConstants.USER, request.getMerchantID());
stub._setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
stub._setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PASSWORD_TEXT);
stub._setProperty(WSHandlerConstants.PW_CALLBACK_REF, this);
stub._setProperty(WSHandlerConstants.MUST_UNDERSTAND, "false");
result = stub.runTransaction(request);
}
catch (Exception e) {
throw e;
}
return result;
}
#Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
System.out.println(ReflectionToStringBuilder.toString(callback, ToStringStyle.MULTI_LINE_STYLE));
if (callback instanceof WSPasswordCallback) {
WSPasswordCallback passwordCallback = (WSPasswordCallback) callback;
switch (Merchant.valueOf(passwordCallback.getIdentifer())) {
case TestMerchant:
passwordCallback.setPassword(Merchant.TestMerchant.getTransactionKey());
System.out.println(ReflectionToStringBuilder.toString(passwordCallback, ToStringStyle.MULTI_LINE_STYLE));
break;
default:
throw new UnsupportedCallbackException(callback, "Unrecognized prompt!");
}
}
else {
throw new UnsupportedCallbackException(callback, "Unrecognized callback!");
}
}
}
}
As you can see from the above, my class implements CallbackHandler and I'm overriding handle() which provides the password for WSPasswordCallback.
Here is the output of the print statement for when I get the callback first:
org.apache.ws.security.WSPasswordCallback#50c713d2[
identifier=TestMerchant
password=<null>
key=<null>
usage=2
passwordType=<null>
]
Here is the output for after setting the password:
org.apache.ws.security.WSPasswordCallback#50c713d2[
identifier=TestMerchant
password=testpassword
key=<null>
usage=2
passwordType=<null>
]
So I'm not really sure why I keep getting that error message. Any help in solving this issue will be greatly appreciated.
Also recommendations for a different approach (axis2, cxf) are welcome.
Here is my full stack trace if it is of any help:
AxisFault
faultCode: {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}InvalidSecurity
faultSubcode:
faultString:
Security Data : General security error (WSSecurityEngine: Callback supplied no password for: TestMerchant)
General security error (WSSecurityEngine: Callback supplied no password for: TestMerchant)
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:
Security Data : General security error (WSSecurityEngine: Callback supplied no password for: TestMerchant)
General security error (WSSecurityEngine: Callback supplied no password for: TestMerchant)
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2939)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at itg.cybersource.axis.ITransactionProcessorStub.runTransaction(ITransactionProcessorStub.java:1284)
at itg.AxisClient.post(AxisClient.java:208)
at itg.AxisClient.doAuth(AxisClient.java:132)
at itg.AxisClient.main(AxisClient.java:75)
{http://xml.apache.org/axis/}hostname:C02GD302DRJL.local
Security Data : General security error (WSSecurityEngine: Callback supplied no password for: TestMerchant)
General security error (WSSecurityEngine: Callback supplied no password for: TestMerchant)
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2939)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at itg.cybersource.axis.ITransactionProcessorStub.runTransaction(ITransactionProcessorStub.java:1284)
at itg.AxisClient.post(AxisClient.java:208)
at itg.AxisClient.doAuth(AxisClient.java:132)
at itg.AxisClient.main(AxisClient.java:75)
After many days of trying very many different things, I finally figured out the answer to my problem. Talk about the problem being in between the keyboard and the chair!!!!!
So without further ado here is what the issue was:
securityHandler.setOption(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PASSWORD_TEXT);
Now WSConstants.PASSWORD_TEXT actually equates to "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText". What I must have really been using is WSConstants.PW_TEXT which equates to "PasswordText" which is exactly what I needed in my code. Once I made the change, everything works beautifully.
Contrary to popular belief, you can do all this entirely in a programmatic manner. You DO NOT need to configure the WSDD xml for you to intercept a message and handle WS-Security in the SOAP header. To tidy up loose ends, here is what the modified methods look like:
public EngineConfiguration createConfigurationWithSecurityHeaders(Merchant merchant) throws Exception {
SimpleProvider result;
Handler securityHandler;
SimpleChain requestHandler;
SimpleChain responseHandler;
Handler pivot;
Handler transport;
try {
result = new SimpleProvider();
securityHandler = new WSDoAllSender();
securityHandler.setOption(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
securityHandler.setOption(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
securityHandler.setOption(WSHandlerConstants.USER, merchant.toString());
securityHandler.setOption(WSHandlerConstants.MUST_UNDERSTAND, "false");
requestHandler = new SimpleChain();
requestHandler.addHandler(securityHandler);
responseHandler = new SimpleChain();
responseHandler.addHandler(securityHandler);
pivot = new HTTPSender();
transport = new SimpleTargetedChain(requestHandler, pivot, responseHandler);
result.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME, transport);
}
catch (Exception e) {
throw e;
}
return result;
}
public ReplyMessage post (Merchant merchant, RequestMessage request) throws Exception {
ReplyMessage result;
TransactionProcessorLocator locator;
URL endPoint;
ITransactionProcessorStub stub;
EngineConfiguration configuration;
try {
locator = new TransactionProcessorLocator();
// use client config
configuration = createConfigurationWithSecurityHeaders(merchant);
locator.setEngineConfiguration(configuration);
locator.setEngine(new org.apache.axis.client.AxisClient(configuration));
endPoint = new URL(environment.getUrl());
stub = (ITransactionProcessorStub) locator.getportXML(endPoint);
stub._setProperty(WSHandlerConstants.PW_CALLBACK_REF, this);
result = stub.runTransaction(request);
}
catch (Exception e) {
throw e;
}
return result;
}
Once these modifications are made, your client will work. Please keep in mind that a few of the settings above are specific to the service I'm integrating with. You might have to tweak these to suit your integration which might require a little trial and error.
Thanks again to all the people who post incredibly knowledgeable articles in SO enabling users like me solve problems we come across every now and then.