You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ro...@apache.org on 2008/04/10 23:15:35 UTC
svn commit: r646963 - in /webservices/axis2/trunk/java/modules:
jaxws-integration/test/org/apache/axis2/jaxws/sample/
jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/
jaxws/src/org/apache/axis2/jaxws/server/
Author: rott
Date: Thu Apr 10 14:15:29 2008
New Revision: 646963
URL: http://svn.apache.org/viewvc?rev=646963&view=rev
Log:
AXIS2-3726 + HUGE much needed improvements in AddNumbersHandlerTests. We now log all handler method calls for each client-server end-to-end transaction and assertEquals expected results. This should make it nearly impossible to regress the handler framework or make "double calls" into it, as this included EndpointController patch fixes.
Modified:
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler2.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler3.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler4.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientProtocolHandler.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersHandlerPortTypeImpl.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersLogicalHandler.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersLogicalHandler2.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler2.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/HandlerTracker.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java Thu Apr 10 14:15:29 2008
@@ -19,18 +19,17 @@
package org.apache.axis2.jaxws.sample;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.apache.axis2.jaxws.TestLogger;
-import org.apache.axis2.jaxws.framework.AbstractTestCase;
-import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersClientLogicalHandler;
-import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersClientLogicalHandler2;
-import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersClientLogicalHandler3;
-import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersClientLogicalHandler4;
-import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersClientProtocolHandler;
-import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerPortType;
-import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerService;
-import org.test.addnumbershandler.AddNumbersHandlerResponse;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Future;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
@@ -49,13 +48,20 @@
import javax.xml.ws.handler.HandlerResolver;
import javax.xml.ws.handler.PortInfo;
import javax.xml.ws.soap.SOAPFaultException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Future;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.axis2.jaxws.TestLogger;
+import org.apache.axis2.jaxws.framework.AbstractTestCase;
+import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersClientLogicalHandler;
+import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersClientLogicalHandler2;
+import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersClientLogicalHandler3;
+import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersClientLogicalHandler4;
+import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersClientProtocolHandler;
+import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerPortType;
+import org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerService;
+import org.test.addnumbershandler.AddNumbersHandlerResponse;
public class AddNumbersHandlerTests extends AbstractTestCase {
@@ -66,6 +72,8 @@
File.separator+"test-resources"+File.separator+"xml";
requestFile = new File(resourceDir+File.separator+"addnumberstest.xml");
}
+
+ private static final String filelogname = "AddNumbersHandlerTests.log";
public static Test suite() {
return getTestSetup(new TestSuite(AddNumbersHandlerTests.class));
@@ -107,6 +115,26 @@
// @PreDestroy method was never called. The file is set to .deleteOnExit(), so no need to delete it.
File file = new File("AddNumbersProtocolHandler.preDestroy.txt");
assertTrue("File AddNumbersProtocolHandler.preDestroy.txt does not exist, meaning the @PreDestroy method was not called.", file.exists());
+
+ String log = readLogFile();
+ String expected_calls =
+ "AddNumbersLogicalHandler2 POST_CONSTRUCT\n"
+ + "AddNumbersProtocolHandler2 GET_HEADERS\n"
+ + "AddNumbersProtocolHandler GET_HEADERS\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler CLOSE\n"
+ + "AddNumbersLogicalHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler CLOSE\n"
+ + "AddNumbersProtocolHandler PRE_DESTROY\n";
+ assertEquals(expected_calls, log);
TestLogger.logger.debug("----------------------------------");
} catch(Exception e) {
@@ -147,7 +175,32 @@
if (!resString.contains("<return>16</return>")) {
fail("Response string should contain <return>16</return>, but does not. The resString was: \"" + resString + "\"");
}
-
+
+ String log = readLogFile();
+ String expected_calls = "AddNumbersClientLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 POST_CONSTRUCT\n"
+ + "AddNumbersProtocolHandler2 GET_HEADERS\n"
+ + "AddNumbersProtocolHandler GET_HEADERS\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler CLOSE\n"
+ + "AddNumbersLogicalHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler CLOSE\n"
+ + "AddNumbersProtocolHandler PRE_DESTROY\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientProtocolHandler CLOSE\n"
+ + "AddNumbersClientLogicalHandler CLOSE\n";
+ assertEquals(expected_calls, log);
+
TestLogger.logger.debug("----------------------------------");
} catch (Exception e) {
e.printStackTrace();
@@ -177,7 +230,32 @@
if (!resString.contains("<return>16</return>")) {
fail("Response string should contain <return>16</return>, but does not. The resString was: \"" + resString + "\"");
}
-
+
+ String log = readLogFile();
+ String expected_calls = "AddNumbersClientLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 POST_CONSTRUCT\n"
+ + "AddNumbersProtocolHandler2 GET_HEADERS\n"
+ + "AddNumbersProtocolHandler GET_HEADERS\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler CLOSE\n"
+ + "AddNumbersLogicalHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler CLOSE\n"
+ + "AddNumbersProtocolHandler PRE_DESTROY\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientProtocolHandler CLOSE\n"
+ + "AddNumbersClientLogicalHandler CLOSE\n";
+ assertEquals(expected_calls, log);
+
TestLogger.logger.debug("----------------------------------");
} catch (Exception e) {
e.printStackTrace();
@@ -208,7 +286,9 @@
List<Handler> list = p.getBinding().getHandlerChain();
assertTrue("List should be empty. We've not conformed to JAXWS 9.2.1.1.", list.isEmpty());
-
+ String log = readLogFile();
+ assertNull("log should be empty, since no handlers are in the list and we never called a service", log);
+
TestLogger.logger.debug("----------------------------------");
} catch (Exception e) {
e.printStackTrace();
@@ -238,7 +318,23 @@
} catch(Exception e) {
e.printStackTrace();
assertTrue("Exception should be SOAPFaultException", e instanceof SOAPFaultException);
- assertEquals(((SOAPFaultException)e).getMessage(), "AddNumbersLogicalHandler2 was here");
+ assertEquals(((SOAPFaultException)e).getMessage(), "I don't like the value 99");
+
+ String log = readLogFile();
+ String expected_calls = "AddNumbersLogicalHandler2 POST_CONSTRUCT\n"
+ + "AddNumbersProtocolHandler2 GET_HEADERS\n"
+ + "AddNumbersProtocolHandler GET_HEADERS\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler2 THROWING PROTOCOLEXCEPTION INBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_FAULT_OUTBOUND\n"
+ + "AddNumbersProtocolHandler HANDLE_FAULT_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler CLOSE\n"
+ + "AddNumbersProtocolHandler PRE_DESTROY\n";
+ assertEquals(expected_calls, log);
}
TestLogger.logger.debug("----------------------------------");
}
@@ -291,6 +387,32 @@
assertEquals("With handler manipulation, total should be 4 less than a proper sumation.", 16, total);
TestLogger.logger.debug("Total (after handler manipulation) = " + total);
+
+ String log = readLogFile();
+ String expected_calls = "AddNumbersClientLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 POST_CONSTRUCT\n"
+ + "AddNumbersProtocolHandler2 GET_HEADERS\n"
+ + "AddNumbersProtocolHandler GET_HEADERS\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler CLOSE\n"
+ + "AddNumbersLogicalHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler CLOSE\n"
+ + "AddNumbersProtocolHandler PRE_DESTROY\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientProtocolHandler CLOSE\n"
+ + "AddNumbersClientLogicalHandler CLOSE\n";
+ assertEquals(expected_calls, log);
+
TestLogger.logger.debug("----------------------------------");
} catch(Exception e) {
e.printStackTrace();
@@ -324,6 +446,32 @@
16,
total);
TestLogger.logger.debug("Total (after handler manipulation) = " + total);
+
+ String log = readLogFile();
+ String expected_calls = "AddNumbersClientLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 POST_CONSTRUCT\n"
+ + "AddNumbersProtocolHandler2 GET_HEADERS\n"
+ + "AddNumbersProtocolHandler GET_HEADERS\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler CLOSE\n"
+ + "AddNumbersLogicalHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler CLOSE\n"
+ + "AddNumbersProtocolHandler PRE_DESTROY\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientProtocolHandler CLOSE\n"
+ + "AddNumbersClientLogicalHandler CLOSE\n";
+ assertEquals(expected_calls, log);
+
TestLogger.logger.debug("----------------------------------");
} catch(Exception e) {
e.printStackTrace();
@@ -364,6 +512,31 @@
"AddNumbersHandlerPortTypeImpl.addNumbersHandler method is " +
"correctly throwing this exception as part of testing");
+ String log = readLogFile();
+ String expected_calls = "AddNumbersClientLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 POST_CONSTRUCT\n"
+ + "AddNumbersProtocolHandler2 GET_HEADERS\n"
+ + "AddNumbersProtocolHandler GET_HEADERS\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_FAULT_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_FAULT_OUTBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_FAULT_OUTBOUND\n"
+ + "AddNumbersProtocolHandler HANDLE_FAULT_OUTBOUND\n"
+ + "AddNumbersLogicalHandler CLOSE\n"
+ + "AddNumbersLogicalHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler CLOSE\n"
+ + "AddNumbersProtocolHandler PRE_DESTROY\n"
+ + "AddNumbersClientProtocolHandler HANDLE_FAULT_INBOUND\n"
+ + "AddNumbersClientLogicalHandler HANDLE_FAULT_INBOUND\n"
+ + "AddNumbersClientProtocolHandler CLOSE\n"
+ + "AddNumbersClientLogicalHandler CLOSE\n";
+ assertEquals(expected_calls, log);
+
}
TestLogger.logger.debug("----------------------------------");
}
@@ -393,12 +566,24 @@
int total = proxy.addNumbersHandler(99,10);
fail("Should have got an exception, but we didn't.");
- TestLogger.logger.debug("----------------------------------");
} catch(Exception e) {
e.printStackTrace();
assertTrue("Exception should be SOAPFaultException", e instanceof SOAPFaultException);
- assertEquals(((SOAPFaultException)e).getMessage(), "I don't like the value 99");
+ assertEquals("I don't like the value 99", ((SOAPFaultException)e).getMessage());
+
+ String log = readLogFile();
+ String expected_calls = "AddNumbersClientLogicalHandler4 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientLogicalHandler3 HANDLE_FAULT_OUTBOUND\n"
+ + "AddNumbersClientLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientLogicalHandler3 HANDLE_FAULT_INBOUND\n"
+ + "AddNumbersClientLogicalHandler3 RETURNING FALSE INBOUND\n"
+ + "AddNumbersClientLogicalHandler CLOSE\n"
+ + "AddNumbersClientLogicalHandler3 CLOSE\n"
+ + "AddNumbersClientLogicalHandler4 CLOSE\n";
+ assertEquals(expected_calls, log);
+
}
+ TestLogger.logger.debug("----------------------------------");
}
/**
@@ -440,6 +625,35 @@
assertEquals("With handler manipulation, total should be 26.", 26, total);
TestLogger.logger.debug("Total (after handler manipulation) = " + total);
+
+ String log = readLogFile();
+ String expected_calls = "AddNumbersClientLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientLogicalHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 POST_CONSTRUCT\n"
+ + "AddNumbersProtocolHandler2 GET_HEADERS\n"
+ + "AddNumbersProtocolHandler GET_HEADERS\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersLogicalHandler CLOSE\n"
+ + "AddNumbersLogicalHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler CLOSE\n"
+ + "AddNumbersProtocolHandler PRE_DESTROY\n"
+ + "AddNumbersClientProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersClientProtocolHandler CLOSE\n"
+ + "AddNumbersClientLogicalHandler2 CLOSE\n"
+ + "AddNumbersClientLogicalHandler CLOSE\n";
+ assertEquals(expected_calls, log);
+
TestLogger.logger.debug("----------------------------------");
} catch(Exception e) {
e.printStackTrace();
@@ -447,6 +661,26 @@
}
}
+ public void testAddNumbersHandlerHandlerResolver() {
+ try {
+ System.out.println("----------------------------------");
+ System.out.println("test: " + getName());
+ AddNumbersHandlerService service = new AddNumbersHandlerService(); // will give NPE:
+ List<Handler> handlers = service.getHandlerResolver()
+ .getHandlerChain(null);
+ assertNotNull(
+ "Default handlers list should not be null but empty.",
+ handlers);
+
+ String log = readLogFile();
+ assertNull("log should be null since we did not call any services", log);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ TestLogger.logger.debug("----------------------------------");
+ }
+
public void testOneWay() {
try {
TestLogger.logger.debug("----------------------------------");
@@ -459,11 +693,26 @@
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
axisEndpoint);
proxy.oneWayInt(11);
- TestLogger.logger.debug("----------------------------------");
+
+ String log = readLogFile();
+ String expected_calls = "AddNumbersLogicalHandler2 POST_CONSTRUCT\n"
+ + "AddNumbersProtocolHandler2 GET_HEADERS\n"
+ + "AddNumbersProtocolHandler GET_HEADERS\n"
+ + "AddNumbersProtocolHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersProtocolHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler2 HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler HANDLE_MESSAGE_INBOUND\n"
+ + "AddNumbersLogicalHandler CLOSE\n"
+ + "AddNumbersLogicalHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler2 CLOSE\n"
+ + "AddNumbersProtocolHandler CLOSE\n";
+ assertEquals(expected_calls, log);
+
} catch (Exception e) {
e.printStackTrace();
fail();
- }
+ }
+ TestLogger.logger.debug("----------------------------------");
}
public void testOneWayWithProtocolException() {
@@ -494,6 +743,12 @@
} catch (Exception e) {
e.printStackTrace();
assertEquals(e.getMessage(), "I don't like the value 99");
+
+ String log = readLogFile();
+ String expected_calls = "AddNumbersClientLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientLogicalHandler CLOSE\n";
+ assertEquals(expected_calls, log);
+
}
TestLogger.logger.debug("----------------------------------");
}
@@ -526,6 +781,11 @@
} catch (Exception e) {
e.printStackTrace();
assertEquals(e.getMessage(), "I don't like the value 999");
+
+ String log = readLogFile();
+ String expected_calls = "AddNumbersClientLogicalHandler HANDLE_MESSAGE_OUTBOUND\n"
+ + "AddNumbersClientLogicalHandler CLOSE\n";
+ assertEquals(expected_calls, log);
}
TestLogger.logger.debug("----------------------------------");
}
@@ -592,21 +852,31 @@
return new StreamSource(fis);
}
- public void testAddNumbersHandlerHandlerResolver() {
- try {
- System.out.println("----------------------------------");
- System.out.println("test: " + getName());
- AddNumbersHandlerService service = new AddNumbersHandlerService(); // will give NPE:
- List<Handler> handlers = service.getHandlerResolver()
- .getHandlerChain(null);
- assertNotNull(
- "Default handlers list should not be null but empty.",
- handlers);
- System.out.println("----------------------------------");
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
+ private String readLogFile() {
+ try {
+ FileReader fr = new FileReader(filelogname);
+ BufferedReader inputStream = new BufferedReader(fr);
+ String line = null;
+ String ret = null;
+ while ((line = inputStream.readLine()) != null) {
+ if (ret == null) {
+ ret = "";
+ }
+ ret = ret.concat(line + "\n");
+ }
+ fr.close();
+ File file = new File(filelogname);
+ file.delete(); // yes, delete for each retrieval, which should only happen once per test
+ return ret;
+ } catch (FileNotFoundException fnfe) {
+ // it's possible the test does not actually call any handlers and therefore
+ // no file would have been written. The test should account for this by
+ // assertNull on the return value from here
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ }
+ return null;
+ }
}
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler.java Thu Apr 10 14:15:29 2008
@@ -55,16 +55,22 @@
public class AddNumbersClientLogicalHandler
implements javax.xml.ws.handler.LogicalHandler<LogicalMessageContext> {
+ HandlerTracker tracker = new HandlerTracker(AddNumbersClientLogicalHandler.class.getSimpleName());
+
public void close(MessageContext messagecontext) {
+ tracker.close();
}
public boolean handleFault(LogicalMessageContext messagecontext) {
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleFault(outbound);
return true;
}
public boolean handleMessage(LogicalMessageContext messagecontext) {
Boolean outbound =
(Boolean)messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleMessage(outbound);
if (!outbound) { // inbound response on the client
// make sure standard property is available
@@ -97,7 +103,7 @@
throw new RuntimeException("Property " + propKey + " was null");
}
if (!(map instanceof AttachmentsAdapter)) {
- throw new RuntimeException("Expected AttachmentAddapter for Property " +
+ throw new RuntimeException("Expected AttachmentAdapter for Property " +
propKey);
}
propKey = "AddNumbersClientProtocolHandlerOutboundHandlerScopedProperty";
@@ -158,7 +164,7 @@
throw new RuntimeException("Property " + propKey + " was null");
}
if (!(map instanceof AttachmentsAdapter)) {
- throw new RuntimeException("Expected AttachmentAddapter for Property " +
+ throw new RuntimeException("Expected AttachmentAdapter for Property " +
propKey);
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler2.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler2.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler2.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler2.java Thu Apr 10 14:15:29 2008
@@ -41,15 +41,21 @@
public class AddNumbersClientLogicalHandler2 implements javax.xml.ws.handler.LogicalHandler<LogicalMessageContext> {
+ HandlerTracker tracker = new HandlerTracker(AddNumbersClientLogicalHandler2.class.getSimpleName());
+
public void close(MessageContext messagecontext) {
+ tracker.close();
}
public boolean handleFault(LogicalMessageContext messagecontext) {
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleFault(outbound);
return true;
}
public boolean handleMessage(LogicalMessageContext messagecontext) {
Boolean outbound = (Boolean)messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleMessage(outbound);
if (outbound) { // outbound request on the client
LogicalMessage msg = messagecontext.getMessage();
Source payload = msg.getPayload();
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler3.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler3.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler3.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler3.java Thu Apr 10 14:15:29 2008
@@ -38,18 +38,25 @@
public class AddNumbersClientLogicalHandler3 implements javax.xml.ws.handler.LogicalHandler<LogicalMessageContext> {
+ HandlerTracker tracker = new HandlerTracker(AddNumbersClientLogicalHandler3.class.getSimpleName());
+
public void close(MessageContext messagecontext) {
- // TODO Auto-generated method stub
+ tracker.close();
}
public boolean handleFault(LogicalMessageContext messagecontext) {
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleFault(outbound);
// let's see if we can do this
LogicalMessage lm = messagecontext.getMessage();
String s = getStringFromSourcePayload(lm.getPayload());
+ tracker.log("RETURNING FALSE", outbound);
return false;
}
- public boolean handleMessage(LogicalMessageContext mc) {
+ public boolean handleMessage(LogicalMessageContext messagecontext) {
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleFault(outbound);
return true;
}
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler4.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler4.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler4.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler4.java Thu Apr 10 14:15:29 2008
@@ -31,15 +31,21 @@
public class AddNumbersClientLogicalHandler4 implements javax.xml.ws.handler.LogicalHandler<LogicalMessageContext> {
+ HandlerTracker tracker = new HandlerTracker(AddNumbersClientLogicalHandler4.class.getSimpleName());
+
public void close(MessageContext messagecontext) {
- // TODO Auto-generated method stub
+ tracker.close();
}
public boolean handleFault(LogicalMessageContext messagecontext) {
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleFault(outbound);
return true;
}
- public boolean handleMessage(LogicalMessageContext mc) {
+ public boolean handleMessage(LogicalMessageContext messagecontext) {
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleMessage(outbound);
return true;
}
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientProtocolHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientProtocolHandler.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientProtocolHandler.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientProtocolHandler.java Thu Apr 10 14:15:29 2008
@@ -32,19 +32,26 @@
public class AddNumbersClientProtocolHandler implements javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {
+ HandlerTracker tracker = new HandlerTracker(AddNumbersClientProtocolHandler.class.getSimpleName());
+
public void close(MessageContext messagecontext) {
+ tracker.close();
}
public boolean handleFault(SOAPMessageContext messagecontext) {
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleFault(outbound);
return true;
}
public Set getHeaders() {
+ tracker.getHeaders();
return null;
}
public boolean handleMessage(SOAPMessageContext messagecontext) {
Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleMessage(outbound);
if (outbound) {
String appProp1 = "AddNumbersClientProtocolHandlerOutboundAppScopedProperty";
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersHandlerPortTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersHandlerPortTypeImpl.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersHandlerPortTypeImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersHandlerPortTypeImpl.java Thu Apr 10 14:15:29 2008
@@ -41,11 +41,7 @@
* @see org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerPortType#addNumbersHandler(int, int)
*/
public int addNumbersHandler(int arg0, int arg1) throws AddNumbersHandlerFault_Exception {
-
- HandlerTracker tracker = HandlerTracker.getHandlerTracker(AddNumbersProtocolHandler.class);
- if (!tracker.isCalled(HandlerTracker.Methods.HANDLE_MESSAGE)) {
- throw new RuntimeException("handleMessage() was not called on the handler");
- }
+
/* FIXME: getHeaders() is currently not called
if (!tracker.isCalled(HandlerTracker.Methods.GET_HEADERS)) {
throw new RuntimeException("getHeaders() was not called on the handler");
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersLogicalHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersLogicalHandler.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersLogicalHandler.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersLogicalHandler.java Thu Apr 10 14:15:29 2008
@@ -19,131 +19,29 @@
package org.apache.axis2.jaxws.sample.addnumbershandler;
-import org.apache.axis2.jaxws.handler.AttachmentsAdapter;
-import org.apache.axis2.jaxws.handler.LogicalMessageContext;
-
-import javax.annotation.PostConstruct;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.ws.LogicalMessage;
-import javax.xml.ws.ProtocolException;
import javax.xml.ws.handler.MessageContext;
-import javax.xml.ws.handler.MessageContext.Scope;
-import java.io.ByteArrayOutputStream;
-import java.io.StringBufferInputStream;
-import java.util.Map;
-import java.util.StringTokenizer;
+
+import org.apache.axis2.jaxws.handler.LogicalMessageContext;
public class AddNumbersLogicalHandler
implements javax.xml.ws.handler.LogicalHandler<LogicalMessageContext> {
-
- private int deduction = 1;
- public void close(MessageContext messagecontext) {
-
- }
+ HandlerTracker tracker = new HandlerTracker(AddNumbersLogicalHandler.class.getSimpleName());
- @PostConstruct
- public void postConstruct() {
- deduction = 2;
+ public void close(MessageContext messagecontext) {
+ tracker.close();
}
public boolean handleFault(LogicalMessageContext messagecontext) {
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleFault(outbound);
return true;
}
- /*
- * this test handleMessage method is obviously not what a customer might write, but it does
- * the trick for kicking the tires in the handler framework. The AddNumbers service takes two
- * ints as incoming params, adds them, and returns the sum. This method subtracts 1 from the
- * first int on the inbound request, and subtracts "deduction" from the int on the outbound
- * response. So the client app should expect a sum 3 less than a sum with this handler
- * manipulating the SOAP message.
- */
public boolean handleMessage(LogicalMessageContext messagecontext) {
- Boolean outbound = (Boolean)messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
- if (!outbound) { // inbound request if we're on the server
- LogicalMessage msg = messagecontext.getMessage();
- String st = getStringFromSourcePayload(msg.getPayload());
- if (st.contains("<arg0>99</arg0>")) {
- throw new ProtocolException("I don't like the value 99");
- }
- String txt = String.valueOf(Integer.valueOf(getFirstArg(st)) - 1);
- st = replaceFirstArg(st, txt);
- msg.setPayload(new StreamSource(new StringBufferInputStream(st)));
-
- messagecontext.put("AddNumbersLogicalHandlerInboundAppScopedProperty", "blargval");
- messagecontext.setScope("AddNumbersLogicalHandlerInboundAppScopedProperty",
- Scope.APPLICATION);
- messagecontext.put("AddNumbersLogicalHandlerInboundHandlerScopedProperty",
- "blargval");
-
- // Check for the presences of the attachment property
- String propKey = MessageContext.INBOUND_MESSAGE_ATTACHMENTS;
- Map map = (Map) messagecontext.get(propKey);
- if (map == null) {
- throw new RuntimeException("Property " + propKey + " was null");
- }
- if (!(map instanceof AttachmentsAdapter)) {
- throw new RuntimeException("Expected AttachmentAddapter for Property " +
- propKey);
- }
-
- } else { // outbound response if we're on the server
- LogicalMessage msg = messagecontext.getMessage();
- String st = getStringFromSourcePayload(msg.getPayload());
- String txt = String.valueOf(Integer.valueOf(getFirstArg(st)) - deduction);
- st = replaceFirstArg(st, txt);
- msg.setPayload(new StreamSource(new StringBufferInputStream(st)));
-
- // Check for the presences of the attachment property
- String propKey = MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS;
- Map map = (Map) messagecontext.get(propKey);
- if (map == null) {
- throw new RuntimeException("Property " + propKey + " was null");
- }
- if (!(map instanceof AttachmentsAdapter)) {
- throw new RuntimeException("Expected AttachmentAddapter for Property " +
- propKey);
- }
- }
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleMessage(outbound);
return true;
}
- private static String getFirstArg(String payloadString) {
- StringTokenizer st = new StringTokenizer(payloadString, ">");
- st.nextToken(); // skip first token.
- st.nextToken(); // skip second
- String tempString = st.nextToken();
- String returnString = new StringTokenizer(tempString, "<").nextToken();
- return returnString;
- }
-
- private static String replaceFirstArg(String payloadString, String newArg) {
- String firstArg = getFirstArg(payloadString);
- payloadString = payloadString.replaceFirst(firstArg, newArg);
- return payloadString;
- }
-
- private static String getStringFromSourcePayload(Source payload) {
- try {
-
- TransformerFactory factory = TransformerFactory.newInstance();
- Transformer trans = factory.newTransformer();
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- StreamResult result = new StreamResult(baos);
-
- trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- trans.transform(payload, result);
-
- return new String(baos.toByteArray());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
}
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersLogicalHandler2.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersLogicalHandler2.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersLogicalHandler2.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersLogicalHandler2.java Thu Apr 10 14:15:29 2008
@@ -19,8 +19,13 @@
package org.apache.axis2.jaxws.sample.addnumbershandler;
-import org.apache.axis2.jaxws.handler.LogicalMessageContext;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.StringBufferInputStream;
+import java.util.Map;
+import java.util.StringTokenizer;
+import javax.annotation.PostConstruct;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
@@ -28,31 +33,102 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.LogicalMessage;
+import javax.xml.ws.ProtocolException;
import javax.xml.ws.handler.MessageContext;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import javax.xml.ws.handler.MessageContext.Scope;
+
+import org.apache.axis2.jaxws.handler.AttachmentsAdapter;
+import org.apache.axis2.jaxws.handler.LogicalMessageContext;
public class AddNumbersLogicalHandler2 implements javax.xml.ws.handler.LogicalHandler<LogicalMessageContext> {
+ private int deduction = 1;
+
+ HandlerTracker tracker = new HandlerTracker(AddNumbersLogicalHandler2.class.getSimpleName());
+
+ @PostConstruct
+ public void postConstruct() {
+ tracker.postConstruct();
+ deduction = 2;
+ }
+
public void close(MessageContext messagecontext) {
-
+ tracker.close();
}
public boolean handleFault(LogicalMessageContext messagecontext) {
- Boolean outbound = (Boolean)messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleFault(outbound);
if (outbound) { // outbound response if we're on the server
LogicalMessage msg = messagecontext.getMessage();
String st = getStringFromSourcePayload(msg.getPayload());
st = st.replaceFirst("blarg", "AddNumbersLogicalHandler2 was here");
- st = st.replaceFirst("I don't like the value 99", "AddNumbersLogicalHandler2 was here");
msg.setPayload(new StreamSource(new ByteArrayInputStream(st.getBytes())));
}
return true;
}
+ /*
+ * this test handleMessage method is obviously not what a customer might write, but it does
+ * the trick for kicking the tires in the handler framework. The AddNumbers service takes two
+ * ints as incoming params, adds them, and returns the sum. This method subtracts 1 from the
+ * first int on the inbound request, and subtracts "deduction" from the int on the outbound
+ * response. So the client app should expect a sum 3 less than a sum with this handler
+ * manipulating the SOAP message.
+ */
public boolean handleMessage(LogicalMessageContext messagecontext) {
- return true;
+ Boolean outbound = (Boolean)messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleMessage(outbound);
+ if (!outbound) { // inbound request if we're on the server
+
+ LogicalMessage msg = messagecontext.getMessage();
+ String st = getStringFromSourcePayload(msg.getPayload());
+ if (st.contains("<arg0>99</arg0>")) {
+ tracker.log("THROWING PROTOCOLEXCEPTION", outbound);
+ throw new ProtocolException("I don't like the value 99");
+ }
+ String txt = String.valueOf(Integer.valueOf(getFirstArg(st)) - 1);
+ st = replaceFirstArg(st, txt);
+ msg.setPayload(new StreamSource(new StringBufferInputStream(st)));
+
+ messagecontext.put("AddNumbersLogicalHandlerInboundAppScopedProperty", "blargval");
+ messagecontext.setScope("AddNumbersLogicalHandlerInboundAppScopedProperty",
+ Scope.APPLICATION);
+ messagecontext.put("AddNumbersLogicalHandlerInboundHandlerScopedProperty",
+ "blargval");
+
+ // Check for the presences of the attachment property
+ String propKey = MessageContext.INBOUND_MESSAGE_ATTACHMENTS;
+ Map map = (Map) messagecontext.get(propKey);
+ if (map == null) {
+ throw new RuntimeException("Property " + propKey + " was null");
+ }
+ if (!(map instanceof AttachmentsAdapter)) {
+ throw new RuntimeException("Expected AttachmentAdapter for Property " +
+ propKey);
+ }
+
+ } else { // outbound response if we're on the server
+ LogicalMessage msg = messagecontext.getMessage();
+ String st = getStringFromSourcePayload(msg.getPayload());
+ String txt = String.valueOf(Integer.valueOf(getFirstArg(st)) - deduction);
+ st = replaceFirstArg(st, txt);
+ msg.setPayload(new StreamSource(new StringBufferInputStream(st)));
+
+ // Check for the presences of the attachment property
+ String propKey = MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS;
+ Map map = (Map) messagecontext.get(propKey);
+ if (map == null) {
+ throw new RuntimeException("Property " + propKey + " was null");
+ }
+ if (!(map instanceof AttachmentsAdapter)) {
+ throw new RuntimeException("Expected AttachmentAdapter for Property " +
+ propKey);
+ }
+ }
+ return true;
}
+
private static String getStringFromSourcePayload(Source payload) {
try {
@@ -70,6 +146,21 @@
} catch (Exception e) {
throw new RuntimeException(e);
}
+ }
+
+ private static String getFirstArg(String payloadString) {
+ StringTokenizer st = new StringTokenizer(payloadString, ">");
+ st.nextToken(); // skip first token.
+ st.nextToken(); // skip second
+ String tempString = st.nextToken();
+ String returnString = new StringTokenizer(tempString, "<").nextToken();
+ return returnString;
+ }
+
+ private static String replaceFirstArg(String payloadString, String newArg) {
+ String firstArg = getFirstArg(payloadString);
+ payloadString = payloadString.replaceFirst(firstArg, newArg);
+ return payloadString;
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler.java Thu Apr 10 14:15:29 2008
@@ -30,14 +30,15 @@
import javax.xml.ws.handler.soap.SOAPMessageContext;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.util.Set;
public class AddNumbersProtocolHandler implements javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {
- HandlerTracker tracker = HandlerTracker.getHandlerTracker(AddNumbersProtocolHandler.class);
+ HandlerTracker tracker = new HandlerTracker(AddNumbersProtocolHandler.class.getSimpleName());
public void close(MessageContext messagecontext) {
- tracker.close(messagecontext);
+ tracker.close();
}
public Set<QName> getHeaders() {
@@ -46,11 +47,12 @@
}
public boolean handleFault(SOAPMessageContext messagecontext) {
- tracker.handleFault(messagecontext);
+ tracker.handleFault((Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
return true;
}
public boolean handleMessage(SOAPMessageContext messagecontext) {
+ tracker.handleMessage((Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
// Ensure that the expected headers are present
JAXBContext context;
try {
@@ -82,14 +84,13 @@
e.printStackTrace();
throw new WebServiceException(e);
}
-
-
- tracker.handleMessage(messagecontext);
+
return true;
}
@PreDestroy
public void preDestroy() {
+ tracker.preDestroy();
try {
/*
* since @PreDestroy methods are called just before the managed (server) side
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler2.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler2.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler2.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler2.java Thu Apr 10 14:15:29 2008
@@ -19,25 +19,34 @@
package org.apache.axis2.jaxws.sample.addnumbershandler;
+import java.util.Set;
+
import javax.xml.namespace.QName;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;
-import java.util.Set;
public class AddNumbersProtocolHandler2 implements javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {
+ HandlerTracker tracker = new HandlerTracker(AddNumbersProtocolHandler2.class.getSimpleName());
+
public void close(MessageContext messagecontext) {
+ tracker.close();
}
public Set<QName> getHeaders() {
+ tracker.getHeaders();
return null;
}
public boolean handleFault(SOAPMessageContext messagecontext) {
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleFault(outbound);
return true;
}
public boolean handleMessage(SOAPMessageContext messagecontext) {
+ Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ tracker.handleMessage(outbound);
return true;
}
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/HandlerTracker.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/HandlerTracker.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/HandlerTracker.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addnumbershandler/HandlerTracker.java Thu Apr 10 14:15:29 2008
@@ -19,54 +19,75 @@
package org.apache.axis2.jaxws.sample.addnumbershandler;
-import javax.xml.ws.handler.MessageContext;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.io.FileWriter;
public class HandlerTracker {
- static Map<String, HandlerTracker> trackers = new HashMap<String, HandlerTracker>();
+ private static final String filelogname = "AddNumbersHandlerTests.log";
- List<Methods> calledMethods = new ArrayList<Methods>();
+ private String classname;
- enum Methods { CLOSE, GET_HEADERS, HANDLE_FAULT, HANDLE_MESSAGE };
+ private static final String CLOSE = "CLOSE";
+ private static final String GET_HEADERS = "GET_HEADERS";
+ private static final String HANDLE_FAULT_INBOUND = "HANDLE_FAULT_INBOUND";
+ private static final String HANDLE_MESSAGE_INBOUND = "HANDLE_MESSAGE_INBOUND";
+ private static final String HANDLE_FAULT_OUTBOUND = "HANDLE_FAULT_OUTBOUND";
+ private static final String HANDLE_MESSAGE_OUTBOUND = "HANDLE_MESSAGE_OUTBOUND";
+ private static final String POST_CONSTRUCT = "POST_CONSTRUCT";
+ private static final String PRE_DESTROY = "PRE_DESTROY";
- public HandlerTracker(String name) {
+ // should pass classname for "name"
+ public HandlerTracker(String name) {
+ classname = name;
}
- public void close(MessageContext context) {
- calledMethods.add(Methods.CLOSE);
+ public void postConstruct() {
+ log_to_file(POST_CONSTRUCT);
}
-
- public void getHeaders() {
- calledMethods.add(Methods.GET_HEADERS);
+
+ public void preDestroy() {
+ log_to_file(PRE_DESTROY);
}
- public void handleFault(MessageContext context) {
- calledMethods.add(Methods.HANDLE_FAULT);
+ public void close() {
+ log_to_file(CLOSE);
}
- public void handleMessage(MessageContext context) {
- calledMethods.add(Methods.HANDLE_MESSAGE);
+ public void getHeaders() {
+ log_to_file(GET_HEADERS);
+ }
+
+ public void handleFault(boolean outbound) {
+ if (outbound) {
+ log_to_file(HANDLE_FAULT_OUTBOUND);
+ } else {
+ log_to_file(HANDLE_FAULT_INBOUND);
+ }
}
- public boolean isCalled(Methods method) {
- return calledMethods.contains(method);
+ public void handleMessage(boolean outbound) {
+ if (outbound) {
+ log_to_file(HANDLE_MESSAGE_OUTBOUND);
+ } else {
+ log_to_file(HANDLE_MESSAGE_INBOUND);
+ }
}
- public static HandlerTracker getHandlerTracker(Class clazz) {
- HandlerTracker tracker = trackers.get(clazz.getName());
- if (tracker == null) {
- tracker = new HandlerTracker(clazz.getName());
- trackers.put(clazz.getName(), tracker);
- }
- return tracker;
+ public void log(String msg, boolean outbound) {
+ log_to_file(msg + " " + (outbound ? "OUTBOUND" : "INBOUND"));
}
- public String toString() {
- return this.calledMethods.toString();
+ /*
+ * we have to open and close the file every time we write
+ * as other handler method calls may be interleaved with this one
+ */
+ private void log_to_file(String msg) {
+ try {
+ FileWriter fw = new FileWriter(filelogname, true);
+ fw.write(classname + " " + msg + "\n");
+ fw.close();
+ } catch (Exception e) {
+ }
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java?rev=646963&r1=646962&r2=646963&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java Thu Apr 10 14:15:29 2008
@@ -93,8 +93,9 @@
}
MessageContext request = eic.getRequestMessageContext();
+ boolean good = true;
try {
- boolean good = handleRequest(eic);
+ good = handleRequest(eic);
if (!good) {
return eic;
@@ -117,9 +118,13 @@
}
throw ExceptionFactory.makeWebServiceException(toBeThrown);
} finally {
- // Passed pivot point
- request.getMessage().setPostPivot();
- handleResponse(eic);
+ if (good) {
+ // Passed pivot point
+ request.getMessage().setPostPivot();
+ handleResponse(eic);
+ } else {
+ destroyHandlers(eic, request);
+ }
}
return eic;
@@ -325,25 +330,29 @@
throw ExceptionFactory.makeWebServiceException(toBeThrown);
} finally {
// at this point, we are done with handler instances on the server; call @PreDestroy on all of them
- HandlerLifecycleManager hlm = createHandlerlifecycleManager();
- List<Handler> list = eic.getHandlers();
- if(list != null) {
- for (Iterator it = list.iterator(); it.hasNext();) {
- try {
- Handler handler = (Handler) it.next();
- hlm.destroyHandlerInstance(request, handler);
- } catch (Exception e) {
- // TODO: can we ignore this?
- throw ExceptionFactory.makeWebServiceException(e);
- }
- }
- }
+ destroyHandlers(eic, request);
responseReady(eic);
restoreRequestMessage(request);
}
eic.setResponseMessageContext(response);
return true;
+ }
+
+ private void destroyHandlers(EndpointInvocationContext eic, MessageContext request) {
+ HandlerLifecycleManager hlm = createHandlerlifecycleManager();
+ List<Handler> list = eic.getHandlers();
+ if(list != null) {
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ try {
+ Handler handler = (Handler) it.next();
+ hlm.destroyHandlerInstance(request, handler);
+ } catch (Exception e) {
+ // TODO: can we ignore this?
+ throw ExceptionFactory.makeWebServiceException(e);
+ }
+ }
+ }
}
/*
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org