-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi
I am having trouble making a custom serializer/deserializer,
i have read through this list somewhat, googled alot but
cant seem to find any good examples or usable documentation on the
subject.
my ant buildfile wsdl2java part:
======================
<target name="wsdl2java" description="Generate stubs from webservice">
<!-- <mkdir dir="${src}" /> -->
<mkdir dir="${src-gen}" />
<java classname="org.apache.axis.wsdl.WSDL2Java" fork="yes"
dir="${src-gen}">
<arg
value="http://localhost:8080/axis/services/HelloWorld?wsdl" />
<classpath refid="compile.classpath" />
</java>
</target>
my deploy.wsdd file:
=======================
<deployment
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name = "HelloWorld" provider = "java:RPC" style="document"
use="literal">
<parameter name = "wsdlTargetNamespace" value="HelloWorld"/>
<!-- <parameter name = "wsdlServiceElement"
value="urn:com.telenor.rd"/>
<parameter name = "wsdlServicePort" value="HelloWorld"/> -->
<parameter name = "className"
value="com.telenor.rd.HelloWorldThread"/>
<parameter name = "scope" value="Application"/>
<operation name = "testMethod" qname="operNS:testMethod"
xmlns:operNS="urn:com.telenor.rd" returnType="rtns:string"
xmlns:rtns="http://www.w3.org/2001/XMLSchema" soapAction="" >
<parameter qname="pns:param" xmlns:pns="http://rd.telenor.com"
type="tns:Parameter" xmlns:tns="http://rd.telenor.com"/>
</operation>
<parameter name = "allowedMethods" value = "*"/>
<typeMapping
qname="ns1:Parameter"
xmlns:ns1="http://rd.telenor.com"
languageSpecificType="java:com.telenor.rd.Parameter"
serializer="com.telenor.rd.ParameterSerializerFactory"
deserializer="com.telenor.rd.ParameterDeserializerFactory"/>
</service>
</deployment>
Parameter.java: (i am dropping all the imports from the files too keep
the length of this message down)
=========================
/*
* Created on 24.mai.2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.telenor.rd;
/**
* @author Arild Herstad
*
*/
public class Parameter {
private String Streng;
private int Heltall;
/**
*
*/
public Parameter() {
this.Streng = null;
this.Heltall = 0;
}
/**
* @param Streng
* @param Heltall
*/
public Parameter(String Streng, int Heltall) {
this.Streng = Streng;
this.Heltall = Heltall;
}
public int add(int number) {
Heltall += number;
return Heltall;
}
public int subtract(int number){
Heltall -= number;
return Heltall;
}
/**
* @return Returns the Heltall.
*/
public int getHeltall() {
return Heltall;
}
/**
* @param Heltall The Heltall to set.
*/
public void setHeltall(int Heltall) {
this.Heltall = Heltall;
}
/**
* @return Returns the Streng.
*/
public String getStreng() {
return Streng;
}
/**
* @param Streng The Streng to set.
*/
public void setStreng(String Streng) {
this.Streng = Streng;
}
}
ParameterDeserializer.java:
======================
package com.telenor.rd;
public class ParameterDeserializer extends DeserializerImpl {
// Field names from Person objects
public static final String STRENG = "Streng";
public static final String HELTALL = "Heltall";
public static final QName myTypeQName = new
QName("http://rd.telenor.com", "Parameter");
private Hashtable typesByMemberName = new Hashtable();
public ParameterDeserializer() {
typesByMemberName.put(STRENG, Constants.XSD_STRING);
typesByMemberName.put(HELTALL, Constants.XSD_INT);
value = new Parameter();
}
public SOAPHandler onStartChild(String namespace, String
localName, String prefix, Attributes attributes,
DeserializationContext context)
throws SAXException
{
System.out.println("in Deserializer!");
QName typeQName=(QName)typesByMemberName.get(localName);
if(typeQName==null){
throw new SAXException("Invalid Element in Person
Struct"+localName);
}
Deserializer dSer=context.getDeserializerForType(typeQName);
try {
dSer.registerValueTarget(new FieldTarget(value,localName));
}
catch(NoSuchFieldException e){
throw new SAXException(e);
}
if (dSer==null)
throw new SAXException("NO deserializer for a"+ typeQName
+ " ???");
return (SOAPHandler)dSer;
}
}
ParameterSerializer.java:
==========================
package com.telenor.rd;
public class ParameterSerializer implements Serializer {
// Field names from Person objects
public static final String STRENG = "Streng";
public static final String HELTALL = "Heltall";
public static final QName myTypeQName = new
QName("http://rd.telenor.com", "Parameter");
// Qualified names for XML nodes
public final static QName QUALIFIED_NAME_STRENG = new QName(STRENG);
public final static QName QUALIFIED_NAME_HELTALL= new QName(HELTALL);
public void serialize(QName name, Attributes attributes, Object
value, SerializationContext context)
throws IOException
{
System.out.println("in Serializer!");
if(!(value instanceof Parameter)){
throw new IOException("Can't serialize a " +
value.getClass().getName()+"with Parameter Serializer");
}
Parameter data=(Parameter)value;
context.startElement(name,attributes);
context.serialize(QUALIFIED_NAME_STRENG,null,data.getStreng());
context.serialize(QUALIFIED_NAME_HELTALL,null,new
Integer(data.getHeltall()));
context.endElement();
}
public String getMechanismType() { return Constants.AXIS_SAX; }
public Element writeSchema(Class javaType, Types types) throws
Exception {
Element complexType=types.createElement("complexType");
types.writeSchemaElement(myTypeQName,complexType);
complexType.setAttribute("name","Parameter");
Element seq=types.createElement("sequence");
complexType.appendChild(seq);
Element name=types.createElement("element");
name.setAttribute("name","Streng");
name.setAttribute("type", "xsd:string");
seq.appendChild(name);
Element ageElement =types.createElement("element");
ageElement.setAttribute("name","Heltall");
ageElement.setAttribute("type","xsd:int");
seq.appendChild(ageElement);
return complexType;
}
}
ParameterDeserializerFactory.java:
==========================
package com.telenor.rd;
public class ParameterDeserializerFactory implements DeserializerFactory {
private Vector mechanisms;
public ParameterDeserializerFactory() {
}
public javax.xml.rpc.encoding.Deserializer
getDeserializerAs(String mechanismType) throws JAXRPCException {
return new ParameterDeserializer();
}
public Iterator getSupportedMechanismTypes() {
if (mechanisms == null) {
mechanisms = new Vector();
mechanisms.add(Constants.AXIS_SAX);
}
return mechanisms.iterator();
}
}
ParameterSerializerFactory.java:
============================
package com.telenor.rd;
public class ParameterSerializerFactory implements SerializerFactory {
private Vector mechanisms;
public ParameterSerializerFactory() {
}
public javax.xml.rpc.encoding.Serializer
getSerializerAs(String mechanismType) throws JAXRPCException {
ParameterSerializer heh = new ParameterSerializer();
return new ParameterSerializer();
}
public Iterator getSupportedMechanismTypes() {
if (mechanisms == null) {
mechanisms = new Vector();
mechanisms.add(Constants.AXIS_SAX);
}
return mechanisms.iterator();
}
}
The exported service: HelloWorldThread.java:
===================================
/*
* Created on 07.10.2004
*
*/
package com.telenor.rd;
/**
* @author Sven Haiges | [EMAIL PROTECTED]
*/
public class HelloWorldThread extends Thread {
private boolean running = true;
public HelloWorldThread() {
}
public void run() {
while (running) {
System.out.println("Hello World!");
/*
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
System.out.println("HelloWorldThread ERROR: " + e);
}
*/
running = false;
}
}
public void stopThread() {
this.running = false;
}
public String testMethod(Parameter param) {
String resVar;
resVar = "Streng=" + param.getStreng() + " Heltall=" +
param.getHeltall();
return resVar;
}
}
the client class: webserviceClient.java:
=============================
/*
* Created on 27.mai.2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.telenor.rd;
/**
* @author t537929
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class webserviceClient {
public static void main(String[] args) throws Exception {
System.out.println("Calling a webservice...");
/*
* // Make a service WSSessionRemoteService service = new
* WSSessionRemoteServiceLocator();
* // Now use the service to get a stub which implements the SDI.
* WSSessionRemote port = service.getWSSession();
*/
HelloWorldThreadService service = new
HelloWorldThreadServiceLocator();
HelloWorldThread hw = service.getHelloWorld();
Parameter param = new Parameter();
param.setHeltall(10);
param.setStreng("Test");
System.out.println("Result : " + hw.testMethod(param));
}
}
RESULT:
==================
faultString: org.xml.sax.SAXException: Deserializing parameter
'param': could not find deserializer for type
{http://rd.telenor.com}Parameter
it works just fine when i change the typemapping in the wsdd file to:
<beanMapping languageSpecificType="java:com.telenor.rd.Parameter"
qname="ns1:Parameter" xmlns:ns1="urn:com.telenor.rd"/>
also after some more searching i though the problem could be solved by
registrering the typemapping on the client so i changed the client
class to:
=========================================
package com.telenor.fou;
public class webserviceClient {
public static void main(String[] args) throws Exception {
System.out.println("Calling a webservice...");
/*
* // Make a service WSSessionRemoteService service = new
* WSSessionRemoteServiceLocator();
* // Now use the service to get a stub which implements the SDI.
* WSSessionRemote port = service.getWSSession();
*/
HelloWorldThreadService service = new
HelloWorldThreadServiceLocator();
HelloWorldThread hw = service.getHelloWorld();
QName parameterTypeQname = new QName("http://rd.telenor.com"
,"Parameter");
SerializerFactory parSerFac = new ParameterSerializerFactory();
DeserializerFactory parDeserFac = new
ParameterDeserializerFactory();
TypeMapping tm = (TypeMapping)
service.getTypeMappingRegistry().getTypeMapping(Constants.URI_DEFAULT_SOAP_ENC);
tm.register(Parameter.class,parameterTypeQname,parSerFac,parDeserFac);
Parameter param = new Parameter();
param.setHeltall(10);
param.setStreng("Test");
System.out.println("Result : " + hw.testMethod(param));
}
}
that results in:
================
in Serializer!
Exception in thread "main" AxisFault
faultCode:
{http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: Deserializing parameter
'param': could not find deserializer for type
{http://rd.telenor.com}Parameter
faultActor:
faultNode:
faultDetail:
.....
Please help me on this, i have tried for quite a while now and would
love to know what i am doing completely wrong :)
thanks in advance
regards
Bjørn Magnus Mathisen
Telenor ASA - R&Dser
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCzlD0QRm7yJAC45gRAplxAKCeBXZMuRVwl1GMZ0ACc7pSzRYDFACgtCYT
7gJTC4fSPMnbzCY3LjctdOM=
=WD9i
-----END PGP SIGNATURE-----