[ 
https://issues.apache.org/jira/browse/AXIS2-5065?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13070373#comment-13070373
 ] 

Paul Nibin K J commented on AXIS2-5065:
---------------------------------------

Hi,

I tried to create a service which receives and returns Document object. My 
service class is:

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

public class DocumentTest
{
    public Document echoDocument( Document doc ) throws Exception
    {
        Transformer trans;
        try
        {
            trans = TransformerFactory.newInstance().newTransformer();
            trans.setOutputProperty( OutputKeys.METHOD, "xml" );
            trans.setOutputProperty( OutputKeys.INDENT, "yes" );
            trans.setOutputProperty( 
"{http://xml.apache.org/xslt}indent-amount";, Integer.toString( 2 ) );

            StringWriter sw = new StringWriter();
            StreamResult result = new StreamResult( sw );
            DOMSource source = new DOMSource( doc.getDocumentElement() );

            trans.transform( source, result );
            String xmlString = sw.toString();
            System.out.println( xmlString );
            return doc;
        }
        catch ( Exception e )
        {
            throw new Exception( "Exception occured while printing the 
document.", e );
        }
    }
}

I deployed the service as a POJO and generated the client stub using the 
following code.

WSDL2Java.main( new String []
        { "-o", ".", "-uw", "-u", "-uri", 
"http://localhost:8080/axis2/services/DocumentTest?wsdl"; } );

My client code to test is:

import java.io.IOException;
import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class Axis2DocumentTest
{
    public static void main( String [] args ) throws 
DocumentTestExceptionException, ParserConfigurationException,
            SAXException, IOException
    {
        DocumentTestStub stub = new DocumentTestStub();
        DocumentBuilder builder = 
DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.parse( new InputSource( new StringReader(
                "<person id=\"1\"><name>Paul</name></person>" ) ) );
        Object echoDocument = stub.echoDocument( document );
        System.out.println( echoDocument );
    }
}

When I try to invoke the service, I am getting the following exception in the 
client side.

Exception in thread "main" org.apache.axis2.AxisFault: Unknow type can not 
serialize
      at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
      at 
org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:78)
      at 
org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:84)
      at 
org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
      at 
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
      at 
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
      at 
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
      at 
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
      at 
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
      at 
org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
      at 
org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
      at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
      at 
org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
      at 
org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
      at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
      at 
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
      at 
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
      at 
org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
      at 
org.apache.ws.axis2.DocumentTestStub.echoDocument(DocumentTestStub.java:190)
      at org.apache.ws.axis2.Axis2DocumentTest.main(Axis2DocumentTest.java:23)
Caused by: javax.xml.stream.XMLStreamException: Unknow type can not serialize
      at 
org.apache.axis2.databinding.utils.ConverterUtil.serializeAnyType(ConverterUtil.java:1472)
      at org.apache.ws.axis2.EchoDocument.serialize(EchoDocument.java:137)
      at org.apache.ws.axis2.EchoDocument.serialize(EchoDocument.java:93)
      at 
org.apache.axis2.databinding.ADBDataSource.serialize(ADBDataSource.java:90)
      at 
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.internalSerialize(OMSourcedElementImpl.java:701)
      at 
org.apache.axiom.om.impl.util.OMSerializerUtil.serializeChildren(OMSerializerUtil.java:564)
      at 
org.apache.axiom.om.impl.llom.OMElementImpl.internalSerialize(OMElementImpl.java:904)
      at 
org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.serializeInternally(SOAPEnvelopeImpl.java:283)
      at 
org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.internalSerialize(SOAPEnvelopeImpl.java:245)
      at 
org.apache.axiom.om.impl.llom.OMSerializableImpl.serializeAndConsume(OMSerializableImpl.java:193)
      at 
org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:74)
      ... 18 more

Please check this case.

Also I find that the return type of the Object DocumentTestStub.echoDocument( 
Document doc ) is java.lang.Object. Shouldn't this be Document?

Thanks,
Paul 

> Provide support for org.w3c.dom.Document in web service.
> --------------------------------------------------------
>
>                 Key: AXIS2-5065
>                 URL: https://issues.apache.org/jira/browse/AXIS2-5065
>             Project: Axis2
>          Issue Type: Improvement
>          Components: adb
>    Affects Versions: 1.5.4, 1.6.0
>            Reporter: Muhammed Shariq
>            Assignee: Sagara Gunathunga 
>             Fix For: 1.7.0
>
>
> Provide support for org.w3c.dom.Document as a parameter for a web service. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to