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 Arthur van Dorp <ar...@gmx.net> on 2006/07/17 14:23:23 UTC

Reusing the axis serializers [Axis 1.4]

Hi all

I'm using Axis 1.4 and java classes generated with WSDL2Java for offering a webservice. The service adds a bit of generated data and is then supposed to store it as a file again in XML. As all the serializers are already there thanks to Axis I'd like to use them. Every generated class has a getSerializer(java.lang.String mechType, java.lang.Class _javaType, javax.xml.namespace.QName _xmlType) function and there's a SerializerFactory. I've looked at the Axis documentation and the source but couldn't figure out how to use getSerializer correctly. Any pointers to documentations or a small example would be very welcome.

Thanks, Arthur.


-- 


Echte DSL-Flatrate dauerhaft für 0,- Euro*!
"Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Re: Re: Reusing the axis serializers [Axis 1.4]

Posted by Arthur van Dorp <ar...@gmx.net>.
Hi again

The code is now much nicer and works very well. Thanks again.

Arthur


MyDocType queryDoc = new MyDocType();

QueryParams queryParams = new QueryParams();

// Get a nice XML representation

MyServiceService_ServiceLocator service
= new MyService_ServiceLocator();

service.setEPCglobalEPCISServiceEndpointAddress(
	accessURI); // Wherever your service is accessible.

MyServicePortType MyService
	= new MyServiceBindingImpl();

javax.xml.namespace.QName queryDocXMLType =
MyDocType.getTypeDesc().getXmlType();

OutputStreamWriter oWriter = new OutputStreamWriter(Out);
SerializationContext serContext
= new SerializationContext(oWriter);
serContext.setWriteXMLType(queryDocXMLType);

queryDoc = myService.poll(pollParams);

serContext.serialize(
	queryDocXMLType,
	new NullAttributes(),
	queryDoc,
	queryDocXMLType,
	MyDocType.class, false, true);

-- 


Echte DSL-Flatrate dauerhaft für 0,- Euro*!
"Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Re: Reusing the axis serializers [Axis 1.4]

Posted by Arthur van Dorp <ar...@gmx.net>.
Hi Martin

> > I'm using Axis 1.4 and java classes generated with WSDL2Java for
> > offering a webservice. The service adds a bit of generated data and is then
> > supposed to store it as a file again in XML. As all the serializers are already
> > there thanks to Axis I'd like to use them. Every generated class has a
> > getSerializer(java.lang.String mechType, java.lang.Class _javaType,
> > javax.xml.namespace.QName _xmlType) function and there's a SerializerFactory. I've
> > looked at the Axis documentation and the source but couldn't figure out how to
> > use getSerializer correctly. Any pointers to documentations or a small
> > example would be very welcome.
 
> Starting with the locator class example located at
> ./samples/addr/AddressBookServiceLocator.class
> will allow you to obtain a service object which will allow you to gain
> access to the properties you desire
> 
> I found the wsdl11 tutorial most instructive via /src/RunClient.java
> http://esw.w3.org/topic/SparqlProtocolWsdl11Examples
> [...]

A thousand thanks for your answer. With your answer, digging through the axis source code and trial and error I've managed to get nice XML from my class instances. I've attached the my work which somewhat resembles java code below in case anyone else has a similar problem. :)

Two problems remain:
* The outermost XML element is now of type xsd:anyType. I've got to have a look at this.
* The need for knowing the service endpoint is ugly.

Thanks again,

Arthur


MyQueryDocType queryDoc = new MyQueryDocType();

MyQueryParams queryParams = new MyServiceParams();
// Fill queryParams with something sensible.

OutputStream Out = whereverYouGetYourStreamFrom.getOutputStream();

// Get a nice XML representation

MyService_ServiceLocator service
	= new MyService_ServiceLocator();

service.setMyServiceEndpointAddress(
	"http://localhost:8080/WhereEverYourServiceLives");
MyServicePortType MyService
	= new MyServiceImpl(); // Your service implementation

javax.xml.rpc.encoding.TypeMappingRegistry reg
	= service.getTypeMappingRegistry();
TypeMapping tm = (TypeMapping) reg.getTypeMapping("");

javax.xml.namespace.QName queryDocQName
	= tm.getTypeQName(MyQueryDocType.class);
javax.xml.namespace.QName queryDocXMLType
	= tm.getXMLType(MyQueryDocType.class,
	queryDocQName,
	false); // TODO: Check boolean value.
Serializer serializer
	= EPCISQueryDocumentType.getSerializer("mechType??",
	MyQueryDocType.class,
	queryDocXMLType); // TODO: What is mechType?

OutputStreamWriter oWriter = new OutputStreamWriter(Out);
SerializationContext serContext
	= new SerializationContext(oWriter);

