JAXM with TXQuery & TQuery with Tamino 4.1

I’m creating a SOAP service using JAXM request response method. Upon receiving a SOAP request, the receiving servlet invokes a query to Tamino 4.1 to retrieve a XML document and encapsulates into a SOAP response.

What’s interesting is that when using Tamino 4.1 Java API, receiving servlet using TQuery can successully query Tamino and return a SOAP response. However, when using TXQuery, I get the following exceptions from the client invoking the service:

javax.xml.soap.SOAPException: Invalid Content-Type:text/html
at com.sun.xml.messaging.saaj.soap.MessageImpl.verify(MessageImpl.java:159)
at com.sun.xml.messaging.saaj.soap.MessageImpl.(MessageImpl.java:91)
at com.sun.xml.messaging.saaj.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:32)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:333)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(HttpSOAPConnection.java:142)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:115)
at com.my.client.test.(test.java:46)
at com.my.client.test.main(test.java:109)
javax.xml.soap.SOAPException: Unable to internalize message
at com.sun.xml.messaging.saaj.soap.MessageImpl.(MessageImpl.java:135)
at com.sun.xml.messaging.saaj.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:32)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:333)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(HttpSOAPConnection.java:142)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:115)
at com.my.client.test.(test.java:46)
at com.my.client.test.main(test.java:109)
Caused by: javax.xml.soap.SOAPException: Invalid Content-Type:text/html
at com.sun.xml.messaging.saaj.soap.MessageImpl.verify(MessageImpl.java:159)
at com.sun.xml.messaging.saaj.soap.MessageImpl.(MessageImpl.java:91)


Code snippets below:
TConnection connection = TConnectionFactory.getInstance().newConnection( DATABASE_URI );
// Obtain a TXMLObjectAccessor with a DOM object model
TXMLObjectAccessor xmlObjectAccessor = connection.newXMLObjectAccessor(
TAccessLocation.newInstance( “General” ),
TDOMObjectModel.getInstance() );
// Prepare to read the instance
/* TQuery query = TQuery.newInstance( “TestXML[/sample=“test”]” );
try {
// Invoke the query operation
TResponse response = xmlObjectAccessor.query( query );
if ( response.hasFirstXMLObject() ) {
StringWriter stringWriter = new StringWriter();
response.getFirstXMLObject().writeTo( stringWriter );
System.out.println( “Retrieved following instance:” + stringWriter );
TXMLObject xmlObject = response.getFirstXMLObject();
doc = (Document) xmlObject.getDocument();
}
else doc= null;
}
catch (TQueryException queryException) {
// Inform about the reason for the failure
System.out.println( “Query failed!” );
if ( queryException.hasAccessFailureException() )
System.out.println( “Query rejected by Tamino. Reason:” +
queryException.getAccessFailureException() );
} */


TXQuery query = TXQuery.newInstance( “for $b in input()/TestXML where $b/sample=‘test’ return $b”);
try {
// Invoke the query operation
TResponse response = xmlObjectAccessor.xquery( query );
if ( response.hasFirstXMLObject() ) {
StringWriter stringWriter = new StringWriter();
response.getFirstXMLObject().writeTo( stringWriter );
System.out.println( “Retrieved following instance:” + stringWriter );
TXMLObject xmlObject = response.getFirstXMLObject();
doc = (Document) xmlObject.getDocument();
}
else doc= null;
}
catch (TXQueryException queryException) {
// Inform about the reason for the failure
System.out.println( “Query failed!” );
if ( queryException.hasAccessFailureException() )
System.out.println( “Query rejected by Tamino. Reason:” +
queryException.getAccessFailureException() );
}
// OK, everything is done, close the connection.


connection.close();

} catch (Exception e) {
System.out.println( “Error” + e.toString() );
};


I’ve similar experience when using X-Application 4.1 as well. Is this a bug or due to my incorrect use of the APIs? Any advise is greatly appreciated. Thanks!

Have you checked the result of the two queries. Is it the same for both queries?

Also I noticed the following line in both variations:
doc = (Document) xmlObject.getDocument();
This method delivers the whole Tamino response as one DOM tree. If you only want the DOM tree for the first result document, you should use:
Element ele = (Element) xmlObject.getElement();

Yes, the query result sets are the same, except X-Query added the ino:id attribute to the root element of the document.

I’ve tried commenting out the lines to retrieve doc and only invoke the TResponse response = xmlObjectAccessor.xquery( query );

The same errors still occur when invoked in a Jaxm servlet onMessage method but runs fine from a class. Are the response Mime Types of a XQuery and a X-Query different?

The only significant difference is in the Tamino response tags as queried via Tamino Interactive and shown below:

X-Query Response
<?xml version="1.0" encoding="windows-1252" ?>
- <ino:response xmlns:ino=“http://namespaces.softwareag.com/tamino/response2” xmlns:xql=“http://metalab.unc.edu/xql/”>
xql:queryTestXML[/sample=“test”]</xql:query>
- <ino:message ino:returnvalue=“0”>
ino:messagelinefetching cursor</ino:messageline>
</ino:message>
- xql:result
-


</xql:result>
- <ino:cursor ino:handle=“1”>
<ino:current ino:position=“1” ino:quantity=“4” />
</ino:cursor>
- <ino:message ino:returnvalue=“0”>
ino:messagelinecursor fetched</ino:messageline>
</ino:message>
</ino:response>

XQuery Response
<?xml version="1.0" encoding="windows-1252" ?>
- <ino:response xmlns:ino=“http://namespaces.softwareag.com/tamino/response2” xmlns:xql=“http://metalab.unc.edu/xql/”>
- <xq:query xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>
-
</xq:query>
- <ino:message ino:returnvalue=“0”>
ino:messagelinefetching cursor</ino:messageline>
</ino:message>
- <xq:result xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>
-



</xq:result>
- <ino:cursor ino:handle=“1”>
<ino:current ino:position=“1” ino:quantity=“4” />
</ino:cursor>
- <ino:message ino:returnvalue=“0”>
ino:messagelinecursor fetched</ino:messageline>
</ino:message>
</ino:response>

A few things are not that clear to us:
- the shown exception trace does not look like an API exception
- we can not correlate the shown exception trace with your application code

Could you provide us with as much as possible, like:
- in case a TException is thrown. Give us the content of TException.toXMLString()
- some sort of HttpSniffer protocol showing the traffic between the App and Tamino
- may be your application or at least a small executable example showing the failure

Stefan

Thanks for the attention! I’ve resolved this.