You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by ja...@mitre.org on 2004/06/17 20:39:52 UTC

Populate WSDL2Java object from XML file.

How do you populate a WSDL2Java created object from an XML file?

I've hunted around in the mailing list archives, and I've seen this question
a few other times, but no answers that were clear enough for me to
understand.

Scenario: We have a WSDL which describes some service and imports some
schema which describes some data structures.  Run WSDL2Java on the WSDL and
get out lots of nice Java.  Typical usage is then to bind to a service
endpoint URL, create a parameter object, populate it, and invoke the service
with the method and parameter object.

Like this:
myService =  new MyServiceLocator().getMyService(new URL(serviceEndpoint));
_myObject requestObj = new _myObject();
requestObj.setSomething(someValue);
Status s = myService.request(requestObj);

However, if _myObject is very complex, manually populating it is a pain.
It'd be easier to have an XML document lying around that complies with the
schema and just deserialize the XML into the WSDL2Java created object.

I tried:
DeserializerImpl myDeserializer =
(DeserializerImpl)_myObject.getDeserializer("", _myObject.class, myQName);
XMLReader reader =
SAXParserFactory.newInstance().newSAXParser().getXMLReader();
reader.setContentHandler(myDeserializer);
reader.parse(new InputSource(new FileInputStream(filename)));
_myObject myObj = (_myObject)myDeserializer.getValue();

But all I get is an empty _myObject.  I _THINK_ part of the issue is that
the deserializer doesn't have access to the type mapping info in
deploy.wsdd, but I'm at a loss how to get that info to the deserializer.  

Maybe this is worth putting in the Wiki?

Help, please.

Thanks.

- Jasen.


Re: Populate WSDL2Java object from XML file.

Posted by Matt Payne <ma...@gmail.com>.
Jasen - Since classes generated by wsdl2java are just POJOs you can use Java's 
built in XMLEncoder class.   There are a few pointers about this here:
http://mattpayne.org/b.cgi/Programming/Java/XMLEncoder.pf

-Matt

On Thu, 17 Jun 2004 14:39:52 -0400, jasenj1@mitre.org <ja...@mitre.org> wrote:
> 
> How do you populate a WSDL2Java created object from an XML file?
> 
> I've hunted around in the mailing list archives, and I've seen this question
> a few other times, but no answers that were clear enough for me to
> understand.
> 
> Scenario: We have a WSDL which describes some service and imports some
> schema which describes some data structures.  Run WSDL2Java on the WSDL and
> get out lots of nice Java.  Typical usage is then to bind to a service
> endpoint URL, create a parameter object, populate it, and invoke the service
> with the method and parameter object.
> 
> Like this:
> myService =  new MyServiceLocator().getMyService(new URL(serviceEndpoint));
> _myObject requestObj = new _myObject();
> requestObj.setSomething(someValue);
> Status s = myService.request(requestObj);
> 
> However, if _myObject is very complex, manually populating it is a pain.
> It'd be easier to have an XML document lying around that complies with the
> schema and just deserialize the XML into the WSDL2Java created object.
> 
> I tried:
> DeserializerImpl myDeserializer =
> (DeserializerImpl)_myObject.getDeserializer("", _myObject.class, myQName);
> XMLReader reader =
> SAXParserFactory.newInstance().newSAXParser().getXMLReader();
> reader.setContentHandler(myDeserializer);
> reader.parse(new InputSource(new FileInputStream(filename)));
> _myObject myObj = (_myObject)myDeserializer.getValue();
> 
> But all I get is an empty _myObject.  I _THINK_ part of the issue is that
> the deserializer doesn't have access to the type mapping info in
> deploy.wsdd, but I'm at a loss how to get that info to the deserializer.
> 
> Maybe this is worth putting in the Wiki?
> 
> Help, please.
> 
> Thanks.
> 
> - Jasen.
> 
>

Re: "Content is not allowed in prolog" exception

Posted by "NJ Rogers, Learning and Research Technology" <Ni...@bristol.ac.uk>.
Hi

It's a prob I've had before & to do with the leading xml declaration
see e.g.

http://java2.5341.com/msg/44393.html

- a case which might have something in common with yours?

Nikki

--On Thursday, July 01, 2004 10:38:08 +0530 Ramya Manian 
<ra...@persistent.co.in> wrote:

