diff options
Diffstat (limited to 'java')
66 files changed, 3555 insertions, 3 deletions
diff --git a/java/allDemos.py b/java/allDemos.py index 955bd9cae40..6110b47efeb 100755 --- a/java/allDemos.py +++ b/java/allDemos.py @@ -33,6 +33,7 @@ demos = [ "Ice/minimal", "Ice/multicast", "Ice/nested", + "Ice/serialize", "Ice/session", "Ice/throughput", "Ice/value", diff --git a/java/allTests.py b/java/allTests.py index 8b89de12648..6a81d4e2bca 100755 --- a/java/allTests.py +++ b/java/allTests.py @@ -28,6 +28,7 @@ tests = [ ("IceUtil/inputUtil", ["once"]), ("Ice/proxy", ["core"]), ("Ice/operations", ["core"]), + ("Ice/seqMapping", ["core"]), ("Ice/exceptions", ["core"]), ("Ice/inheritance", ["core"]), ("Ice/facets", ["core"]), diff --git a/java/demo/Ice/build.xml b/java/demo/Ice/build.xml index a8f43061344..c101f7c9627 100644 --- a/java/demo/Ice/build.xml +++ b/java/demo/Ice/build.xml @@ -22,6 +22,7 @@ <ant dir="minimal"/> <ant dir="multicast"/> <ant dir="nested"/> + <ant dir="serialize"/> <ant dir="session"/> <ant dir="throughput"/> <ant dir="value"/> @@ -38,6 +39,7 @@ <ant dir="minimal" target="clean"/> <ant dir="multicast" target="clean"/> <ant dir="nested" target="clean"/> + <ant dir="serialize" target="clean"/> <ant dir="session" target="clean"/> <ant dir="throughput" target="clean"/> <ant dir="value" target="clean"/> diff --git a/java/demo/Ice/protobuf/Client.java b/java/demo/Ice/protobuf/Client.java new file mode 100644 index 00000000000..cbdbb7aca2b --- /dev/null +++ b/java/demo/Ice/protobuf/Client.java @@ -0,0 +1,127 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Demo.*; + +public class Client extends Ice.Application +{ + class ShutdownHook extends Thread + { + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + + private static void + menu() + { + System.out.println( + "usage:\n" + + "t: send greeting\n" + + "s: shutdown server\n" + + "x: exit\n" + + "?: help\n"); + } + + public int + run(String[] args) + { + if(args.length > 0) + { + System.err.println(appName() + ": too many arguments"); + return 1; + } + + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + + HelloPrx hello = HelloPrxHelper.checkedCast(communicator().propertyToProxy("Hello.Proxy")); + if(hello == null) + { + System.err.println("invalid proxy"); + return 1; + } + + tutorial.PersonPB.Person p = tutorial.PersonPB.Person.newBuilder(). + setId(1).setName("Fred Jones").setEmail("fred@jones.com").build(); + + menu(); + + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + + String line = null; + do + { + try + { + System.out.print("==> "); + System.out.flush(); + line = in.readLine(); + if(line == null) + { + break; + } + if(line.equals("t")) + { + hello.sayHello(p); + } + else if(line.equals("s")) + { + hello.shutdown(); + } + else if(line.equals("x")) + { + // Nothing to do + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!line.equals("x")); + + return 0; + } + + public static void + main(String[] args) + { + Client app = new Client(); + int status = app.main("Client", args, "config.client"); + System.exit(status); + } +} + diff --git a/java/demo/Ice/protobuf/Hello.ice b/java/demo/Ice/protobuf/Hello.ice new file mode 100644 index 00000000000..8ddbbbd34ae --- /dev/null +++ b/java/demo/Ice/protobuf/Hello.ice @@ -0,0 +1,27 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef HELLO_ICE +#define HELLO_ICE + +module Demo +{ + +["cpp:protobuf:tutorial::Person", "java:protobuf:tutorial.PersonPB.Person", "python:protobuf:Person_pb2.Person"] +sequence<byte> Person; + +interface Hello +{ + idempotent void sayHello(Person p); + void shutdown(); +}; + +}; + +#endif diff --git a/java/demo/Ice/protobuf/HelloI.java b/java/demo/Ice/protobuf/HelloI.java new file mode 100644 index 00000000000..e3fcf7008bb --- /dev/null +++ b/java/demo/Ice/protobuf/HelloI.java @@ -0,0 +1,26 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Demo.*; + +public class HelloI extends _HelloDisp +{ + public void + sayHello(tutorial.PersonPB.Person p, Ice.Current current) + { + System.out.println("Hello World from " + p); + } + + public void + shutdown(Ice.Current current) + { + System.out.println("Shutting down..."); + current.adapter.getCommunicator().shutdown(); + } +} diff --git a/java/demo/Ice/protobuf/Person.proto b/java/demo/Ice/protobuf/Person.proto new file mode 100644 index 00000000000..6ee58a3f246 --- /dev/null +++ b/java/demo/Ice/protobuf/Person.proto @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package tutorial; + +option java_outer_classname = "PersonPB"; + +message Person { + required int32 id = 1; + required string name = 2; + optional string email = 3; +} diff --git a/java/demo/Ice/protobuf/README b/java/demo/Ice/protobuf/README new file mode 100644 index 00000000000..a431af0e734 --- /dev/null +++ b/java/demo/Ice/protobuf/README @@ -0,0 +1,41 @@ +This demo shows how to integrate Google Protocol Buffers with Ice. + +The Protocol Buffers distribution and documentation can be found at + + http://code.google.com/apis/protocolbuffers/ + +This demo was tested with Protocol Buffers version 2.0.2. + +We have added new metadata that makes it possible for you to specify +protocol buffers message types in your Slice definitions, with Ice +handling the serialization chores for you automatically. The metadata, +which may only be used on a sequence<byte> type, has the following +syntax in Java: + + java:protobuf:protoc-generated-class + +For example: + + ["java:protobuf:tutorial.PersonPB.Person"] sequence<byte> Person; + +The type name specified in this example, tutorial.PersonPB.Person, +corresponds to the Java class generated by the Protocol Buffers +compiler (protoc) for the definition shown below: + + package tutorial; + option java_outer_classname = "PersonPB"; + message Person { ... }; + +This demo uses an ant build task, located in the "ant" subdirectory, +for compiling .proto files. + +Prior to building the demo, you should add protoc to your PATH and +protobuf-java-2.0.2 to your CLASSPATH. + +To run the demo, first start the server: + + $ java Server + +In a separate window, start the client: + + $ java Client diff --git a/java/demo/Ice/protobuf/Server.java b/java/demo/Ice/protobuf/Server.java new file mode 100644 index 00000000000..6ffab5d02fb --- /dev/null +++ b/java/demo/Ice/protobuf/Server.java @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Demo.*; + +public class Server extends Ice.Application +{ + public int + run(String[] args) + { + if(args.length > 0) + { + System.err.println(appName() + ": too many arguments"); + return 1; + } + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello"); + adapter.add(new HelloI(), communicator().stringToIdentity("hello")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + Server app = new Server(); + int status = app.main("Server", args, "config.server"); + System.exit(status); + } +} diff --git a/java/demo/Ice/protobuf/ant/ProtocTask.java b/java/demo/Ice/protobuf/ant/ProtocTask.java new file mode 100644 index 00000000000..ba981a27db0 --- /dev/null +++ b/java/demo/Ice/protobuf/ant/ProtocTask.java @@ -0,0 +1,367 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +//package Ice.Ant; + +import org.apache.tools.ant.Task; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.taskdefs.ExecTask; +import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.PumpStreamHandler; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Commandline.Argument; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Reference; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.StringReader; +import java.io.BufferedReader; +import java.io.BufferedWriter; + +/** + * An ant task for protoc. + * + * Attributes specific to protoc: + * + * translator - The pathname of the translator (default: "protoc"). + * protocpath - The value for the --proto_path translator option. + * outputdir - The value for the --java_out translator option. + * dependencyfile - The file in which dependencies are stored (default: ".pbdepend"). + * + * Example: + * + * <project ...> + * <taskdef name="protoc" classname="ProtocTask" /> + * <property name="protoc.dir" value="../include/protoc"/> + * <target name="generate"> + * <mkdir dir="tags" /> + * <protoc tagdir="tags" outputdir="out"> + * <fileset dir="${protoc.dir}"> + * <include name="*.ice" /> + * </fileset> + * </protoc> + * </target> + * </project> + * + * The <taskdef> element installs the protoctask task. + */ +public class ProtocTask extends org.apache.tools.ant.Task +{ + public + ProtocTask() + { + _translator = null; + _outputDir = null; + _protocPath = null; + _outputDirString = null; + } + + public void + setDependencyFile(File file) + { + _dependencyFile = file; + } + + public void + setOutputdir(File dir) + { + _outputDir = dir; + _outputDirString = _outputDir.toString(); + if(_outputDirString.indexOf(' ') != -1) + { + _outputDirString = '"' + _outputDirString + '"'; + } + } + + public void + setProtocpath(File dir) + { + _protocPath = dir.toString(); + } + + public void + setTranslator(File prog) + { + _translator = prog; + } + + public FileSet + createFileset() + { + FileSet fileset = new FileSet(); + _fileSets.add(fileset); + + return fileset; + } + + public void + execute() + throws BuildException + { + if(_fileSets.isEmpty()) + { + throw new BuildException("No fileset specified"); + } + + // + // Read the set of dependencies for this task. + // + java.util.HashMap dependencies = readDependencies(); + + // + // Compose a list of the files that need to be translated. A + // file needs to translated if we can't find a dependency in + // the dependency table or if its dependency is not up-to-date + // anymore (the proto file changed since the dependency was + // last updated) + // + java.util.Vector buildList = new java.util.Vector(); + java.util.Vector skipList = new java.util.Vector(); + java.util.Iterator p = _fileSets.iterator(); + while(p.hasNext()) + { + FileSet fileset = (FileSet)p.next(); + + DirectoryScanner scanner = fileset.getDirectoryScanner(getProject()); + scanner.scan(); + String[] files = scanner.getIncludedFiles(); + for(int i = 0; i < files.length; i++) + { + File proto = new File(fileset.getDir(getProject()), files[i]); + + ProtoDependency depend = (ProtoDependency)dependencies.get(getTargetKey(proto.toString())); + if(depend == null || !depend.isUpToDate()) + { + buildList.addElement(proto); + } + else + { + skipList.addElement(proto); + } + } + + java.util.Iterator i = skipList.iterator(); + while(i.hasNext()) + { + File file = (File)i.next(); + log("skipping " + file.getName()); + } + } + + // + // Run the translator + // + if(!buildList.isEmpty()) + { + String translator; + if(_translator == null) + { + translator = "protoc"; + } + else + { + translator = _translator.toString(); + } + + StringBuffer cmd = new StringBuffer(); + + // + // Add --java_out. + // + if(_outputDir != null) + { + cmd.append(" --java_out="); + cmd.append(stripDriveLetter(_outputDirString)); + } + + // + // Add --proto_path + // + if(_protocPath != null) + { + cmd.append(" --proto_path="); + cmd.append(stripDriveLetter(_protocPath)); + } + + // + // Add files to be translated + // + for(int i = 0; i < buildList.size(); i++) + { + File f = (File)buildList.elementAt(i); + cmd.append(" "); + String s = stripDriveLetter(f.toString()); + if(s.indexOf(' ') != -1) + { + cmd.append('"' + s + '"'); + } + else + { + cmd.append(s); + } + } + + // + // Execute + // + log(translator + " " + cmd); + ExecTask task = (ExecTask)getProject().createTask("exec"); + task.setFailonerror(true); + Argument arg = task.createArg(); + arg.setLine(cmd.toString()); + task.setExecutable(translator); + task.execute(); + + // + // Update dependency file. + // + for(int i = 0; i < buildList.size(); i++) + { + ProtoDependency depend = new ProtoDependency(); + depend._timeStamp = new java.util.Date().getTime(); + depend._dependency = ((File)buildList.elementAt(i)).toString(); + dependencies.put(getTargetKey(depend._dependency), depend); + } + + writeDependencies(dependencies); + } + } + + private String + getTargetKey(String proto) + { + // + // Since the dependency file can be shared by several proto + // tasks we need to make sure that each dependency has a + // unique key. We use the name of the task, the output + // directory and the name of the proto file to be compiled. + // + // If there's two protoc tasks using the same dependency + // file, with the same output dir and which compiles the same + // protoc file they'll use the same dependency. + // + return "protoc " + _outputDir.toString() + " " + proto; + } + + // This is to work around a bug with protoc, where it does not + // accept drive letters in path names. See + // http://bugzilla/bugzilla/show_bug.cgi?id=3349 + // + private String + stripDriveLetter(String s) + { + if(s.length() > 1 && s.charAt(1) == ':') + { + return s.substring(2); + } + return s; + } + + // + // Read the dependency file. + // + private java.util.HashMap + readDependencies() + { + if(_dependencyFile == null) + { + if(_outputDir != null) + { + _dependencyFile = new File(_outputDir, ".pbdepend"); + } + else + { + _dependencyFile = new File(".pbdepend"); + } + } + + try + { + java.io.ObjectInputStream in = new java.io.ObjectInputStream(new java.io.FileInputStream(_dependencyFile)); + java.util.HashMap dependencies = (java.util.HashMap)in.readObject(); + in.close(); + return dependencies; + } + catch(java.io.IOException ex) + { + } + catch(java.lang.ClassNotFoundException ex) + { + } + + return new java.util.HashMap(); + } + + private void + writeDependencies(java.util.HashMap dependencies) + { + try + { + java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(new FileOutputStream(_dependencyFile)); + out.writeObject(dependencies); + out.close(); + } + catch(java.io.IOException ex) + { + throw new BuildException("Unable to write dependencies in file " + _dependencyFile.getPath() + ": " + ex); + } + } + + // + // A proto dependency. + // + // * the _timeStamp attribute contains the last time the proto + // file was compiled. + // + // * the _dependency attribute contains the .proto file. + // + private class ProtoDependency implements java.io.Serializable + { + private void writeObject(java.io.ObjectOutputStream out) + throws java.io.IOException + { + out.writeObject(_dependency); + out.writeLong(_timeStamp); + } + + private void readObject(java.io.ObjectInputStream in) + throws java.io.IOException, java.lang.ClassNotFoundException + { + _dependency = (String)in.readObject(); + _timeStamp = in.readLong(); + } + + public boolean + isUpToDate() + { + File dep = new File(_dependency); + if(!dep.exists() || _timeStamp < dep.lastModified()) + { + return false; + } + + return true; + } + + public String _dependency; + public long _timeStamp; + } + + private File _translator; + private File _dependencyFile; + private File _outputDir; + private String _outputDirString; + private String _protocPath; + private java.util.List _fileSets = new java.util.LinkedList(); +} diff --git a/java/demo/Ice/protobuf/build.xml b/java/demo/Ice/protobuf/build.xml new file mode 100644 index 00000000000..aa336420300 --- /dev/null +++ b/java/demo/Ice/protobuf/build.xml @@ -0,0 +1,63 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. + + This copy of Ice is licensed to you under the terms described in the + ICE_LICENSE file included in this distribution. + + ********************************************************************** +--> + +<project name="demo_Ice_protobuf" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- import common definitions --> + <import file="${top.dir}/config/common.xml"/> + + <target name="protoc" depends="init"> + <!-- Build protoc task --> + <mkdir dir="${class.dir}"/> + <javac srcdir="ant" destdir="${class.dir}" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + </target> + + <target name="generate" depends="protoc"> + <!-- Add the protoc task --> + <taskdef name="protoc" classpath="${class.dir}" classname="ProtocTask" /> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <meta value="${java2metadata}"/> + <fileset dir="." includes="Hello.ice"/> + </slice2java> + <protoc outputdir="${generated.dir}" protocpath="."> + <fileset dir="." includes="Person.proto"/> + </protoc> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + debug="${debug}"> + <classpath refid="ice.classpath"/> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" + excludes="generated/**, ant/**" debug="${debug}"> + <classpath refid="ice.classpath"/> + <compilerarg value="${javac.lint}"/> + </javac> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> diff --git a/java/demo/Ice/protobuf/config.client b/java/demo/Ice/protobuf/config.client new file mode 100644 index 00000000000..a02cab0f4cb --- /dev/null +++ b/java/demo/Ice/protobuf/config.client @@ -0,0 +1,23 @@ +# +# The client reads this property to create the reference to the +# "hello" object in the server. +# +Hello.Proxy=hello:tcp -p 10000 + +# +# Network Tracing +# +# 0 = no network tracing +# 1 = trace connection establishment and closure +# 2 = like 1, but more detailed +# 3 = like 2, but also trace data transfer +# +#Ice.Trace.Network=1 + +# +# Protocol Tracing +# +# 0 = no protocol tracing +# 1 = trace protocol messages +# +#Ice.Trace.Protocol=1 diff --git a/java/demo/Ice/protobuf/config.server b/java/demo/Ice/protobuf/config.server new file mode 100644 index 00000000000..309db9731b2 --- /dev/null +++ b/java/demo/Ice/protobuf/config.server @@ -0,0 +1,24 @@ +# +# The server creates one single object adapter with the name +# "Hello". The following line sets the endpoints for this +# adapter. +# +Hello.Endpoints=tcp -p 10000 + +# +# Network Tracing +# +# 0 = no network tracing +# 1 = trace connection establishment and closure +# 2 = like 1, but more detailed +# 3 = like 2, but also trace data transfer +# +#Ice.Trace.Network=1 + +# +# Protocol Tracing +# +# 0 = no protocol tracing +# 1 = trace protocol messages +# +#Ice.Trace.Protocol=1 diff --git a/java/demo/Ice/serialize/Client.java b/java/demo/Ice/serialize/Client.java new file mode 100644 index 00000000000..e5c6ce82fb0 --- /dev/null +++ b/java/demo/Ice/serialize/Client.java @@ -0,0 +1,142 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Demo.*; + +public class Client extends Ice.Application +{ + class ShutdownHook extends Thread + { + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + + private static void + menu() + { + System.out.println( + "usage:\n" + + "g: send greeting\n" + + "t: toggle null greeting\n" + + "s: shutdown server\n" + + "x: exit\n" + + "?: help\n"); + } + + public int + run(String[] args) + { + if(args.length > 0) + { + System.err.println(appName() + ": too many arguments"); + return 1; + } + + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + + GreetPrx greet = GreetPrxHelper.checkedCast(communicator().propertyToProxy("Greet.Proxy")); + if(greet == null) { + + System.err.println("invalid proxy"); + return 1; + } + + MyGreeting greeting = new MyGreeting(); + greeting.text = "Hello there!"; + MyGreeting nullGreeting = null; + + boolean sendNull = false; + + menu(); + + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + + String line = null; + do + { + try + { + System.out.print("==> "); + System.out.flush(); + line = in.readLine(); + if(line == null) + { + break; + } + if(line.equals("g")) + { + if(sendNull) + { + greet.sendGreeting(nullGreeting); + } + else + { + greet.sendGreeting(greeting); + } + } + else if(line.equals("t")) + { + sendNull = !sendNull; + } + else if(line.equals("s")) + { + greet.shutdown(); + } + else if(line.equals("x")) + { + // Nothing to do + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!line.equals("x")); + + return 0; + } + + public static void + main(String[] args) + { + Client app = new Client(); + int status = app.main("Client", args, "config.client"); + System.exit(status); + } +} + diff --git a/java/demo/Ice/serialize/Demo/MyGreeting.java b/java/demo/Ice/serialize/Demo/MyGreeting.java new file mode 100644 index 00000000000..bbefc3e687b --- /dev/null +++ b/java/demo/Ice/serialize/Demo/MyGreeting.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Demo; + +public class MyGreeting implements java.io.Serializable +{ + public String text; +} diff --git a/java/demo/Ice/serialize/Greet.ice b/java/demo/Ice/serialize/Greet.ice new file mode 100644 index 00000000000..e06d9d04f6d --- /dev/null +++ b/java/demo/Ice/serialize/Greet.ice @@ -0,0 +1,26 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef GREET_ICE +#define GREET_ICE + +module Demo +{ + +["java:serializable:Demo.MyGreeting"] sequence<byte> Greeting; + +interface Greet +{ + idempotent void sendGreeting(Greeting g); + void shutdown(); +}; + +}; + +#endif diff --git a/java/demo/Ice/serialize/GreetI.java b/java/demo/Ice/serialize/GreetI.java new file mode 100644 index 00000000000..855af5173f5 --- /dev/null +++ b/java/demo/Ice/serialize/GreetI.java @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Demo.*; + +public class GreetI extends _GreetDisp +{ + public void + sendGreeting(MyGreeting greeting, Ice.Current current) + { + if(greeting != null) + { + System.out.println(greeting.text); + } + else + { + System.out.println("Received null greeting"); + } + } + + public void + shutdown(Ice.Current current) + { + System.out.println("Shutting down..."); + current.adapter.getCommunicator().shutdown(); + } +} diff --git a/java/demo/Ice/serialize/README b/java/demo/Ice/serialize/README new file mode 100644 index 00000000000..b6e3828c445 --- /dev/null +++ b/java/demo/Ice/serialize/README @@ -0,0 +1,36 @@ +This demo illustrates how to transfer serializable Java classes +with Ice. + +The Java classes are transferred as byte sequences by Ice. It was +always possible to do this, but it would have required that you +explicitly serialize your class into a byte sequence and then pass +that sequence to your operations. Through the use of Slice metadata, +Ice now makes this much more convenient to accomplish. + +In your Slice definitions you must declare a byte sequence using the +"java:serializable" metadata and specify the Java class name, as shown +below: + +["java:serializable:JavaClassName"] sequence<byte> SliceType; + +Now, wherever you use the declared Slice type in your operations, you +will be able to supply an instance of the designated Java class and +Ice will automatically convert it to and from the byte sequence that +is passed over the wire. + +With the "java:serializable" metadata, if you have a serializable +class as an out-parameter, the our-parameter is passed as +Ice.Holder<JavaClassName>. For example, if you have a java class +MyPackage.Car as an out-parameter, the out-parameter is passed as +Ice.Holder<MyPackage.Car>. + +To run the demo, first start the server: + +$ java Server + +In a separate window, start the client: + +$ java Client + +The client allows you to toggle between sending a real class instance +and sending a null value, to show that passing null is supported. diff --git a/java/demo/Ice/serialize/Server.java b/java/demo/Ice/serialize/Server.java new file mode 100644 index 00000000000..6550ea79a6d --- /dev/null +++ b/java/demo/Ice/serialize/Server.java @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Demo.*; + +public class Server extends Ice.Application +{ + public int + run(String[] args) + { + if(args.length > 0) + { + System.err.println(appName() + ": too many arguments"); + return 1; + } + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Greet"); + adapter.add(new GreetI(), communicator().stringToIdentity("greet")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + Server app = new Server(); + int status = app.main("Server", args, "config.server"); + System.exit(status); + } +} diff --git a/java/demo/Ice/serialize/build.xml b/java/demo/Ice/serialize/build.xml new file mode 100644 index 00000000000..96b3470fb12 --- /dev/null +++ b/java/demo/Ice/serialize/build.xml @@ -0,0 +1,52 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. + + This copy of Ice is licensed to you under the terms described in the + ICE_LICENSE file included in this distribution. + + ********************************************************************** +--> + +<project name="demo_Ice_serialize" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- import common definitions --> + <import file="${top.dir}/config/common.xml"/> + + <target name="generate" depends="init"> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <meta value="${java2metadata}"/> + <fileset dir="." includes="Greet.ice"/> + </slice2java> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="." destdir="${class.dir}" includes="Demo/**" debug="${debug}"> + <classpath refid="ice.classpath"/> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="${generated.dir}" destdir="${class.dir}" debug="${debug}"> + <classpath refid="ice.classpath"/> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" excludes="generated/**,Serialize/**" debug="${debug}"> + <classpath refid="ice.classpath"/> + <compilerarg value="${javac.lint}"/> + </javac> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> diff --git a/java/demo/Ice/serialize/config.client b/java/demo/Ice/serialize/config.client new file mode 100644 index 00000000000..f0cff951933 --- /dev/null +++ b/java/demo/Ice/serialize/config.client @@ -0,0 +1,36 @@ +# +# The client reads this property to create the reference to the +# "greet" object in the server. +# +Greet.Proxy=greet:tcp -p 10000 + +# +# Warn about connection exceptions. +# +Ice.Warn.Connections=1 + +# +# Client-side ACM is enabled by default, with an interval of 60 +# seconds. For this demo, we want to use a short timeout of 10 +# seconds. By enabling network tracing below, you can see ACM +# automatically close idle connections. +# +Ice.ACM.Client=10 + +# +# Network Tracing +# +# 0 = no network tracing +# 1 = trace connection establishment and closure +# 2 = like 1, but more detailed +# 3 = like 2, but also trace data transfer +# +#Ice.Trace.Network=1 + +# +# Protocol Tracing +# +# 0 = no protocol tracing +# 1 = trace protocol messages +# +#Ice.Trace.Protocol=1 diff --git a/java/demo/Ice/serialize/config.server b/java/demo/Ice/serialize/config.server new file mode 100644 index 00000000000..a2227d3a224 --- /dev/null +++ b/java/demo/Ice/serialize/config.server @@ -0,0 +1,37 @@ +# +# The server creates one single object adapter with the name +# "Greet". The following line sets the endpoints for this +# adapter. +# +Greet.Endpoints=tcp -p 10000 + +# +# Warn about connection exceptions. +# +Ice.Warn.Connections=1 + +# +# Server-side ACM is disabled by default. For this demo, we want it +# enabled and set to a short timeout of 10 seconds. By enabling +# network tracing below, you can see ACM automatically close idle +# connections. +# +Ice.ACM.Server=10 + +# +# Network Tracing +# +# 0 = no network tracing +# 1 = trace connection establishment and closure +# 2 = like 1, but more detailed +# 3 = like 2, but also trace data transfer +# +#Ice.Trace.Network=1 + +# +# Protocol Tracing +# +# 0 = no protocol tracing +# 1 = trace protocol messages +# +#Ice.Trace.Protocol=1 diff --git a/java/src/Ice/InputStream.java b/java/src/Ice/InputStream.java index da108992b7b..9028cad551d 100644 --- a/java/src/Ice/InputStream.java +++ b/java/src/Ice/InputStream.java @@ -21,6 +21,8 @@ public interface InputStream byte readByte(); byte[] readByteSeq(); + java.io.Serializable readSerializable(); + short readShort(); short[] readShortSeq(); diff --git a/java/src/Ice/InputStreamI.java b/java/src/Ice/InputStreamI.java index a5f970e54d4..9ee2c868b4a 100644 --- a/java/src/Ice/InputStreamI.java +++ b/java/src/Ice/InputStreamI.java @@ -61,6 +61,12 @@ public class InputStreamI implements InputStream return _is.readByteSeq(); } + public java.io.Serializable + readSerializable() + { + return _is.readSerializable(); + } + public short readShort() { diff --git a/java/src/Ice/OutputStream.java b/java/src/Ice/OutputStream.java index d481187c89d..4105fbc94b6 100644 --- a/java/src/Ice/OutputStream.java +++ b/java/src/Ice/OutputStream.java @@ -19,6 +19,8 @@ public interface OutputStream void writeByte(byte v); void writeByteSeq(byte[] v); + void writeSerializable(java.io.Serializable o); + void writeShort(short v); void writeShortSeq(short[] v); diff --git a/java/src/Ice/OutputStreamI.java b/java/src/Ice/OutputStreamI.java index 39130ee350a..934f8047e85 100644 --- a/java/src/Ice/OutputStreamI.java +++ b/java/src/Ice/OutputStreamI.java @@ -56,6 +56,12 @@ public class OutputStreamI implements OutputStream } public void + writeSerializable(java.io.Serializable v) + { + _os.writeSerializable(v); + } + + public void writeShort(short v) { _os.writeShort(v); diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java index 10c9b8a25f7..659995acc2a 100644 --- a/java/src/IceInternal/BasicStream.java +++ b/java/src/IceInternal/BasicStream.java @@ -692,6 +692,28 @@ public class BasicStream } } + public void + writeSerializable(java.io.Serializable o) + { + if(o == null) + { + writeSize(0); + return; + } + try + { + OutputStreamWrapper w = new OutputStreamWrapper(this); + java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(w); + out.writeObject(o); + out.close(); + w.close(); + } + catch(java.lang.Exception ex) + { + throw new Ice.MarshalException("cannot serialize object: " + ex); + } + } + public byte readByte() { @@ -733,6 +755,27 @@ public class BasicStream } } + public java.io.Serializable + readSerializable() + { + int sz = readSize(); + if (sz == 0) + { + return null; + } + checkFixedSeq(sz, 1); + try + { + InputStreamWrapper w = new InputStreamWrapper(sz, this); + java.io.ObjectInputStream in = new java.io.ObjectInputStream(w); + return (java.io.Serializable)in.readObject(); + } + catch(java.lang.Exception ex) + { + throw new Ice.MarshalException("cannot deserialize object: " + ex); + } + } + public void writeBool(boolean v) { @@ -2056,7 +2099,7 @@ public class BasicStream return ucStream; } - private void + public void expand(int n) { if(!_unlimited && _buf.b != null && _buf.b.position() + n > _messageSizeMax) diff --git a/java/src/IceInternal/InputStreamWrapper.java b/java/src/IceInternal/InputStreamWrapper.java new file mode 100644 index 00000000000..aa12dda716c --- /dev/null +++ b/java/src/IceInternal/InputStreamWrapper.java @@ -0,0 +1,94 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package IceInternal; + +import java.io.*; + +// +// Class to provide a java.io.InputStream on top of a BasicStream. +// We use this to deserialize arbitrary Java serializable classes from +// a Slice byte sequence. This class is a wrapper around a BasicStream +// that passes all methods through. +// + +public class InputStreamWrapper extends java.io.InputStream +{ + public + InputStreamWrapper(int size, BasicStream s) + { + _s = s; + _markPos = 0; + } + + public int + read() throws IOException + { + try + { + return _s.getBuffer().b.get(); + } + catch(java.lang.Exception ex) + { + throw new IOException(ex.toString()); + } + } + + public int + read(byte[] b) throws IOException + { + return read(b, 0, b.length); + } + + public int + read(byte[] b, int offset, int count) throws IOException + { + try + { + _s.getBuffer().b.get(b, offset, count); + } + catch(java.lang.Exception ex) + { + throw new IOException(ex.toString()); + } + return count; + } + + public int + available() + { + return _s.getBuffer().b.remaining(); + } + + public void + mark(int readlimit) + { + _markPos = _s.pos(); + } + + public void + reset() throws IOException + { + _s.pos(_markPos); + } + + public boolean + markSupported() + { + return true; + } + + public void + close() throws IOException + { + } + + private BasicStream _s; + private int _markPos; +} diff --git a/java/src/IceInternal/OutputStreamWrapper.java b/java/src/IceInternal/OutputStreamWrapper.java new file mode 100644 index 00000000000..471eef7358c --- /dev/null +++ b/java/src/IceInternal/OutputStreamWrapper.java @@ -0,0 +1,173 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package IceInternal; + +import java.io.*; + +// +// Class to provide a java.io.OutputStream on top of a BasicStream. +// We use this to serialize arbitrary Java serializable classes into +// +// Slice sequences are encoded on the wire as a count of elements, followed +// by the sequence contents. For arbitrary Java classes, we do not know how +// big the sequence that is eventually written will be. To avoid excessive +// data copying, this class mantains a private _bytes array of 254 bytes and, +// initially, writes data into that array. If more than 254 bytes end up being +// written, we write a dummy sequence size of 255 (which occupies five bytes +// on the wire) into the BasicStream and, once this stream is closed, patch +// that size to match the actual size. Otherwise, if the _bytes buffer contains +// fewer than 255 bytes when this stream is closed, we write the sequence size +// as a single byte, followed by the contents of the _bytes buffer. +// + +public class OutputStreamWrapper extends java.io.OutputStream +{ + public + OutputStreamWrapper(BasicStream s) + { + _s = s; + _spos = s.pos(); + _bytes = new byte[254]; + _pos = 0; + } + + public void + write(int b) throws IOException + { + try + { + if(_bytes != null) + { + // + // If we can fit the data into the first 254 bytes, write it to _bytes. + // + if(_pos < _bytes.length) + { + _bytes[_pos++] = (byte)b; + return; + } + + _s.writeSize(255); // Dummy size, until we know how big the stream + // really is and can patch the size. + + if(_pos > 0) + { + // + // Write the current contents of _bytes. + // + _s.expand(_pos); + _s.getBuffer().b.put(_bytes, 0, _pos); + } + _bytes = null; + } + + // + // Write data passed by caller. + // + _s.expand(1); + _s.getBuffer().b.put((byte)b); + _pos += 1; + } + catch(java.lang.Exception ex) + { + throw new IOException(ex.toString()); + } + } + + public void + write(byte[] b) throws IOException + { + write(b, 0, b.length); + } + + public void + write(byte[] bytes, int offset, int count) throws IOException + { + try + { + if(_bytes != null) + { + // + // If we can fit the data into the first 254 bytes, write it to _bytes. + // + if(count <= _bytes.length - _pos) + { + System.arraycopy(bytes, offset, _bytes, _pos, count); + _pos += count; + return; + } + + _s.writeSize(255); // Dummy size, until we know how big the stream + // really is and can patch the size. + + if(_pos > 0) + { + // + // Write the current contents of _bytes. + // + _s.expand(_pos); + _s.getBuffer().b.put(_bytes, 0, _pos); + } + _bytes = null; + } + + // + // Write data passed by caller. + // + _s.expand(count); + _s.getBuffer().b.put(bytes, offset, count); + _pos += count; + } + catch(java.lang.Exception ex) + { + throw new IOException(ex.toString()); + } + } + + public void + flush() throws IOException + { + // This does nothing because we do not know the final size of a writable stream until it is closed, + // and we cannot write to the BasicStream until we know whether the final size is < 255 or not. + } + + public void + close() throws IOException + { + try + { + if(_bytes != null) + { + assert(_pos <= _bytes.length); + _s.pos(_spos); + _s.writeSize(_pos); + _s.expand(_pos); + _s.getBuffer().b.put(_bytes, 0, _pos); + _bytes = null; + } + else + { + int currentPos = _s.pos(); + _s.pos(_spos); + _s.writeSize(_pos); // Patch previously-written dummy value. + _s.pos(currentPos); + } + } + catch(java.lang.Exception ex) + { + throw new IOException(ex.toString()); + } + } + + private BasicStream _s; + private int _spos; + private byte[] _bytes; + private int _pos; +} diff --git a/java/test/Ice/build.xml b/java/test/Ice/build.xml index af5f5fb57bb..52b188936eb 100644 --- a/java/test/Ice/build.xml +++ b/java/test/Ice/build.xml @@ -27,6 +27,8 @@ <ant dir="proxyAMD"/> <ant dir="operations"/> <ant dir="operationsAMD"/> + <ant dir="seqMapping"/> + <ant dir="seqMappingAMD"/> <ant dir="slicing"/> <ant dir="custom"/> <ant dir="translator"/> @@ -57,6 +59,8 @@ <ant dir="proxyAMD" target="clean"/> <ant dir="operations" target="clean"/> <ant dir="operationsAMD" target="clean"/> + <ant dir="seqMapping" target="clean"/> + <ant dir="seqMappingAMD" target="clean"/> <ant dir="slicing" target="clean"/> <ant dir="custom" target="clean"/> <ant dir="translator" target="clean"/> diff --git a/java/test/Ice/protobuf/AllTests.java b/java/test/Ice/protobuf/AllTests.java new file mode 100644 index 00000000000..a5ce93d0fca --- /dev/null +++ b/java/test/Ice/protobuf/AllTests.java @@ -0,0 +1,162 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class AllTests +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + private static class Callback + { + Callback() + { + _called = false; + } + + public synchronized boolean + check() + { + while(!_called) + { + try + { + wait(5000); + } + catch(InterruptedException ex) + { + continue; + } + + if(!_called) + { + return false; // Must be timeout. + } + } + + _called = false; + return true; + } + + public synchronized void + called() + { + assert(!_called); + _called = true; + notify(); + } + + private boolean _called; + } + + private static class AMI_MyClass_opMessage extends Test.AMI_MyClass_opMessage + { + public void + ice_response(test.TestPB.Message r, test.TestPB.Message o) + { + test(o.getI() == 99); + test(r.getI() == 99); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(false); + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + private static class AMI_MyClass_opMessageAMD extends Test.AMI_MyClass_opMessageAMD + { + public void + ice_response(test.TestPB.Message r, test.TestPB.Message o) + { + test(o.getI() == 99); + test(r.getI() == 99); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(false); + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + public static Test.MyClassPrx + allTests(Ice.Communicator communicator, boolean collocated) + { + String ref = "test:default -p 12010 -t 10000"; + Ice.ObjectPrx baseProxy = communicator.stringToProxy(ref); + Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(baseProxy); + + System.out.print("testing twoway operations... "); + { + test.TestPB.Message i = test.TestPB.Message.newBuilder().setI(99).build(); + Ice.Holder<test.TestPB.Message> o = new Ice.Holder<test.TestPB.Message>(); + test.TestPB.Message r; + + r = cl.opMessage(i, o); + + test(o.value.getI() == 99); + test(r.getI() == 99); + } + { + test.TestPB.Message i = test.TestPB.Message.newBuilder().setI(99).build(); + Ice.Holder<test.TestPB.Message> o = new Ice.Holder<test.TestPB.Message>(); + test.TestPB.Message r; + + r = cl.opMessageAMD(i, o); + + test(o.value.getI() == 99); + test(r.getI() == 99); + } + System.out.println("ok"); + + System.out.print("testing twoway AMI operations... "); + { + test.TestPB.Message i = test.TestPB.Message.newBuilder().setI(99).build(); + + AMI_MyClass_opMessage cb = new AMI_MyClass_opMessage(); + cl.opMessage_async(cb, i); + test(cb.check()); + } + { + test.TestPB.Message i = test.TestPB.Message.newBuilder().setI(99).build(); + + AMI_MyClass_opMessageAMD cb = new AMI_MyClass_opMessageAMD(); + cl.opMessageAMD_async(cb, i); + test(cb.check()); + } + System.out.println("ok"); + + return cl; + } +} diff --git a/java/test/Ice/protobuf/Client.java b/java/test/Ice/protobuf/Client.java new file mode 100644 index 00000000000..9381242aacf --- /dev/null +++ b/java/test/Ice/protobuf/Client.java @@ -0,0 +1,53 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Client +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + Test.MyClassPrx myClass = AllTests.allTests(communicator, false); + myClass.shutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/protobuf/Collocated.java b/java/test/Ice/protobuf/Collocated.java new file mode 100644 index 00000000000..64843c27243 --- /dev/null +++ b/java/test/Ice/protobuf/Collocated.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Collocated +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new MyClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + AllTests.allTests(communicator, true); + + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.exit(status); + } +} diff --git a/java/test/Ice/protobuf/MyClassI.java b/java/test/Ice/protobuf/MyClassI.java new file mode 100644 index 00000000000..29e637d532b --- /dev/null +++ b/java/test/Ice/protobuf/MyClassI.java @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public final class MyClassI extends Test.MyClass +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public void + shutdown(Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + } + + public test.TestPB.Message opMessage(test.TestPB.Message i, Ice.Holder<test.TestPB.Message> o, Ice.Current current) + { + o.value = i; + return i; + } + + public void opMessageAMD_async(Test.AMD_MyClass_opMessageAMD amdCB, test.TestPB.Message i, Ice.Current current) + { + amdCB.ice_response(i, i); + } +} diff --git a/java/test/Ice/protobuf/Server.java b/java/test/Ice/protobuf/Server.java new file mode 100644 index 00000000000..e77a401ddca --- /dev/null +++ b/java/test/Ice/protobuf/Server.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Server +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new MyClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/protobuf/Test.ice b/java/test/Ice/protobuf/Test.ice new file mode 100644 index 00000000000..f30fca97b31 --- /dev/null +++ b/java/test/Ice/protobuf/Test.ice @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +module Test +{ + +["java:protobuf:test.TestPB.Message"] sequence<byte> Message; + +["ami"] class MyClass +{ + void shutdown(); + + Message opMessage(Message i, out Message o); + + ["amd"] Message opMessageAMD(Message i, out Message o); +}; + +// Remaining type definitions are there to verify that the generated +// code compiles correctly. + +sequence<Message> SLS; +sequence<SLS> SLSS; +dictionary<int, Message> SLD; +dictionary<int, SLS> SLSD; +struct Foo +{ + Message SLmem; + SLS SLSmem; +}; + +exception Bar +{ + Message SLmem; + SLS SLSmem; +}; + +class Baz +{ + Message SLmem; + SLS SLSmem; +}; + +}; + +#endif diff --git a/java/test/Ice/protobuf/Test.proto b/java/test/Ice/protobuf/Test.proto new file mode 100644 index 00000000000..fea4c801ddd --- /dev/null +++ b/java/test/Ice/protobuf/Test.proto @@ -0,0 +1,16 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package test; + +option java_outer_classname = "TestPB"; + +message Message { + required int32 i = 1; +} diff --git a/java/test/Ice/protobuf/ant/ProtocTask.java b/java/test/Ice/protobuf/ant/ProtocTask.java new file mode 100644 index 00000000000..ba981a27db0 --- /dev/null +++ b/java/test/Ice/protobuf/ant/ProtocTask.java @@ -0,0 +1,367 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +//package Ice.Ant; + +import org.apache.tools.ant.Task; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.taskdefs.ExecTask; +import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.PumpStreamHandler; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Commandline.Argument; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Reference; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.StringReader; +import java.io.BufferedReader; +import java.io.BufferedWriter; + +/** + * An ant task for protoc. + * + * Attributes specific to protoc: + * + * translator - The pathname of the translator (default: "protoc"). + * protocpath - The value for the --proto_path translator option. + * outputdir - The value for the --java_out translator option. + * dependencyfile - The file in which dependencies are stored (default: ".pbdepend"). + * + * Example: + * + * <project ...> + * <taskdef name="protoc" classname="ProtocTask" /> + * <property name="protoc.dir" value="../include/protoc"/> + * <target name="generate"> + * <mkdir dir="tags" /> + * <protoc tagdir="tags" outputdir="out"> + * <fileset dir="${protoc.dir}"> + * <include name="*.ice" /> + * </fileset> + * </protoc> + * </target> + * </project> + * + * The <taskdef> element installs the protoctask task. + */ +public class ProtocTask extends org.apache.tools.ant.Task +{ + public + ProtocTask() + { + _translator = null; + _outputDir = null; + _protocPath = null; + _outputDirString = null; + } + + public void + setDependencyFile(File file) + { + _dependencyFile = file; + } + + public void + setOutputdir(File dir) + { + _outputDir = dir; + _outputDirString = _outputDir.toString(); + if(_outputDirString.indexOf(' ') != -1) + { + _outputDirString = '"' + _outputDirString + '"'; + } + } + + public void + setProtocpath(File dir) + { + _protocPath = dir.toString(); + } + + public void + setTranslator(File prog) + { + _translator = prog; + } + + public FileSet + createFileset() + { + FileSet fileset = new FileSet(); + _fileSets.add(fileset); + + return fileset; + } + + public void + execute() + throws BuildException + { + if(_fileSets.isEmpty()) + { + throw new BuildException("No fileset specified"); + } + + // + // Read the set of dependencies for this task. + // + java.util.HashMap dependencies = readDependencies(); + + // + // Compose a list of the files that need to be translated. A + // file needs to translated if we can't find a dependency in + // the dependency table or if its dependency is not up-to-date + // anymore (the proto file changed since the dependency was + // last updated) + // + java.util.Vector buildList = new java.util.Vector(); + java.util.Vector skipList = new java.util.Vector(); + java.util.Iterator p = _fileSets.iterator(); + while(p.hasNext()) + { + FileSet fileset = (FileSet)p.next(); + + DirectoryScanner scanner = fileset.getDirectoryScanner(getProject()); + scanner.scan(); + String[] files = scanner.getIncludedFiles(); + for(int i = 0; i < files.length; i++) + { + File proto = new File(fileset.getDir(getProject()), files[i]); + + ProtoDependency depend = (ProtoDependency)dependencies.get(getTargetKey(proto.toString())); + if(depend == null || !depend.isUpToDate()) + { + buildList.addElement(proto); + } + else + { + skipList.addElement(proto); + } + } + + java.util.Iterator i = skipList.iterator(); + while(i.hasNext()) + { + File file = (File)i.next(); + log("skipping " + file.getName()); + } + } + + // + // Run the translator + // + if(!buildList.isEmpty()) + { + String translator; + if(_translator == null) + { + translator = "protoc"; + } + else + { + translator = _translator.toString(); + } + + StringBuffer cmd = new StringBuffer(); + + // + // Add --java_out. + // + if(_outputDir != null) + { + cmd.append(" --java_out="); + cmd.append(stripDriveLetter(_outputDirString)); + } + + // + // Add --proto_path + // + if(_protocPath != null) + { + cmd.append(" --proto_path="); + cmd.append(stripDriveLetter(_protocPath)); + } + + // + // Add files to be translated + // + for(int i = 0; i < buildList.size(); i++) + { + File f = (File)buildList.elementAt(i); + cmd.append(" "); + String s = stripDriveLetter(f.toString()); + if(s.indexOf(' ') != -1) + { + cmd.append('"' + s + '"'); + } + else + { + cmd.append(s); + } + } + + // + // Execute + // + log(translator + " " + cmd); + ExecTask task = (ExecTask)getProject().createTask("exec"); + task.setFailonerror(true); + Argument arg = task.createArg(); + arg.setLine(cmd.toString()); + task.setExecutable(translator); + task.execute(); + + // + // Update dependency file. + // + for(int i = 0; i < buildList.size(); i++) + { + ProtoDependency depend = new ProtoDependency(); + depend._timeStamp = new java.util.Date().getTime(); + depend._dependency = ((File)buildList.elementAt(i)).toString(); + dependencies.put(getTargetKey(depend._dependency), depend); + } + + writeDependencies(dependencies); + } + } + + private String + getTargetKey(String proto) + { + // + // Since the dependency file can be shared by several proto + // tasks we need to make sure that each dependency has a + // unique key. We use the name of the task, the output + // directory and the name of the proto file to be compiled. + // + // If there's two protoc tasks using the same dependency + // file, with the same output dir and which compiles the same + // protoc file they'll use the same dependency. + // + return "protoc " + _outputDir.toString() + " " + proto; + } + + // This is to work around a bug with protoc, where it does not + // accept drive letters in path names. See + // http://bugzilla/bugzilla/show_bug.cgi?id=3349 + // + private String + stripDriveLetter(String s) + { + if(s.length() > 1 && s.charAt(1) == ':') + { + return s.substring(2); + } + return s; + } + + // + // Read the dependency file. + // + private java.util.HashMap + readDependencies() + { + if(_dependencyFile == null) + { + if(_outputDir != null) + { + _dependencyFile = new File(_outputDir, ".pbdepend"); + } + else + { + _dependencyFile = new File(".pbdepend"); + } + } + + try + { + java.io.ObjectInputStream in = new java.io.ObjectInputStream(new java.io.FileInputStream(_dependencyFile)); + java.util.HashMap dependencies = (java.util.HashMap)in.readObject(); + in.close(); + return dependencies; + } + catch(java.io.IOException ex) + { + } + catch(java.lang.ClassNotFoundException ex) + { + } + + return new java.util.HashMap(); + } + + private void + writeDependencies(java.util.HashMap dependencies) + { + try + { + java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(new FileOutputStream(_dependencyFile)); + out.writeObject(dependencies); + out.close(); + } + catch(java.io.IOException ex) + { + throw new BuildException("Unable to write dependencies in file " + _dependencyFile.getPath() + ": " + ex); + } + } + + // + // A proto dependency. + // + // * the _timeStamp attribute contains the last time the proto + // file was compiled. + // + // * the _dependency attribute contains the .proto file. + // + private class ProtoDependency implements java.io.Serializable + { + private void writeObject(java.io.ObjectOutputStream out) + throws java.io.IOException + { + out.writeObject(_dependency); + out.writeLong(_timeStamp); + } + + private void readObject(java.io.ObjectInputStream in) + throws java.io.IOException, java.lang.ClassNotFoundException + { + _dependency = (String)in.readObject(); + _timeStamp = in.readLong(); + } + + public boolean + isUpToDate() + { + File dep = new File(_dependency); + if(!dep.exists() || _timeStamp < dep.lastModified()) + { + return false; + } + + return true; + } + + public String _dependency; + public long _timeStamp; + } + + private File _translator; + private File _dependencyFile; + private File _outputDir; + private String _outputDirString; + private String _protocPath; + private java.util.List _fileSets = new java.util.LinkedList(); +} diff --git a/java/test/Ice/protobuf/build.xml b/java/test/Ice/protobuf/build.xml new file mode 100644 index 00000000000..8e992925cee --- /dev/null +++ b/java/test/Ice/protobuf/build.xml @@ -0,0 +1,68 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. + + This copy of Ice is licensed to you under the terms described in the + ICE_LICENSE file included in this distribution. + + ********************************************************************** +--> + +<project name="test_Ice_seqMapping" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- import common definitions --> + <import file="${top.dir}/config/common.xml"/> + + <target name="protoc" depends="init"> + <!-- Build protoc task --> + <mkdir dir="${class.dir}"/> + <javac srcdir="ant" destdir="${class.dir}" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + </target> + + <target name="generate" depends="protoc"> + <!-- Add the protoc task --> + <taskdef name="protoc" classpath="${class.dir}" classname="ProtocTask" /> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <meta value="${java2metadata}"/> + <fileset dir="." includes="Test.ice"/> + <includepath> + <pathelement path="${slice.dir}" /> + </includepath> + </slice2java> + <protoc outputdir="${generated.dir}" protocpath="."> + <fileset dir="." includes="Test.proto"/> + </protoc> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="." destdir="${class.dir}" includes="Serialize/**" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" + classpathref="ice.classpath" excludes="generated/**,Serialize/**" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> diff --git a/java/test/Ice/protobuf/run.py b/java/test/Ice/protobuf/run.py new file mode 100755 index 00000000000..70bca77e564 --- /dev/null +++ b/java/test/Ice/protobuf/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +TestUtil.clientServerTest() + diff --git a/java/test/Ice/seqMapping/AllTests.java b/java/test/Ice/seqMapping/AllTests.java new file mode 100644 index 00000000000..e95f38943cc --- /dev/null +++ b/java/test/Ice/seqMapping/AllTests.java @@ -0,0 +1,34 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class AllTests +{ + public static Test.MyClassPrx + allTests(Ice.Communicator communicator, boolean collocated) + { + String ref = "test:default -p 12010 -t 10000"; + Ice.ObjectPrx baseProxy = communicator.stringToProxy(ref); + Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(baseProxy); + + System.out.print("testing twoway operations... "); + System.out.flush(); + Twoways.twoways(communicator, cl); + System.out.println("ok"); + + if(!collocated) + { + System.out.print("testing twoway operations with AMI... "); + System.out.flush(); + TwowaysAMI.twowaysAMI(communicator, cl); + System.out.println("ok"); + } + + return cl; + } +} diff --git a/java/test/Ice/seqMapping/Client.java b/java/test/Ice/seqMapping/Client.java new file mode 100644 index 00000000000..dff52ec6dd6 --- /dev/null +++ b/java/test/Ice/seqMapping/Client.java @@ -0,0 +1,58 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Client +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + Test.MyClassPrx myClass = AllTests.allTests(communicator, false); + + System.out.print("shutting down server... "); + System.out.flush(); + myClass.shutdown(); + System.out.println("ok"); + + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/seqMapping/Collocated.java b/java/test/Ice/seqMapping/Collocated.java new file mode 100644 index 00000000000..64843c27243 --- /dev/null +++ b/java/test/Ice/seqMapping/Collocated.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Collocated +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new MyClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + AllTests.allTests(communicator, true); + + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.exit(status); + } +} diff --git a/java/test/Ice/seqMapping/MyClassI.java b/java/test/Ice/seqMapping/MyClassI.java new file mode 100644 index 00000000000..5622e7415d2 --- /dev/null +++ b/java/test/Ice/seqMapping/MyClassI.java @@ -0,0 +1,44 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public final class MyClassI extends Test.MyClass +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public void + shutdown(Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + } + + public Serialize.Small opSerialSmallJava(Serialize.Small i, Ice.Holder<Serialize.Small> o, Ice.Current current) + { + o.value = i; + return i; + } + + public Serialize.Large opSerialLargeJava(Serialize.Large i, Ice.Holder<Serialize.Large> o, Ice.Current current) + { + o.value = i; + return i; + } + + public Serialize.Struct opSerialStructJava(Serialize.Struct i, Ice.Holder<Serialize.Struct> o, Ice.Current current) + { + o.value = i; + return i; + } +} diff --git a/java/test/Ice/seqMapping/Serialize/Large.java b/java/test/Ice/seqMapping/Serialize/Large.java new file mode 100644 index 00000000000..188bbe59fac --- /dev/null +++ b/java/test/Ice/seqMapping/Serialize/Large.java @@ -0,0 +1,24 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Serialize; + +public class Large implements java.io.Serializable // More than 254 bytes when serialized. +{ + public double d1; + public double d2; + public double d3; + public double d4; + public double d5; + public double d6; + public double d7; + public double d8; + public double d9; + public double d10; +} diff --git a/java/test/Ice/seqMapping/Serialize/Small.java b/java/test/Ice/seqMapping/Serialize/Small.java new file mode 100644 index 00000000000..be92e68edea --- /dev/null +++ b/java/test/Ice/seqMapping/Serialize/Small.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Serialize; + +public class Small implements java.io.Serializable // Fewer than 254 bytes when serialized. +{ + public int i; +} diff --git a/java/test/Ice/seqMapping/Serialize/Struct.java b/java/test/Ice/seqMapping/Serialize/Struct.java new file mode 100644 index 00000000000..c40d95b3c75 --- /dev/null +++ b/java/test/Ice/seqMapping/Serialize/Struct.java @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Serialize; + +public class Struct implements java.io.Serializable // Used to test that null members marshal correctly. +{ + public Object o; + public Object o2; + public String s; + public String s2; +} diff --git a/java/test/Ice/seqMapping/Server.java b/java/test/Ice/seqMapping/Server.java new file mode 100644 index 00000000000..e77a401ddca --- /dev/null +++ b/java/test/Ice/seqMapping/Server.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Server +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new MyClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/seqMapping/Test.ice b/java/test/Ice/seqMapping/Test.ice new file mode 100644 index 00000000000..3ffe3a4140b --- /dev/null +++ b/java/test/Ice/seqMapping/Test.ice @@ -0,0 +1,56 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +module Test +{ + +["java:serializable:Serialize.Small"] sequence<byte> SerialSmall; +["java:serializable:Serialize.Large"] sequence<byte> SerialLarge; +["java:serializable:Serialize.Struct"] sequence<byte> SerialStruct; + +["ami"] class MyClass +{ + void shutdown(); + + SerialSmall opSerialSmallJava(SerialSmall i, out SerialSmall o); + SerialLarge opSerialLargeJava(SerialLarge i, out SerialLarge o); + SerialStruct opSerialStructJava(SerialStruct i, out SerialStruct o); +}; + +// Remaining type definitions are there to verify that the generated +// code compiles correctly. + +sequence<SerialLarge> SLS; +sequence<SLS> SLSS; +dictionary<int, SerialLarge> SLD; +dictionary<int, SLS> SLSD; +struct Foo +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +exception Bar +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +class Baz +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +}; + +#endif diff --git a/java/test/Ice/seqMapping/Twoways.java b/java/test/Ice/seqMapping/Twoways.java new file mode 100644 index 00000000000..4e88edaa74d --- /dev/null +++ b/java/test/Ice/seqMapping/Twoways.java @@ -0,0 +1,132 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +class Twoways +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + static void + twoways(Ice.Communicator communicator, Test.MyClassPrx p) + { + { + Serialize.Small i = null; + Ice.Holder<Serialize.Small> o = new Ice.Holder<Serialize.Small>(); + Serialize.Small r; + + r = p.opSerialSmallJava(i, o); + + test(o.value == null); + test(r == null); + } + + { + Serialize.Small i = new Serialize.Small(); + i.i = 99; + Ice.Holder<Serialize.Small> o = new Ice.Holder<Serialize.Small>(); + Serialize.Small r; + + try + { + r = p.opSerialSmallJava(i, o); + + test(o.value.i == 99); + test(r.i == 99); + } + catch(Ice.OperationNotExistException ex) + { + // OK, talking to non-Java server. + } + } + + { + Serialize.Large i = new Serialize.Large(); + i.d1 = 1.0; + i.d2 = 2.0; + i.d3 = 3.0; + i.d4 = 4.0; + i.d5 = 5.0; + i.d6 = 6.0; + i.d7 = 7.0; + i.d8 = 8.0; + i.d9 = 9.0; + i.d10 = 10.0; + Ice.Holder<Serialize.Large> o = new Ice.Holder<Serialize.Large>(); + Serialize.Large r; + + try + { + r = p.opSerialLargeJava(i, o); + + test(o.value.d1 == 1.0); + test(o.value.d2 == 2.0); + test(o.value.d3 == 3.0); + test(o.value.d4 == 4.0); + test(o.value.d5 == 5.0); + test(o.value.d6 == 6.0); + test(o.value.d7 == 7.0); + test(o.value.d8 == 8.0); + test(o.value.d9 == 9.0); + test(o.value.d10 == 10.0); + test(r.d1 == 1.0); + test(r.d2 == 2.0); + test(r.d3 == 3.0); + test(r.d4 == 4.0); + test(r.d5 == 5.0); + test(r.d6 == 6.0); + test(r.d7 == 7.0); + test(r.d8 == 8.0); + test(r.d9 == 9.0); + test(r.d10 == 10.0); + } + catch(Ice.OperationNotExistException ex) + { + // OK, talking to non-Java server. + } + } + + { + Serialize.Struct i = new Serialize.Struct(); + i.o = null; + i.o2 = i; + i.s = null; + i.s2 = "Hello"; + Ice.Holder<Serialize.Struct> o = new Ice.Holder<Serialize.Struct>(); + Serialize.Struct r; + + try + { + r = p.opSerialStructJava(i, o); + + test(o.value.o == null); + test(o.value.o2 != null); + test(((Serialize.Struct)(o.value.o2)).o == null); + test(((Serialize.Struct)(o.value.o2)).o2 == o.value.o2); + test(o.value.s == null); + test(o.value.s2.equals("Hello")); + test(r.o == null); + test(r.o2 != null); + test(((Serialize.Struct)(r.o2)).o == null); + test(((Serialize.Struct)(r.o2)).o2 == r.o2); + test(r.s == null); + test(r.s2.equals("Hello")); + } + catch(Ice.OperationNotExistException ex) + { + // OK, talking to non-Java server. + } + } + } +} diff --git a/java/test/Ice/seqMapping/TwowaysAMI.java b/java/test/Ice/seqMapping/TwowaysAMI.java new file mode 100644 index 00000000000..ca3af245cb5 --- /dev/null +++ b/java/test/Ice/seqMapping/TwowaysAMI.java @@ -0,0 +1,241 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +class TwowaysAMI +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + private static class Callback + { + Callback() + { + _called = false; + } + + public synchronized boolean + check() + { + while(!_called) + { + try + { + wait(5000); + } + catch(InterruptedException ex) + { + continue; + } + + if(!_called) + { + return false; // Must be timeout. + } + } + + _called = false; + return true; + } + + public synchronized void + called() + { + assert(!_called); + _called = true; + notify(); + } + + private boolean _called; + } + + private static class AMI_MyClass_opSerialSmallJavaNull extends Test.AMI_MyClass_opSerialSmallJava + { + public void + ice_response(Serialize.Small r, Serialize.Small o) + { + test(o == null); + test(r == null); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(ex instanceof Ice.OperationNotExistException); // OK, talking to non-Java server. + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + private static class AMI_MyClass_opSerialSmallJava extends Test.AMI_MyClass_opSerialSmallJava + { + public void + ice_response(Serialize.Small r, Serialize.Small o) + { + test(o.i == 99); + test(r.i == 99); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(ex instanceof Ice.OperationNotExistException); // OK, talking to non-Java server. + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + private static class AMI_MyClass_opSerialLargeJava extends Test.AMI_MyClass_opSerialLargeJava + { + public void + ice_response(Serialize.Large r, Serialize.Large o) + { + test(o.d1 == 1.0); + test(o.d2 == 2.0); + test(o.d3 == 3.0); + test(o.d4 == 4.0); + test(o.d5 == 5.0); + test(o.d6 == 6.0); + test(o.d7 == 7.0); + test(o.d8 == 8.0); + test(o.d9 == 9.0); + test(o.d10 == 10.0); + test(r.d1 == 1.0); + test(r.d2 == 2.0); + test(r.d3 == 3.0); + test(r.d4 == 4.0); + test(r.d5 == 5.0); + test(r.d6 == 6.0); + test(r.d7 == 7.0); + test(r.d8 == 8.0); + test(r.d9 == 9.0); + test(r.d10 == 10.0); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(ex instanceof Ice.OperationNotExistException); // OK, talking to non-Java server. + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + private static class AMI_MyClass_opSerialStructJava extends Test.AMI_MyClass_opSerialStructJava + { + public void + ice_response(Serialize.Struct r, Serialize.Struct o) + { + test(o.o == null); + test(o.o2 != null); + test(((Serialize.Struct)(o.o2)).o == null); + test(((Serialize.Struct)(o.o2)).o2 == o.o2); + test(o.s == null); + test(o.s2.equals("Hello")); + test(r.o == null); + test(r.o2 != null); + test(((Serialize.Struct)(r.o2)).o == null); + test(((Serialize.Struct)(r.o2)).o2 == r.o2); + test(r.s == null); + test(r.s2.equals("Hello")); + callback.called(); + } + + public void + ice_exception(Ice.LocalException ex) + { + test(ex instanceof Ice.OperationNotExistException); // OK, talking to non-Java server. + } + + public boolean + check() + { + return callback.check(); + } + + private Callback callback = new Callback(); + } + + static void + twowaysAMI(Ice.Communicator communicator, Test.MyClassPrx p) + { + { + Serialize.Small i = null; + + AMI_MyClass_opSerialSmallJavaNull cb = new AMI_MyClass_opSerialSmallJavaNull(); + p.opSerialSmallJava_async(cb, i); + test(cb.check()); + } + + { + Serialize.Small i = new Serialize.Small(); + i.i = 99; + + AMI_MyClass_opSerialSmallJava cb = new AMI_MyClass_opSerialSmallJava(); + p.opSerialSmallJava_async(cb, i); + test(cb.check()); + } + + { + Serialize.Large i = new Serialize.Large(); + i.d1 = 1.0; + i.d2 = 2.0; + i.d3 = 3.0; + i.d4 = 4.0; + i.d5 = 5.0; + i.d6 = 6.0; + i.d7 = 7.0; + i.d8 = 8.0; + i.d9 = 9.0; + i.d10 = 10.0; + + AMI_MyClass_opSerialLargeJava cb = new AMI_MyClass_opSerialLargeJava(); + p.opSerialLargeJava_async(cb, i); + test(cb.check()); + } + + { + Serialize.Struct i = new Serialize.Struct(); + i.o = null; + i.o2 = i; + i.s = null; + i.s2 = "Hello"; + + AMI_MyClass_opSerialStructJava cb = new AMI_MyClass_opSerialStructJava(); + p.opSerialStructJava_async(cb, i); + test(cb.check()); + } + } +} diff --git a/java/test/Ice/seqMapping/build.xml b/java/test/Ice/seqMapping/build.xml new file mode 100644 index 00000000000..a12392802de --- /dev/null +++ b/java/test/Ice/seqMapping/build.xml @@ -0,0 +1,55 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. + + This copy of Ice is licensed to you under the terms described in the + ICE_LICENSE file included in this distribution. + + ********************************************************************** +--> + +<project name="test_Ice_seqMapping" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- import common definitions --> + <import file="${top.dir}/config/common.xml"/> + + <target name="generate" depends="init"> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <meta value="${java2metadata}"/> + <fileset dir="." includes="Test.ice"/> + <includepath> + <pathelement path="${slice.dir}" /> + </includepath> + </slice2java> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="." destdir="${class.dir}" includes="Serialize/**" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" + classpathref="ice.classpath" excludes="generated/**,Serialize/**" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> diff --git a/java/test/Ice/seqMapping/run.py b/java/test/Ice/seqMapping/run.py new file mode 100755 index 00000000000..09d700b9f48 --- /dev/null +++ b/java/test/Ice/seqMapping/run.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +print "tests with regular server." +TestUtil.clientServerTest() + +print "tests with AMD server." +import copy +amdenv = copy.deepcopy(os.environ) +TestUtil.addClasspath(os.path.join(os.getcwd(), "..", "seqMappingAMD", "classes"), amdenv) +TestUtil.clientServerTest(serverenv = amdenv) + +print "tests with collocated server." +TestUtil.collocatedTest() diff --git a/java/test/Ice/seqMappingAMD/MyClassI.java b/java/test/Ice/seqMappingAMD/MyClassI.java new file mode 100644 index 00000000000..61bbde13d70 --- /dev/null +++ b/java/test/Ice/seqMappingAMD/MyClassI.java @@ -0,0 +1,42 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public final class MyClassI extends Test.MyClass +{ + public void + shutdown_async(Test.AMD_MyClass_shutdown cb, + Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + cb.ice_response(); + } + + public void + opSerialSmallJava_async(Test.AMD_MyClass_opSerialSmallJava cb, + Serialize.Small i, + Ice.Current current) + { + cb.ice_response(i, i); + } + + public void + opSerialLargeJava_async(Test.AMD_MyClass_opSerialLargeJava cb, + Serialize.Large i, + Ice.Current current) + { + cb.ice_response(i, i); + } + + public void opSerialStructJava_async(Test.AMD_MyClass_opSerialStructJava cb, + Serialize.Struct i, + Ice.Current current) + { + cb.ice_response(i, i); + } +} diff --git a/java/test/Ice/seqMappingAMD/Serialize/Large.java b/java/test/Ice/seqMappingAMD/Serialize/Large.java new file mode 100644 index 00000000000..188bbe59fac --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Serialize/Large.java @@ -0,0 +1,24 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Serialize; + +public class Large implements java.io.Serializable // More than 254 bytes when serialized. +{ + public double d1; + public double d2; + public double d3; + public double d4; + public double d5; + public double d6; + public double d7; + public double d8; + public double d9; + public double d10; +} diff --git a/java/test/Ice/seqMappingAMD/Serialize/Small.java b/java/test/Ice/seqMappingAMD/Serialize/Small.java new file mode 100644 index 00000000000..be92e68edea --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Serialize/Small.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Serialize; + +public class Small implements java.io.Serializable // Fewer than 254 bytes when serialized. +{ + public int i; +} diff --git a/java/test/Ice/seqMappingAMD/Serialize/SmallHolder.java b/java/test/Ice/seqMappingAMD/Serialize/SmallHolder.java new file mode 100644 index 00000000000..66776ade146 --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Serialize/SmallHolder.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Serialize; + +public class SmallHolder +{ + public Small value; +} diff --git a/java/test/Ice/seqMappingAMD/Serialize/Struct.java b/java/test/Ice/seqMappingAMD/Serialize/Struct.java new file mode 100644 index 00000000000..c40d95b3c75 --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Serialize/Struct.java @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Serialize; + +public class Struct implements java.io.Serializable // Used to test that null members marshal correctly. +{ + public Object o; + public Object o2; + public String s; + public String s2; +} diff --git a/java/test/Ice/seqMappingAMD/Serialize/StructHolder.java b/java/test/Ice/seqMappingAMD/Serialize/StructHolder.java new file mode 100644 index 00000000000..8bf50b75215 --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Serialize/StructHolder.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Serialize; + +public class StructHolder +{ + public Struct value; +} diff --git a/java/test/Ice/seqMappingAMD/Server.java b/java/test/Ice/seqMappingAMD/Server.java new file mode 100644 index 00000000000..ab531a55a60 --- /dev/null +++ b/java/test/Ice/seqMappingAMD/Server.java @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Server +{ + private static int + run(String[] args, Ice.Communicator communicator) + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000:udp"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new MyClassI(), communicator.stringToIdentity("test")); + adapter.activate(); + + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + communicator = Ice.Util.initialize(args); + status = run(args, communicator); + } + catch(Exception ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/seqMappingAMD/TestAMD.ice b/java/test/Ice/seqMappingAMD/TestAMD.ice new file mode 100644 index 00000000000..88a987c9eec --- /dev/null +++ b/java/test/Ice/seqMappingAMD/TestAMD.ice @@ -0,0 +1,56 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +module Test +{ + +["java:serializable:Serialize.Small"] sequence<byte> SerialSmall; +["java:serializable:Serialize.Large"] sequence<byte> SerialLarge; +["java:serializable:Serialize.Struct"] sequence<byte> SerialStruct; + +["ami", "amd"] class MyClass +{ + void shutdown(); + + SerialSmall opSerialSmallJava(SerialSmall i, out SerialSmall o); + SerialLarge opSerialLargeJava(SerialLarge i, out SerialLarge o); + SerialStruct opSerialStructJava(SerialStruct i, out SerialStruct o); +}; + +// Remaining type definitions are there to verify that the generated +// code compiles correctly. + +sequence<SerialLarge> SLS; +sequence<SLS> SLSS; +dictionary<int, SerialLarge> SLD; +dictionary<int, SLS> SLSD; +struct Foo +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +exception Bar +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +class Baz +{ + SerialLarge SLmem; + SLS SLSmem; +}; + +}; + +#endif diff --git a/java/test/Ice/seqMappingAMD/build.xml b/java/test/Ice/seqMappingAMD/build.xml new file mode 100644 index 00000000000..e98924112fc --- /dev/null +++ b/java/test/Ice/seqMappingAMD/build.xml @@ -0,0 +1,55 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. + + This copy of Ice is licensed to you under the terms described in the + ICE_LICENSE file included in this distribution. + + ********************************************************************** +--> + +<project name="test_Ice_seqMappingAMD" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- import common definitions --> + <import file="${top.dir}/config/common.xml"/> + + <target name="generate" depends="init"> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <meta value="${java2metadata}"/> + <fileset dir="." includes="TestAMD.ice"/> + <includepath> + <pathelement path="${slice.dir}" /> + </includepath> + </slice2java> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="." destdir="${class.dir}" includes="Serialize/**" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" + classpathref="ice.classpath" excludes="generated/**,Serialize/**" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> diff --git a/java/test/Ice/stream/Client.java b/java/test/Ice/stream/Client.java index 8c1993fc612..ebeb12378df 100644 --- a/java/test/Ice/stream/Client.java +++ b/java/test/Ice/stream/Client.java @@ -325,6 +325,19 @@ public class Client } { + Serialize.Small small = new Serialize.Small(); + small.i = 99; + out = Ice.Util.createOutputStream(communicator); + out.writeSerializable(small); + byte[] data = out.finished(); + in = Ice.Util.createInputStream(communicator, data); + Serialize.Small small2 = (Serialize.Small)in.readSerializable(); + test(small2.i == 99); + out.destroy(); + in.destroy(); + } + + { final short[] arr = { (short)0x01, diff --git a/java/test/Ice/stream/Serialize/Small.java b/java/test/Ice/stream/Serialize/Small.java new file mode 100644 index 00000000000..be92e68edea --- /dev/null +++ b/java/test/Ice/stream/Serialize/Small.java @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package Serialize; + +public class Small implements java.io.Serializable // Fewer than 254 bytes when serialized. +{ + public int i; +} diff --git a/java/test/Ice/stream/Test.ice b/java/test/Ice/stream/Test.ice index dafd2f02d41..03ac2d92dc3 100644 --- a/java/test/Ice/stream/Test.ice +++ b/java/test/Ice/stream/Test.ice @@ -22,6 +22,8 @@ enum MyEnum class MyClass; +["java:serializable:Serialize.Small"] sequence<byte> SerialSmall; + struct SmallStruct { bool bo; @@ -34,6 +36,7 @@ struct SmallStruct string str; MyEnum e; MyClass* p; + SerialSmall ss; }; sequence<bool> BoolS; diff --git a/java/test/Ice/stream/build.xml b/java/test/Ice/stream/build.xml index f3283a483ba..e719c890777 100644 --- a/java/test/Ice/stream/build.xml +++ b/java/test/Ice/stream/build.xml @@ -28,12 +28,16 @@ <target name="compile" depends="generate"> <mkdir dir="${class.dir}"/> + <javac srcdir="." destdir="${class.dir}" includes="Serialize/**" + classpathref="ice.classpath" debug="${debug}"> + <compilerarg value="${javac.lint}"/> + </javac> <javac srcdir="${generated.dir}" destdir="${class.dir}" classpathref="ice.classpath" debug="${debug}"> <compilerarg value="${javac.lint}"/> </javac> - <javac srcdir="." destdir="${class.dir}" - classpathref="ice.classpath" excludes="generated/**" debug="${debug}"> + <javac srcdir="." destdir="${class.dir}" excludes="${generated.dir}/** Serialize/**" + classpathref="ice.classpath" debug="${debug}"> <compilerarg value="${javac.lint}"/> </javac> </target> |