queryDoc = MyService.myQuery(queryParams);

serializer.serialize(queryDocXMLType,
	new NullAttributes(),
	queryDoc,
	serContext
	);

oWriter.flush();
oWriter.close();
Out.flush();
Out.close();

-- 


Echte DSL-Flatrate dauerhaft für 0,- Euro*!
"Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Reusing the axis serializers [Axis 1.4]

Posted by Martin Gainty <mg...@hotmail.com>.
Good Morning Arthur-

Starting with the locator class example located at
./samples/addr/AddressBookServiceLocator.class
will allow you to obtain a service object which will allow you to gain access to the properties you desire

I found the wsdl11 tutorial most instructive via /src/RunClient.java
http://esw.w3.org/topic/SparqlProtocolWsdl11Examples

To paraphrase-

//ensure this is declared at the top of your client source file
static String endpoint = "http://localhost:2525/axis/services/sparql-query" ;

//obtain the service
      SPARQLQueryServiceLocator  service = new SPARQLQueryServiceLocator();

       service.setSparqlQueryEndpointAddress(endpoint);
     
        // Retrieve a reference to the SparqlQuery interface
        SparqlQueryInterface soapQuery = null;
        try {
            soapQuery = service.getSparqlQuery() ;
        } catch (javax.xml.rpc.ServiceException ex) 
       { 
                throw new RuntimeException("Query exception: " + ex.getMessage()) ; 
        }

  a.. We next take care of some bookkeeping. The latest SPARQL-Protocol-draft XML Schema imports a stub schema file for RDF/XML. Because this schema does not fully describe the XML that will be returned when RDF/XML is returned, we must give Axis a custom deserializer that can be invoked when RDF/XML is encountered in the response to the query operation. In our case, we define a trivial deserializer factory (SimpleDeserializerFactory) and deserializer class (SimpleDeserializer) that does nothing more than convert the root element of an RDF/XML document fragment to its string representation. 

        // We register a stub class to deserialize RDF/XML
        // so that Axis does not complain. A "real" implementation
        // would use a deserialization class that parses the RDF/XML
        // into an appropriate graph representation. Our deserializer
        // simply returns a string representation of the RDF/XML returned.
        TypeMappingRegistry reg = service.getEngine().getTypeMappingRegistry() ;
        TypeMapping tm = (TypeMapping)reg.getTypeMapping("") ;
        tm.register(
            String.class, // the type to deserialize to
            new QName("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "RDF") ,
            null,         // SerializerFactory
            new SimpleDeserializerFactory()
        );
a.. The next step uses the bean classes to populate the input messages for the query operation: 

        QueryRequest q = new QueryRequest() ;
        q.setQuery(query) ;
        // Any default graphs or named graphs would be set here
        //q.setDefaultGraphUri(new URI[] { ... });
        //q.setNamedGraphUri(new URI[] { ... });
a.. Now we're ready to invoke the operation via the interface reference retrieved above. The various faults defined in the WSDL are translates to appropriately named exceptions. For the purposes of this example, we simply propagate any exceptions as RuntimeExceptions. 

        QueryResult result = null;
        try {
            result =  soapQuery.query(q) ;
        } catch (MalformedQuery ex) {
            throw new RuntimeException("Malformed query fault: " + ex.getFaultString(), ex) ;
        } catch (QueryRequestRefused refused) {
                throw new RuntimeException("Query request refused fault: " + refused.getFaultString(), refused);
        } catch (AxisFault axisFault) {
            throw new RuntimeException("Axis Fault: "+axisFault.getFaultString(), axisFault); 
        } catch (RemoteException e) {
            throw new RuntimeException("Remote Exception: "+e.getMessage(), e) ; 
        }HTHMartin --
*********************************************************************
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.



----- Original Message ----- 
From: "Arthur van Dorp" <ar...@gmx.net>
To: <ax...@ws.apache.org>
Sent: Monday, July 17, 2006 8:23 AM
Subject: Reusing the axis serializers [Axis 1.4]


> Hi all
> 
> I'm using Axis 1.4 and java classes generated with WSDL2Java for offering a webservice. The service adds a bit of generated data and is then supposed to store it as a file again in XML. As all the serializers are already there thanks to Axis I'd like to use them. Every generated class has a getSerializer(java.lang.String mechType, java.lang.Class _javaType, javax.xml.namespace.QName _xmlType) function and there's a SerializerFactory. I've looked at the Axis documentation and the source but couldn't figure out how to use getSerializer correctly. Any pointers to documentations or a small example would be very welcome.
> 
> Thanks, Arthur.
> 
> 
> -- 
> 
> 
> Echte DSL-Flatrate dauerhaft für 0,- Euro*!
> "Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
>