> Hi
>
> I get a SAX parser exception as "Content is not allowed in prolog"
> while parsing the response. I have included the response that I
> receive from the server and the stack trace of the exception. Also
> there are no junk characters before or after the response.
>
> Can someone please explain what can cause this exception? Is anything
> wrong in the response?
>
> This is a repost as there were no replies for the earlier one. I need to
> get this working ASAP.
>
> Thanks
> Ramya
>
> RESPONSE
> ----------
> HTTP/1.1 200 OK Accept: application/soap+xml, application/dime,
> multipart/related, text/* Cache-Control: no-cache Content-Type: text/xml;
> charset="UTF-8" Host: 127.0.0.1 Pragma: no-cache User-Agent: enlistSrv
> Content-Length: 728
> <?xml version="1.0" encoding="UTF-8"?>
>    <E:Envelope xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:A="http://schemas.xmlsoap.org/soap/encoding/"
> xmlns:s="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:y="http://www.w3.org/2001/XMLSchema"
> E:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
>       <E:Body>
>          <m:ConnectResponse
> xmlns:m="http://www.PersistentData.com/enList">
> <m:connectionid s:type="y:int">3</m:connectionid>
>             <m:result>
>                <m:resultCode s:type="y:int">0</m:resultCode>
>                <m:errorCode s:type="y:int">0</m:errorCode>
>                <m:errorMessage s:type="y:string"></m:errorMessage>
>                <m:diagonsticMessage
> s:type="y:string"></m:diagonsticMessage>                <m:size
> s:type="y:int">0</m:size>
>             </m:result>
>          </m:ConnectResponse>
>       </E:Body>
>    </E:Envelope>
>
>
> STACKTRACE
> ----------
> " org.xml.sax.SAXParseException: Content is not allowed in prolog.
>         at org.apache.axis.AxisFault.makeFault(AxisFault.java:129)
>         at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:562)
>         at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
>         at org.apache.axis.client.Call.invokeEngine(Call.java:2600)
>         at org.apache.axis.client.Call.invoke(Call.java:2565)
>         at org.apache.axis.client.Call.invoke(Call.java:2254)
>         at org.apache.axis.client.Call.invoke(Call.java:2177)
>         at org.apache.axis.client.Call.invoke(Call.java:1694)
>         at
> com.PersistentData.www.enList.ServiceBindingStub.connect(ServiceBindingSt
> ub.java :312)
>         at Client.main(Client.java:32)
> Caused by: org.xml.sax.SAXParseException: Content is not allowed in
> prolog.         at
> org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorH
> andlerW rapper.ja
> va:236)
>         at
> org.apache.xerces.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper
> .java:2 15)
>         at
> org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java
> :384)         at
> org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java
> :314)         at
> org.apache.xerces.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
>         at
> org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(X
> MLDocum entScanne
> rImpl.java:857)
>         at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDoc
> umentFr agmentSca
> nnerImpl.java:338)
>         at
> org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.jav
> a:828)         at
> org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.jav
> a:758)         at
> org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:148)         at
> org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:
> 1178)         at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
>         at
> org.apache.axis.encoding.DeserializationContextImpl.parse(Deserialization
> Context Impl.java
> :272)
>         at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:554)
>         ... 8 more
> "
>



----------------------
NJ Rogers, Technical Researcher
(Semantic Web Applications Developer)
Institute for Learning and Research Technology (ILRT)
Email:nikki.rogers@bristol.ac.uk
Tel: +44(0)117 9287096 (Direct)
Tel: +44(0)117 9287193 (Office)

"Content is not allowed in prolog" exception

Posted by Ramya Manian <ra...@persistent.co.in>.
Hi

I get a SAX parser exception as "Content is not allowed in prolog"
while parsing the response. I have included the response that I
receive from the server and the stack trace of the exception. Also
there are no junk characters before or after the response.

Can someone please explain what can cause this exception? Is anything
wrong in the response?

This is a repost as there were no replies for the earlier one. I need to get
this working ASAP.

Thanks
Ramya

RESPONSE
----------
HTTP/1.1 200 OK Accept: application/soap+xml, application/dime,
multipart/related, text/* Cache-Control: no-cache Content-Type: text/xml;
charset="UTF-8" Host: 127.0.0.1 Pragma: no-cache User-Agent: enlistSrv
Content-Length: 728
<?xml version="1.0" encoding="UTF-8"?>
   <E:Envelope xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:A="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s="http://www.w3.org/2001/XMLSchema-instance"
xmlns:y="http://www.w3.org/2001/XMLSchema"
E:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <E:Body>
         <m:ConnectResponse xmlns:m="http://www.PersistentData.com/enList">
            <m:connectionid s:type="y:int">3</m:connectionid>
            <m:result>
               <m:resultCode s:type="y:int">0</m:resultCode>
               <m:errorCode s:type="y:int">0</m:errorCode>
               <m:errorMessage s:type="y:string"></m:errorMessage>
               <m:diagonsticMessage s:type="y:string"></m:diagonsticMessage>
               <m:size s:type="y:int">0</m:size>
            </m:result>
         </m:ConnectResponse>
      </E:Body>
   </E:Envelope>


STACKTRACE
----------
" org.xml.sax.SAXParseException: Content is not allowed in prolog.
        at org.apache.axis.AxisFault.makeFault(AxisFault.java:129)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:562)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2600)
        at org.apache.axis.client.Call.invoke(Call.java:2565)
        at org.apache.axis.client.Call.invoke(Call.java:2254)
        at org.apache.axis.client.Call.invoke(Call.java:2177)
        at org.apache.axis.client.Call.invoke(Call.java:1694)
        at
com.PersistentData.www.enList.ServiceBindingStub.connect(ServiceBindingStub.java
:312)
        at Client.main(Client.java:32)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
        at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerW
rapper.ja
va:236)
        at
org.apache.xerces.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:2
15)
        at
org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
        at
org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:314)
        at
org.apache.xerces.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
        at
org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(XMLDocum
entScanne
rImpl.java:857)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFr
agmentSca
nnerImpl.java:338)
        at
org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:828)
        at
org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:758)
        at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:148)
        at
org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1178)
        at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
        at
org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContext
Impl.java
:272)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:554)
        ... 8 more
"


RE: Very urgent: "Read timed out" error while parsing the response

Posted by Ramya Manian <ra...@persistent.co.in>.
Hi

Furthur to my earlier problem given below, I found out that the "Read timed out"
error occurs
when XML parser is trying to fetch the document version from the response. By
default EasySOAP (which is used by our server) does not include the XML
declaration in the response. Once the XML declaration (<?xml version="1.0"
encoding="UTF-8"?>) was included, the timed out exception got resolved.
But now I get a SAX parser exception as "Content is not allowed in prolog". I
have included the response that I receive from the server and the stack trace of
the exception. Can someone please explain why I get this error? Is anything
wrong in the response?

Thanks
Ramya

RESPONSE
----------
HTTP/1.1 200 OK Accept: application/soap+xml, application/dime,
multipart/related, text/* Cache-Control: no-cache Content-Type: text/xml;
charset="UTF-8" Host: 127.0.0.1 Pragma: no-cache User-Agent: enlistSrv
Content-Length: 728
<?xml version="1.0" encoding="UTF-8"?>
   <E:Envelope xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:A="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s="http://www.w3.org/2001/XMLSchema-instance"
xmlns:y="http://www.w3.org/2001/XMLSchema"
E:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <E:Body>
         <m:ConnectResponse xmlns:m="http://www.PersistentData.com/enList">
            <m:connectionid s:type="y:int">3</m:connectionid>
            <m:result>
               <m:resultCode s:type="y:int">0</m:resultCode>
               <m:errorCode s:type="y:int">0</m:errorCode>
               <m:errorMessage s:type="y:string"></m:errorMessage>
               <m:diagonsticMessage s:type="y:string"></m:diagonsticMessage>
               <m:size s:type="y:int">0</m:size>
            </m:result>
         </m:ConnectResponse>
      </E:Body>
   </E:Envelope>


STACKTRACE
----------
" org.xml.sax.SAXParseException: Content is not allowed in prolog.
        at org.apache.axis.AxisFault.makeFault(AxisFault.java:129)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:562)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2600)
        at org.apache.axis.client.Call.invoke(Call.java:2565)
        at org.apache.axis.client.Call.invoke(Call.java:2254)
        at org.apache.axis.client.Call.invoke(Call.java:2177)
        at org.apache.axis.client.Call.invoke(Call.java:1694)
        at
com.PersistentData.www.enList.ServiceBindingStub.connect(ServiceBindingStub.java
:312)
        at Client.main(Client.java:32)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
        at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerW
rapper.ja
va:236)
        at
org.apache.xerces.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:2
15)
        at
org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
        at
org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:314)
        at
org.apache.xerces.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
        at
org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(XMLDocum
entScanne
rImpl.java:857)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFr
agmentSca
nnerImpl.java:338)
        at
org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:828)
        at
org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:758)
        at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:148)
        at
org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1178)
        at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
        at
org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContext
Impl.java
:272)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:554)
        ... 8 more
"

-----Original Message-----
From: Ramya Manian [mailto:ramya_manian@persistent.co.in]
Sent: Monday, June 21, 2004 5:54 PM
To: axis-user@ws.apache.org
Subject: Very urgent: "Read timed out" error while parsing the response
using JAxis 1-1


Hi

We have written our client using JAxis to send requests and our SOAP server uses
EasySOAP library
for providing the SOAP interface.

But the client throws a "Read timed out" error while parsing the response from
the server.

I tried increasing the timeout value but it did not work.
The error occurs just before parsing the response using Xerces SAX parser. I
also
printed the contents of the response before sending it for parsing and it seemed
to be
complete and OK. I am not able to figure out what is causing the error.

Any pointers on why is this occurring?

Are there any compatibility issues between JAxis1-1 and EasySOAP or Xerces ?
Are there any known issues that must be taken care of?

We need answers to the questions ASAP.

Thanks in advance
Ramya


Very urgent: "Read timed out" error while parsing the response using JAxis 1-1

Posted by Ramya Manian <ra...@persistent.co.in>.
Hi

We have written our client using JAxis to send requests and our SOAP server uses
EasySOAP library
for providing the SOAP interface.

But the client throws a "Read timed out" error while parsing the response from
the server.

I tried increasing the timeout value but it did not work.
The error occurs just before parsing the response using Xerces SAX parser. I
also
printed the contents of the response before sending it for parsing and it seemed
to be
complete and OK. I am not able to figure out what is causing the error.

Any pointers on why is this occurring?

Are there any compatibility issues between JAxis1-1 and EasySOAP or Xerces ?
Are there any known issues that must be taken care of?

We need answers to the questions ASAP.

Thanks in advance
Ramya


RE: Populate WSDL2Java object from XML file.

Posted by Anderson Jonathan <an...@bah.com>.
Ever looked into Axis MSG style calls?  This is client code, but you can do
the same thing on the server side as well, assuming you've built a MSG style
service.  Check out the Axis docs for more information.

Service service = new Service();
Call call = (Call) service.createCall();
call.setSOAPActionURI("MyOperationName");
call.setTargetEndpointAddress("http://localhost:8080/services/MyService");

SOAPBodyElement body = new SOAPBodyElement(doc.getDocumentElement());
body.setNamespaceURI("");
call.invoke(new SOAPBodyElement[]{body});

-Jon

-----Original Message-----
From: jasenj1@mitre.org [mailto:jasenj1@mitre.org]
Sent: Thursday, June 17, 2004 2:40 PM
To: axis-user@ws.apache.org
Subject: Populate WSDL2Java object from XML file.


How do you populate a WSDL2Java created object from an XML file?

I've hunted around in the mailing list archives, and I've seen this question
a few other times, but no answers that were clear enough for me to
understand.

Scenario: We have a WSDL which describes some service and imports some
schema which describes some data structures.  Run WSDL2Java on the WSDL and
get out lots of nice Java.  Typical usage is then to bind to a service
endpoint URL, create a parameter object, populate it, and invoke the service
with the method and parameter object.

Like this:
myService =  new MyServiceLocator().getMyService(new URL(serviceEndpoint));
_myObject requestObj = new _myObject();
requestObj.setSomething(someValue);
Status s = myService.request(requestObj);

However, if _myObject is very complex, manually populating it is a pain.
It'd be easier to have an XML document lying around that complies with the
schema and just deserialize the XML into the WSDL2Java created object.

I tried:
DeserializerImpl myDeserializer =
(DeserializerImpl)_myObject.getDeserializer("", _myObject.class, myQName);
XMLReader reader =
SAXParserFactory.newInstance().newSAXParser().getXMLReader();
reader.setContentHandler(myDeserializer);
reader.parse(new InputSource(new FileInputStream(filename)));
_myObject myObj = (_myObject)myDeserializer.getValue();

But all I get is an empty _myObject.  I _THINK_ part of the issue is that
the deserializer doesn't have access to the type mapping info in
deploy.wsdd, but I'm at a loss how to get that info to the deserializer.

Maybe this is worth putting in the Wiki?

Help, please.

Thanks.

- Jasen.