cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r470011 - in /incubator/cxf/trunk: distribution/src/main/release/samples/handlers/ distribution/src/main/release/samples/handlers/src/demo/handlers/client/ distribution/src/main/release/samples/handlers/src/demo/handlers/common/ distributio...
Date Wed, 01 Nov 2006 17:46:39 GMT
Author: jliu
Date: Wed Nov  1 09:46:38 2006
New Revision: 470011

URL: http://svn.apache.org/viewvc?view=rev&rev=470011
Log:
Update handler demo and handler system test.

Added:
    incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/LoggingHandler.java
  (with props)
Modified:
    incubator/cxf/trunk/distribution/src/main/release/samples/handlers/README.txt
    incubator/cxf/trunk/distribution/src/main/release/samples/handlers/build.xml
    incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/client/Client.java
    incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/SmallNumberHandler.java
    incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/demo_handlers.xml
    incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/server/AddNumbersImpl.java
    incubator/cxf/trunk/distribution/src/main/release/samples/handlers/wsdl/addNumbers.wsdl
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers.xml
    incubator/cxf/trunk/testutils/src/main/resources/wsdl/addNumbers.wsdl

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/handlers/README.txt
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/handlers/README.txt?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/handlers/README.txt (original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/handlers/README.txt Wed Nov
 1 09:46:38 2006
@@ -9,22 +9,9 @@
 within the service implementation class. For this demo, LoggingHandler
 is SOAPHandler that logs the entire SOAP message content to stdout.
 
-While the annotation in the service implementation class specifies
-that the server should use the LoggingHandler, the demo shows how
-this behaviour is superceded by information obtained from the
-celtix-server.xml configuration file, thus allowing control over the
-server's behaviour without changing the code.  When the server process
-uses the configuration file, LoggingHandler is replaced with
-FileLoggingHandler, which logs simple informative messages, not the
-entire message content, to the console and adds information to the
-demo.log file.
-
 The client includes a logical handler that checks the parameters on
 outbound requests and short-circuits the invocation in certain
-circumstances. This handler is not specified programatically but
-through configuration in the file celtix-client.xml.  Alternatively,
-you can run the client without applying the configuration.
-In this case, the client does not instantiate a handler.
+circumstances. This handler is specified programatically.
 
 Please review the README in the samples directory before continuing.
 
@@ -52,12 +39,17 @@
   ant server 
   ant client
 
-When using these ant targets, the server process uses the FileLoggingHandler
+When using these ant targets, the server process uses the LoggingHandler
 and the client process uses the SmallNumberHandler.  Notice that the both
-the client and server consoles display short informative messages.  The server's
-handler also appends information to the file demo.log.  The client handler
-examines the operation parameters and, depending on the parameter values, may
-not forward the request to the server.
+the client and server consoles display short informative messages.  The 
+client handler examines the operation parameters and, depending on the 
+parameter values, may not forward the request to the server. The server 
+handler displays the entire content of each message in its console and
+the client no longer uses a handler.  The @HandlerChain annotation in the
+implementation class indicates that the file demo_handler.xml includes the
+information needed to identify the handler class.
+
+  @HandlerChain(file = "../common/demo_handlers.xml", name = "DemoHandlerChain")
 
 Look in the build.xml file to see how an argument to the java executable specifies
 use of the configuration file.  For example:
@@ -70,28 +62,6 @@
 
 After running the client, terminate the server process.
 
-Now run the server process using the LoggingHandler.
-
-Using either UNIX or Windows:
-
-  ant server2  (in the background or another window)
-  ant client2
-
-The ant targets client2 and server2 do not include the attribute that
-specifies the configuration file.  For example:
-
-  <target name="client2" description="run demo client" depends="build">
-    <celtixrun classname="demo.handlers.client.Client"
-               param1="${basedir}/wsdl/addNumbers.wsdl"/>
-  </target>
-
-Now, the server displays the entire content of each message in its console and
-the client no longer uses a handler.  The @HandlerChain annotation in the
-implementation class indicates that the file demo_handler.xml includes the
-information needed to identify the handler class.
-
-  @HandlerChain(file = "../common/demo_handlers.xml", name = "DemoHandlerChain")
-
 To remove the code generated from the WSDL file and the .class
 files, run:
 
@@ -144,50 +114,13 @@
 Running the demo using java
 ---------------------------
 
-Run the applications using the configuration information in the files
-celtix-server.xml and celtix-client.xml.  The server will use the FileLoggingHandler
-and the client will use the SmallNumberHandler.
-
-From the samples/handlers directory run the commands (entered on a single command line):
-
-For UNIX (must use forward slashes):
-    java -Djava.util.logging.config.file=$CELTIX_HOME/etc/logging.properties
-         -Dceltix.config.file=file:///$CELTIX_HOME/samples/handlers/celtix-server.xml
-         demo.handlers.server.Server &
-
-    java -Djava.util.logging.config.file=$CELTIX_HOME/etc/logging.properties
-         -Dceltix.config.file=file:///$CELTIX_HOME/samples/handlers/celtix-client.xml
-         demo.handlers.client.Client ./wsdl/addNumbers.wsdl
-
-The server process starts in the background.
-
-For Windows (may use either forward or back slashes):
-  start 
-    java -Djava.util.logging.config.file=%CELTIX_HOME%\etc\logging.properties
-         -Dceltix.config.file=file:///%CELTIX_HOME%\samples\handlers\celtix-server.xml
-         demo.handlers.server.Server
-
-    java -Djava.util.logging.config.file=%CELTIX_HOME%\etc\logging.properties
-         -Dceltix.config.file=file:///%CELTIX_HOME%\samples\handlers\celtix-client.xml
-         demo.handlers.client.Client .\wsdl\addNumbers.wsdl
-
-The server process starts in a new command window.
-
-Notice that the FileLoggingHandler, specified in the configuration file
-celtix-server.xml, logs information to the console and makes entries into
-the file demo.log, which is in the samples/handler directory.  Also, the
-SmallNumberHandler, specified in the configuration file celtix-client.xml,
-logs information to the console in which the client application runs.
-
-Now run the server process using the LoggingHandler.  The client does not use a handler.
-
 From the samples/handlers directory run the commands (entered on a single command line):
 
 For UNIX (must use forward slashes):
-    java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
+    java -Djava.util.logging.config.file=$CXF_HOME%/etc/logging.properties
          demo.handlers.server.Server &
 
-    java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
+    java -Djava.util.logging.config.file=$CXF_HOME%/etc/logging.properties
          demo.handlers.client.Client ./wsdl/addNumbers.wsdl
 
 The server process starts in the background.

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/handlers/build.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/handlers/build.xml?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/handlers/build.xml (original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/handlers/build.xml Wed Nov 
1 09:46:38 2006
@@ -29,14 +29,6 @@
         <cxfrun classname="demo.handlers.server.Server" param1="${basedir}/wsdl/addNumbers.wsdl"/>
     </target>
 
-    <target name="client2" description="run demo client with out handlers" depends="build">
-        <cxfrun classname="demo.handlers.client.Client" param1="${basedir}/wsdl/addNumbers.wsdl"/>
-    </target>
-
-    <target name="server2" description="run demo server with out handlers" depends="build">
-        <cxfrun classname="demo.handlers.server.Server" param1="${basedir}/wsdl/addNumbers.wsdl"/>
-    </target>
-
     <target name="generate.code">
         <echo level="info" message="Generating code using wsdl2java..."/>
         <wsdl2java file="addNumbers.wsdl"/>

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/client/Client.java?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/client/Client.java
(original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/client/Client.java
Wed Nov  1 09:46:38 2006
@@ -20,12 +20,19 @@
 package demo.handlers.client;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.xml.namespace.QName;
+
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.handler.Handler;
+
+import demo.handlers.common.SmallNumberHandler;
 import org.apache.handlers.AddNumbers;
 import org.apache.handlers.AddNumbersFault;
 import org.apache.handlers.AddNumbersService;
 
-
 public final class Client {
 
     static QName serviceName = new QName("http://apache.org/handlers",
@@ -48,16 +55,13 @@
         AddNumbersService service = new AddNumbersService(wsdl.toURL(), serviceName);
         AddNumbers port = (AddNumbers)service.getPort(portName, AddNumbers.class);
 
-        try {
-            String number1 = "10";
-            System.out.printf("Invoking addNumbers\n");
-            port.addNumbers(number1);
-            System.out.printf("Invoking addNumbers done\n");
-            //System.out.printf("The result of adding %d and %d is %d.\n\n", number1, number2,
result);
-
-            //Comment below out as int type doesnt work. see jira 136
+        //Add client side handlers programmatically
+        SmallNumberHandler sh = new SmallNumberHandler();
+        List<Handler> newHandlerChain = new ArrayList<Handler>();
+        newHandlerChain.add(sh);
+        ((BindingProvider)port).getBinding().setHandlerChain(newHandlerChain);
 
-/*
+        try {
             int number1 = 10;
             int number2 = 20;
 
@@ -76,7 +80,7 @@
             System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
             result = port.addNumbers(number1, number2);
             System.out.printf("The result of adding %d and %d is %d.\n", number1, number2,
result);
-*/
+
         } catch (AddNumbersFault ex) {
             System.out.printf("Caught AddNumbersFault: %s\n", ex.getFaultInfo().getMessage());
         }

Added: incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/LoggingHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/LoggingHandler.java?view=auto&rev=470011
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/LoggingHandler.java
(added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/LoggingHandler.java
Wed Nov  1 09:46:38 2006
@@ -0,0 +1,104 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package demo.handlers.common;
+
+
+import java.io.PrintStream;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+/*
+ * This simple SOAPHandler will output the contents of incoming
+ * and outgoing messages.
+ */
+public class LoggingHandler implements SOAPHandler<SOAPMessageContext> {
+
+    private PrintStream out;
+
+    public LoggingHandler() {
+        setLogStream(System.out);
+    }
+
+    protected final void setLogStream(PrintStream ps) {
+        out = ps;
+    }
+
+    public void init(Map c) {
+        System.out.println("LoggingHandler : init() Called....");
+    }
+
+    public Set<QName> getHeaders() {
+        return null;
+    }
+
+    public boolean handleMessage(SOAPMessageContext smc) {
+        System.out.println("LoggingHandler : handleMessage Called....");
+        logToSystemOut(smc);
+        return true;
+    }
+
+    public boolean handleFault(SOAPMessageContext smc) {
+        System.out.println("LoggingHandler : handleFault Called....");
+        logToSystemOut(smc);
+        return true;
+    }
+
+    // nothing to clean up
+    public void close(MessageContext messageContext) {
+        System.out.println("LoggingHandler : close() Called....");
+    }
+
+    // nothing to clean up
+    public void destroy() {
+        System.out.println("LoggingHandler : destroy() Called....");
+    }
+
+    /*
+     * Check the MESSAGE_OUTBOUND_PROPERTY in the context
+     * to see if this is an outgoing or incoming message.
+     * Write a brief message to the print stream and
+     * output the message. The writeTo() method can throw
+     * SOAPException or IOException
+     */
+    protected void logToSystemOut(SOAPMessageContext smc) {
+        Boolean outboundProperty = (Boolean)
+            smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+
+        if (outboundProperty.booleanValue()) {
+            out.println("\nOutbound message:");
+        } else {
+            out.println("\nInbound message:");
+        }
+
+        SOAPMessage message = smc.getMessage();
+        try {
+            message.writeTo(out);
+            out.println();
+        } catch (Exception e) {
+            out.println("Exception in handler: " + e);
+        }
+    }
+}

Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/LoggingHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/LoggingHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/SmallNumberHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/SmallNumberHandler.java?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/SmallNumberHandler.java
(original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/SmallNumberHandler.java
Wed Nov  1 09:46:38 2006
@@ -20,15 +20,15 @@
 package demo.handlers.common;
 
 import java.util.Map;
-//import javax.xml.bind.JAXBContext;
-//import javax.xml.bind.JAXBException;
-//import javax.xml.ws.LogicalMessage;
-//import javax.xml.ws.ProtocolException;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.ws.LogicalMessage;
+import javax.xml.ws.ProtocolException;
 import javax.xml.ws.handler.LogicalHandler;
 import javax.xml.ws.handler.LogicalMessageContext;
 import javax.xml.ws.handler.MessageContext;
-//import org.objectweb.handlers.types.AddNumbers;
-//import org.objectweb.handlers.types.AddNumbersResponse;
+import org.apache.handlers.types.AddNumbers;
+import org.apache.handlers.types.AddNumbersResponse;
 
 
 
@@ -42,8 +42,7 @@
 
     public final boolean handleMessage(LogicalMessageContext messageContext) {
         System.out.println("LogicalMessageHandler handleMessage called");
-        //Comment below out as int type doesnt work. see jira 136
-/*
+
         try {
             boolean outbound = (Boolean)messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
 
@@ -86,8 +85,7 @@
         } catch (JAXBException ex) {
             throw new ProtocolException(ex);
         }
-        */
-        return true;
+
     }
 
     public final boolean handleFault(LogicalMessageContext messageContext) {

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/demo_handlers.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/demo_handlers.xml?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/demo_handlers.xml
(original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/common/demo_handlers.xml
Wed Nov  1 09:46:38 2006
@@ -24,8 +24,8 @@
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee">
     <handler-chain>
 	<handler>
-		<handler-name>SmallNumberHandler</handler-name>
-		<handler-class>demo.handlers.common.SmallNumberHandler</handler-class>
+		<handler-name>LoggingHandler</handler-name>
+		<handler-class>demo.handlers.common.LoggingHandler</handler-class>
 	</handler>
     </handler-chain>
 </handler-chains>

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/server/AddNumbersImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/server/AddNumbersImpl.java?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/server/AddNumbersImpl.java
(original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/handlers/src/demo/handlers/server/AddNumbersImpl.java
Wed Nov  1 09:46:38 2006
@@ -23,7 +23,7 @@
 import javax.jws.WebService;
 import org.apache.handlers.AddNumbers;
 import org.apache.handlers.AddNumbersFault;
-//import org.objectweb.handlers.types.FaultDetail;
+import org.apache.handlers.types.FaultDetail;
 
 
 @WebService(name = "AddNumbers",
@@ -42,9 +42,8 @@
      * @throws AddNumbersException
      *             if any of the numbers to be added is negative.
      */
-    public void addNumbers(String number1) throws AddNumbersFault {
-        System.out.println("addNumbers called....." + number1);
-/*
+    public int addNumbers(int number1, int number2) throws AddNumbersFault {
+        System.out.println("addNumbers called....." + number1 + ":" + number2);
         if (number1 < 0 || number2 < 0) {
             String message = "Negative number cant be added!";
             String detail = "Numbers: " + number1 + ", " + number2;
@@ -54,8 +53,6 @@
             throw new AddNumbersFault(message, fault);
         }
         return number1 + number2;
-        */
-        return;
     }
 
 }

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/handlers/wsdl/addNumbers.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/handlers/wsdl/addNumbers.wsdl?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/handlers/wsdl/addNumbers.wsdl
(original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/handlers/wsdl/addNumbers.wsdl
Wed Nov  1 09:46:38 2006
@@ -35,13 +35,15 @@
 
             <complexType name="addNumbersResponse">
                 <sequence>
+                    <element name="return" type="xsd:int" />
                 </sequence>
             </complexType>
             <element name="addNumbersResponse" type="x1:addNumbersResponse"/>
 
             <complexType name="addNumbers">
                 <sequence>
-                    <element name="arg0" type="xsd:string" />
+                    <element name="arg0" type="xsd:int" />
+                    <element name="arg1" type="xsd:int" />
                 </sequence>
             </complexType>
             <element name="addNumbers" type="x1:addNumbers"/>

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersImpl.java?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersImpl.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/AddNumbersImpl.java
Wed Nov  1 09:46:38 2006
@@ -41,8 +41,9 @@
      * @throws AddNumbersException
      *             if any of the numbers to be added is negative.
      */
-    public void addNumbers(String number1) throws AddNumbersFault {
-        System.out.println("addNumbers called....." + number1);
+    public int addNumbers(int number1, int number2) throws AddNumbersFault {
+        System.out.println("addNumbers called....., number1: " + number1 + " number2: " +
number2);
+        return number1 * number2;
     }
 
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerClientServerTest.java
Wed Nov  1 09:46:38 2006
@@ -20,11 +20,15 @@
 package org.apache.cxf.systest.handlers;
 
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 
 //import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Endpoint;
+import javax.xml.ws.handler.Handler;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -76,11 +80,18 @@
 
         AddNumbersService service = new AddNumbersService(wsdl, serviceName);
         AddNumbers port = (AddNumbers)service.getPort(portName, AddNumbers.class);
-
-        port.addNumbers("20");
-
-        //This assertion can not pass due to jira CXF-136: int type or more than two parameters
dont work
-        //assertEquals("2020", result);
+        
+        //Add client side handlers programmatically
+        SmallNumberHandler sh = new SmallNumberHandler();
+        List<Handler> newHandlerChain = new ArrayList<Handler>();
+        newHandlerChain.add(sh);
+        ((BindingProvider)port).getBinding().setHandlerChain(newHandlerChain);
+
+        int result = port.addNumbers(10, 20);
+        assertEquals(200, result);
+        int result1 = port.addNumbers(5, 6);
+        //TODO: This test can not pass due to jira cxf-195
+        //assertEquals(11, result1);
     }
 
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
Wed Nov  1 09:46:38 2006
@@ -19,38 +19,94 @@
 package org.apache.cxf.systest.handlers;
 
 import java.util.Map;
-/*
- * import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException;
- * import javax.xml.ws.LogicalMessage; import javax.xml.ws.ProtocolException;
- */
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.ws.LogicalMessage;
+import javax.xml.ws.ProtocolException;
 import javax.xml.ws.handler.LogicalHandler;
 import javax.xml.ws.handler.LogicalMessageContext;
 import javax.xml.ws.handler.MessageContext;
 
-// import org.apache.handlers.types.AddNumbers;
+import org.apache.handlers.types.AddNumbers;
+import org.apache.handlers.types.AddNumbersResponse;
 
-// import org.apache.handlers.types.AddNumbersResponse;
 
 /**
  * handles addition of small numbers.
  */
-public class SmallNumberHandler implements
-        LogicalHandler<LogicalMessageContext> {
+public class SmallNumberHandler implements LogicalHandler<LogicalMessageContext> {
+
+
+    // Implementation of javax.xml.ws.handler.Handler
+
     public final boolean handleMessage(LogicalMessageContext messageContext) {
-        //System.out.println("SmallNumberHandler : handleMessage Called....");
-        return true;
+        //System.out.println("LogicalMessageHandler handleMessage called");
+
+        try {
+            boolean outbound = (Boolean)messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+
+            if (outbound) {
+                // get the LogicalMessage from our context
+                //
+                LogicalMessage msg = messageContext.getMessage();
+
+                // check the payload, if its an AddNumbers request, we'll intervene
+                //
+                JAXBContext jaxbContext = JAXBContext.newInstance(AddNumbers.class);
+                Object payload = msg.getPayload(jaxbContext);
+
+                if (payload instanceof AddNumbers) {
+                    AddNumbers req = (AddNumbers)payload;
+
+                    // now, if the arguments are small, let's do the calculation here
+                    //
+                    int a = req.getArg0();
+                    int b = req.getArg1();
+
+                    if (isSmall(a) && isSmall(b)) {
+                        int answer = a + b;
+
+                        //System.out.printf("SmallNumberHandler addNumbers(%d, %d) == %d\n",
a, b, answer);
+                        // ok, we've done the calculation, so build the
+                        // response and set it as the payload of the message
+                        AddNumbersResponse resp = new AddNumbersResponse();
+                        resp.setReturn(answer);
+                        msg.setPayload(resp, jaxbContext);
+
+                        // finally, return false, indicating that request
+                        // processing stops here and our answer will be
+                        // returned to the client
+                        return false;
+                    }
+                }
+            }
+            return true;
+        } catch (JAXBException ex) {
+            throw new ProtocolException(ex);
+        }
+
     }
 
     public final boolean handleFault(LogicalMessageContext messageContext) {
+        System.out.println("LogicalMessageHandler handleFault called");
+        System.out.println(messageContext);
+
         return true;
     }
 
     public void close(MessageContext ctx) {
+        System.out.println("LogicalHandler close called");
     }
 
     public void init(Map config) {
+        System.out.println("LogicalHandler init called");
     }
 
     public void destroy() {
+        System.out.println("LogicalHandler close called");
+    }
+
+    private boolean isSmall(int i) {
+        return i > 0 && i <= 10;
     }
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers.xml?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers.xml
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/handlers.xml
Wed Nov  1 09:46:38 2006
@@ -5,15 +5,7 @@
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee">
     <handler-chain>
-	<handler>
-		<handler-name>lh1</handler-name>
-		<handler-class>org.apache.cxf.systest.handlers.SmallNumberHandler</handler-class>
-		<init-param>
-			<param-name>token</param-name>
-			<param-value>String</param-value>
-		</init-param>
-	</handler>
-	<handler>
+        <handler>
 		<handler-name>ph1</handler-name>
 		<handler-class>org.apache.cxf.systest.handlers.LoggingHandler</handler-class>
 		<init-param>

Modified: incubator/cxf/trunk/testutils/src/main/resources/wsdl/addNumbers.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/resources/wsdl/addNumbers.wsdl?view=diff&rev=470011&r1=470010&r2=470011
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/resources/wsdl/addNumbers.wsdl (original)
+++ incubator/cxf/trunk/testutils/src/main/resources/wsdl/addNumbers.wsdl Wed Nov  1 09:46:38
2006
@@ -35,13 +35,15 @@
 
             <complexType name="addNumbersResponse">
                 <sequence>
+                    <element name="return" type="xsd:int" />
                 </sequence>
             </complexType>
             <element name="addNumbersResponse" type="x1:addNumbersResponse"/>
 
             <complexType name="addNumbers">
                 <sequence>
-                    <element name="arg0" type="xsd:string" />
+                    <element name="arg0" type="xsd:int" />
+                    <element name="arg1" type="xsd:int" />
                 </sequence>
             </complexType>
             <element name="addNumbers" type="x1:addNumbers"/>
@@ -53,7 +55,7 @@
                     <element name="message" type="xsd:string" />
                 </sequence>
             </complexType>
-        </xsd:schema>
+       </xsd:schema>
     </types>
     <message name="addNumbers">
         <part name="parameters" element="x1:addNumbers" />



Mime
View raw message