Tutorials to .com

Tutorials to .com » Jsp » Xml » Technical Analysis: Based on the Custom Axis Object Serialization

Technical Analysis: Based on the Custom Axis Object Serialization

Print View , by: iSee ,Total views: 42 ,Word Count: 1329 ,Date: Mon, 20 Apr 2009 Time: 4:39 AM


With the recent adoption of Web Services technology to do Enterprise application integration (EAI) projects, the technical staff can not respond to the use of Axis transfer user-defined object.

The whole error message is as follows:

AxisFault

faultCode: (http://schemas.xmlsoap.org/soap/envelope/) Server.userException

faultSubcode:

faultString: java.io.IOException: No serializer found for class com.whcyit.axis.SimpleObject in registry org.apache.axis.encoding.TypeMappingDelegate @ da3a1e

faultActor:

faultNode:

faultDetail:

(http://xml.apache.org/axis/) stackTrace: java.io.IOException: No serializer found for class com.whcyit.axis.SimpleObject in registry org.apache.axis.encoding.TypeMappingDelegate @ da3a1e

at org.apache.axis.encoding.SerializationContext.serializeActual (SerializationContext.java: 1429)

Contact for Web Services is already 4 years ago, and basically for Web Services there is a concept only. With doubt, try to decide on their own how matter in the end?

Finally, more than two hours of testing, the problem was finally resolved. Solution is as follows:

1. In the Axis client services, registered a custom object serialization / deserialization axis device is modified WEB-INF/server-config.wsdd document under the installation directory.

<service name="SimpleObjectService" provider="java:RPC"> <parameter name="allowedMethods" value="*"/> <parameter name="className" value="com.whcyit.axis.SimpleObjectService"/> < beanMapping languageSpecificType = "java: com.whcyit.axis.SimpleObject" qname = "ns: SimpleObject" xmlns: ns = "urn: BeanService "/></ service>

Attention to service / beanMapping definition. languageSpecificType defined in the use of that type, qname type the name of the definition.

2. In the Axis client, a registered custom object serialization / deserialization devices.

Core code is as follows:

/ / Create a call object Service service = new Service (); Call call = null; call = (Call) service.createCall ();// registration serial SimpleObject type QName qn = new QName ( "urn: BeanService", " SimpleObject "); call.registerTypeMapping (SimpleObject.class, qn, new BeanSerializerFactory (SimpleObject.class, qn), new BeanDeserializerFactory (SimpleObject.class, qn));

All sample code is as follows:

/ / SimpleObject.java

/ / Web Service object passing the object package com.whcyit.axis; import java.io.Serializable; public class SimpleObject implements Serializable (/ ** * * / private static final long serialVersionUID =-6414428095965735488L; private int i = 0; private float f = 0.0f; private String str = ""; public SimpleObject () () public float getFloat () (return f;) public void setFloat (float f) (this.f = f;) public int getInt () ( return i;) public void setInt (int i) (this.i = i;) public String getString () (return str;) public void setString (String str) (this.str = str;))

/ / SimpleObjectService.java

/ / Service program package com.whcyit.axis; public class SimpleObjectService (public String sayHello (String name) (return "Hello" + name +"!";) public String getString (SimpleObject obj) (System.out.println ( " SimpleObjectService getString invoked! "); return" return by serviced: "+ obj.getString ();) public SimpleObject createSimpleObject (int i, float f, String str) (System.out.println (" SimpleObjectService createSimpleObject invoked! "); SimpleObject so = new SimpleObject (); so.setInt (i); so.setFloat (f); so.setString (str); return so;))

/ / SimpleObjectClient.java

/ / Call the document the client package com.whcyit.axis; import javax.xml.namespace.QName; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis . encoding.ser.BeanDeserializerFactory; import org.apache.axis.encoding.ser.BeanSerializerFactory; public class SimpleObjectClient (/ ** * @ param args * / public static void main (String [] args) (String ret = ""; try (String wsdlUrl = "http://localhost:8080/axis/services/SimpleObjectService?wsdl"; String nameSpaceUri = "http://localhost:8080/axis/services/SimpleObjectService"; / / String wsdlUrl = "http: / / 10.68.19.24:8080 / sample / services / SimpleObjectService? wsdl "; / / String nameSpaceUri =" http://10.68.19.24:8080/sample/services/SimpleObjectService "; / / create a call object Service service = new Service (); Call call = null; call = (Call) service.createCall (); / / registration serial SimpleObject type QName qn = new QName ( "urn: BeanService", "SimpleObject"); call.registerTypeMapping (SimpleObject. class, qn, new BeanSerializerFactory (SimpleObject.class, qn), new BeanDeserializerFactory (SimpleObject.class, qn)); / / call the sayHello System.out.println (">>> sayHello "); call.setOperationName (new QName ( nameSpaceUri, "sayHello")); call.setTargetEndpointAddress (new java.net.URL (wsdlUrl)); ret = (String) call.invoke (new Object [] ( "liu2")); System.out.println ( " return value is "+ ret); / / call getDesc System.out.println (">>> getString"); SimpleObject so = new SimpleObject (); so.setString ( "hello!"); QName getDescQn = new QName ( nameSpaceUri, "getString"); call.setOperationName (getDescQn); call.setTargetEndpointAddress (new java.net.URL (wsdlUrl)); ret = (String) call.invoke (new Object [] (so)); System.out . println ( "return value is" + ret); / / call createSimpleObject System.out.println (">>> createSimpleObject "); QName getObjectQn = new QName (nameSpaceUri," createSimpleObject "); call.setOperationName (getObjectQn); call.setTargetEndpointAddress (new java.net.URL (wsdlUrl)); SimpleObject rtnSO = (SimpleObject) call.invoke (new Object [] (new Integer (1), new Float (0.1f), "liu2")); system . out.println ( "return object" + rtnSO.getString ());) catch (Exception ex) (ex.printStackTrace ();)))

/ / server-config.wsdd

/ / Server configuration file <? xml version = "1.0" encoding = "UTF-8"?> <Deployment xmlns = "http://xml.apache.org/axis/wsdd/" xmlns: java = "http: / / xml.apache.org / axis / wsdd / providers / java "> <globalConfiguration> <parameter name="adminPassword" value="admin"/> <parameter name =" attachments.Directory "value =" C: \ eclipse \ workspace \ bookstore \ WEB-INF \ attachments "/> <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/> <parameter name =" sendXsiTypes "value =" true "/ > <parameter name="sendMultiRefs" value="true"/> <parameter name="sendXMLDeclaration" value="true"/> <parameter name="axis.sendMinimizedElements" value="true"/> <requestFlow> <handler type = "java: org.apache.axis.handlers.JWSHandler"> <parameter name="scope" value="session"/> </ handler> <handler type = "java: org.apache.axis.handlers.JWSHandler "> <parameter name="scope" value="request"/> <parameter name="extension" value=".jwr"/> </ handler> </ requestFlow> </ globalConfiguration> <handler name =" LocalResponder " type = "java: org.apache.axis.transport.local.LocalResponder" /> <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/> <handler name = "URLMapper" type = "java: org.apache.axis.handlers.http.URLMapper" /> <service name="Version" provider="java:RPC"> <parameter name="allowedMethods" value="getVersion"/> <parameter name = "className" value = "org.apache.axis.Version" /> </ service> <service name="SimpleObjectService" provider="java:RPC"> <parameter name = "allowedMethods" value ="*"/ > <parameter name="className" value="com.whcyit.axis.SimpleObjectService"/> <beanMapping languageSpecificType = "java: com.whcyit.axis.SimpleObject" qname = "ns: SimpleObject" xmlns: ns = "urn: BeanService "/> </ service> <service name="AdminService" provider="java:MSG"> <parameter name="allowedMethods" value="AdminService"/> <parameter name =" enableRemoteAdmin "value =" false "/ > <parameter name = "className" value = "org.a


Java and XML Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.