[prev in list] [next in list] [prev in thread] [next in thread]
List: xmlbeans-dev
Subject: [jira] Created: (XMLBEANS-266) javax.xml.stream.XMLStreamException:
From: "Wesley King (JIRA)" <xmlbeans-dev () xml ! apache ! org>
Date: 2006-04-13 20:48:04
Message-ID: 31805578.1144961284266.JavaMail.jira () brutus
[Download RAW message or body]
javax.xml.stream.XMLStreamException: problem accessing the parser
-----------------------------------------------------------------
Key: XMLBEANS-266
URL: http://issues.apache.org/jira/browse/XMLBEANS-266
Project: XMLBeans
Type: Bug
Components: Binding
Versions: Version 2.1
Environment: Windows XP, Eclipse w/ MyEclipse plugin, Tomcat
Reporter: Wesley King
I have an soap message receiver class that extends AbstractInOutSyncMessageReceiver. \
I use this class to handle my web service requests. Inside the \
invokeBusinessLogic(MessageContext, MessageContext) method, I am attempting to parse \
the envelope header first and then the body. The header contains an element called \
MultiSpeakMsgHeader and the body contains an element called PingURL. All the XML \
objects were created using XMLBeans. The web service works fine if I only attempt to \
parse the body's first element creating the PingURLDocument. If I try to parse the \
header's first element creating the MultiSpeakMsgHeaderDocument, that works fine, but \
right afterwards if I try to parse the body's first element I get an exception: \
XMLStreamException: problem accessing parser.
Am I doing something wrong? If so, any help would be appreciated. If not, is this a \
known bug/issue? And is there a work around?
Include below are three files that may or may not be helpfull. (1) The \
AbstractInOutSyncMessageReceiver java file. (2) The skeleton java file that handles \
the service. And (3) the xml I'm sending to the server. As I mentioned above, \
everything works fine if I don't attempt to read the header. As a side note, the \
reason I need to read the header is to check for a valid user id and password. If \
there is another way to check/validate header information, I'm open to suggestions.
=====================================
=====================================
(3) XML Request being sent
---------------------------------------
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope" />
<soapenv:Header>
<MultiSpeakMsgHeader UserID="test" Pwd="test" \
xmlns="http://www.multispeak.org/Version_3.0" /> </soapenv:Header>
<soapenv:Body>
<PingURL xmlns="http://www.multispeak.org/Version_3.0" />
</soapenv:Body>
</soapenv:Envelope>
=====================================
=====================================
=====================================
=====================================
(2) Java class to handle request
--------------------------------------------
package com.daffron.multispeak;
import java.lang.reflect.Method;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.apache.xmlbeans.XmlObject;
import org.multispeak.version30.*;
public class MultispeakSoapSkeleton {
public PingURLResponseDocument PingURL(PingURLDocument requestDoc) {
PingURLResponseDocument pingURLRespDoc = null;
try {
pingURLRespDoc = (PingURLResponseDocument) \
getReturnObject(PingURLResponseDocument.class); }
catch (Exception e) {
System.out.println("Failed to create return object for PingURL request.");
}
if (pingURLRespDoc != null) {
pingURLRespDoc.addNewPingURLResponse();
}
return pingURLRespDoc;
}
protected XmlObject getReturnObject(Class type) throws Exception {
Method creatorMethod = null;
if (XmlObject.class.isAssignableFrom(type)) {
Class[] declaredClasses = type.getDeclaredClasses();
for (int i = 0; i < declaredClasses.length; i++) {
Class declaredClass = declaredClasses[i];
if (declaredClass.getName().endsWith("$Factory")) {
creatorMethod = declaredClass.getMethod("newInstance", null);
break;
}
}
}
if (creatorMethod != null) {
return (XmlObject) creatorMethod.invoke(null, null);
}
else {
throw new Exception("Creator not found!");
}
}
}
=====================================
=====================================
=====================================
=====================================
(1) AbstractInOutSyncMessageReceiver java file
-----------------------------------------------------------------
package com.daffron.multispeak;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.axis2.*;
import org.apache.axis2.context.*;
import org.apache.axis2.description.*;
import org.apache.axis2.engine.*;
import org.apache.axis2.om.*;
import org.apache.axis2.om.impl.OMNodeEx;
import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
import org.apache.axis2.receivers.*;
import org.apache.axis2.soap.*;
import org.apache.axis2.util.StreamWrapper;
import org.apache.xmlbeans.XmlObject;
import org.multispeak.version30.*;
/**
*
*/
public class MultispeakSoapMessageReceiver extends AbstractInOutSyncMessageReceiver {
//
private static QName[] qNameArray = {};
public void invokeBusinessLogic(MessageContext msgContext, MessageContext \
newMsgContext) throws AxisFault { try {
// get the implementation class for the Web Service
Object obj = getTheImplementationObject(msgContext);
//Inject the Message Context if it is asked for
DependencyManager.configureBusinessLogicProvider(obj, msgContext, newMsgContext);
MultispeakSoapSkeleton skel = (MultispeakSoapSkeleton) obj;
//Out Envelop
SOAPEnvelope envelope = null;
//Find the axisOperation that has been set by the Dispatch phase.
AxisOperation op = msgContext.getOperationContext().getAxisOperation();
if (op == null) {
throw new AxisFault(
"Operation is not located, if this is doclit style the SOAP-ACTION should \
specified via the SOAP Action to use the RawXMLProvider"); }
String methodName;
if ((op.getName() != null) & ((methodName = op.getName().getLocalPart()) != null)) \
{ SOAPEnvelope tempEnv = msgContext.getEnvelope();
// NOTE: validate header
SOAPHeader header = tempEnv.getHeader();
if (header != null) {
OMElement headerE = header.getFirstElement();
validateHeader((MultiSpeakMsgHeaderDocument) fromOM(headerE, \
MultiSpeakMsgHeaderDocument.class)); }
if ("PingURL".equals(methodName)) {
PingURLResponseDocument respDoc = null;
//doc style
respDoc = skel.PingURL((PingURLDocument) \
fromOM(msgContext.getEnvelope().getBody().getFirstElement(), \
PingURLDocument.class));
envelope = toEnvelope(getSOAPFactory(msgContext), respDoc);
}
newMsgContext.setEnvelope(envelope);
}
}
catch (Exception e) {
throw AxisFault.makeFault(e);
}
}
private OMElement toOM(MultiSpeakMsgHeaderDocument param) {
StAXOMBuilder builder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), new \
StreamWrapper(param.newXMLStreamReader()));
OMElement documentElement = builder.getDocumentElement();
optimizeContent(documentElement, qNameArray);
((OMNodeEx) documentElement).setParent(null);
return documentElement;
}
private SOAPEnvelope toEnvelope(SOAPFactory factory, MultiSpeakMsgHeaderDocument \
param) { SOAPEnvelope envelope = factory.getDefaultEnvelope();
envelope.getBody().addChild(toOM(param));
return envelope;
}
private boolean validateHeader(MultiSpeakMsgHeaderDocument headerDoc) {
return true;
}
private OMElement toOM(PingURLResponseDocument param) {
StAXOMBuilder builder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), new \
StreamWrapper(param.newXMLStreamReader()));
OMElement documentElement = builder.getDocumentElement();
optimizeContent(documentElement, qNameArray);
((OMNodeEx) documentElement).setParent(null);
return documentElement;
}
private SOAPEnvelope toEnvelope(SOAPFactory factory, PingURLResponseDocument param) \
{ SOAPEnvelope envelope = factory.getDefaultEnvelope();
envelope.getBody().addChild(toOM(param));
return envelope;
}
private OMElement toOM(PingURLDocument param) {
StAXOMBuilder builder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), new \
StreamWrapper(param.newXMLStreamReader()));
OMElement documentElement = builder.getDocumentElement();
optimizeContent(documentElement, qNameArray);
((OMNodeEx) documentElement).setParent(null);
return documentElement;
}
private SOAPEnvelope toEnvelope(SOAPFactory factory, PingURLDocument param) {
SOAPEnvelope envelope = factory.getDefaultEnvelope();
envelope.getBody().addChild(toOM(param));
return envelope;
}
public XmlObject fromOM(OMElement param, Class type) {
try {
if (MultiSpeakMsgHeaderDocument.class.equals(type)) {
return MultiSpeakMsgHeaderDocument.Factory.parse(param.getXMLStreamReaderWithoutCaching());
}
if (PingURLResponseDocument.class.equals(type)) {
return PingURLResponseDocument.Factory.parse(param.getXMLStreamReaderWithoutCaching());
}
if (PingURLDocument.class.equals(type)) {
return PingURLDocument.Factory.parse(param.getXMLStreamReaderWithoutCaching());
}
}
catch (Exception e) {
throw new RuntimeException("Data binding error", e);
}
return null;
}
private void optimizeContent(org.apache.axis2.om.OMElement element, \
javax.xml.namespace.QName[] qNames) { for (int i = 0; i < qNames.length; i++) {
markElementsAsOptimized(qNames[i], element);
}
}
private void markElementsAsOptimized(javax.xml.namespace.QName qName, \
org.apache.axis2.om.OMElement rootElt) { if (rootElt.getQName().equals(qName)) {
//get the text node and mark it
org.apache.axis2.om.OMNode node = rootElt.getFirstOMChild();
if (node.getType() == org.apache.axis2.om.OMNode.TEXT_NODE) {
((org.apache.axis2.om.OMText) node).setOptimize(true);
}
}
java.util.Iterator childElements = rootElt.getChildElements();
while (childElements.hasNext()) {
markElementsAsOptimized(qName, (org.apache.axis2.om.OMElement) \
childElements.next()); }
}
}
=====================================
=====================================
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic