Colin Song wrote:
>> I want to transfer Object by webservice,and I want write a generic
>> webservice to transfer some difierent Objects.
>> So, I need to change Object to String and in webservice client return
>> to Object.
> Don't.
>
> It is rather pointless to spend a lot of CPU cycles and network
> bandwith to use a technology neutral format and then send a
> Java object that can only be understood by Java.
Stepping back one level, one sees a number of solutions to the general problem
of communicating information, including sometimes object models, between
heterogeneous systems. One popular solution is XML, albeit in multiple
incompatible formats. Depending on how multi-platform your user base is,
SOAP-based web services offer a reasonable solution to how to glue together a
service-oriented architecture (SOA). Even within the supposedly interoperable
world of SOAP-based web services over HTTP, there are nuances (XML-RPC vs.
document-literal) that can break compatibility, but at least there they're
fairly well documented.
Happily, Java lives very well with the world of SOAP-based web services, and
the two converge more and more all the time.
<http://java.sun.com/developer/technicalArticles/J2EE/intro_ee5/>
<http://java.sun.com/developer/technicalArticles/J2EE/intro_ee5/#support>

Signature
Lew
Andrew Thompson - 18 Dec 2007 04:21 GMT
>Colin Song wrote:
>>> I want to transfer Object by webservice,and I want write a generic
>>> webservice to transfer some difierent Objects.
(Arne)
>> Don't. ..
...
>Stepping back one level, ...
This thread has become a lot more interesting since the
arrival of Lew and Arne. I hope the OP is still reading it.

Signature
Andrew Thompson
http://www.physci.org/
Colin Song - 18 Dec 2007 04:43 GMT
Hi,all
I serialize Object to byte[] and then use base64 encode.It works well
now,I need more test on unix server(now I tested on my pc,win
XP).btw,the web service client and server both run on unix server and
writen by java.
Thanks for your help.
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class WSHelper {
static private BASE64Encoder encode = new BASE64Encoder();
static private BASE64Decoder decode = new BASE64Decoder();
static public String OToS(Object obj) {
long start=System.currentTimeMillis();
String out = null;
if (obj != null) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
out = encode.encode(baos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
long end=System.currentTimeMillis();
System.out.println("Encode:"+(end-start));
return out;
}
static public Object SToO(String str) {
long start=System.currentTimeMillis();
Object out = null;
if (str != null) {
try {
ByteArrayInputStream bios = new ByteArrayInputStream(decode
.decodeBuffer(str));
ObjectInputStream ois = new ObjectInputStream(bios);
out = ois.readObject();
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
long end=System.currentTimeMillis();
System.out.println("Decode:"+(end-start));
return out;
}
}
Colin Song - 18 Dec 2007 04:50 GMT
Hi,all
I serialize Object to byte[] and then use base64 encode.It works well
now,I need more test on unix server(now I tested on my pc,win
XP).btw,the web service client and server both run on unix server and
writen by java.
Thanks for your help.
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class WSHelper {
static private BASE64Encoder encode = new BASE64Encoder();
static private BASE64Decoder decode = new BASE64Decoder();
static public String OToS(Object obj) {
long start=System.currentTimeMillis();
String out = null;
if (obj != null) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
out = encode.encode(baos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
long end=System.currentTimeMillis();
System.out.println("Encode:"+(end-start));
return out;
}
static public Object SToO(String str) {
long start=System.currentTimeMillis();
Object out = null;
if (str != null) {
try {
ByteArrayInputStream bios = new ByteArrayInputStream(decode
.decodeBuffer(str));
ObjectInputStream ois = new ObjectInputStream(bios);
out = ois.readObject();
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
long end=System.currentTimeMillis();
System.out.println("Decode:"+(end-start));
return out;
}
}