Author: thomas.diesler(a)jboss.com
Date: 2007-03-15 12:08:22 -0400 (Thu, 15 Mar 2007)
New Revision: 2624
Added:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ClientHandler.java
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ServerHandler.java
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/CommonMessageContext.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/HandlerChainExecutor.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/MessageContextJAXWS.java
trunk/jbossws-tests/ant-import/build-jars-jaxws.xml
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/HandlerLifecycleClientTestCase.java
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/LifecycleHandler.java
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/SOAPEndpointBean.java
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ServletClient.java
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/jaxws-client-handlers.xml
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/jaxws-server-handlers.xml
Log:
Test scoped context properties
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/CommonMessageContext.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/CommonMessageContext.java 2007-03-15
13:47:10 UTC (rev 2623)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/CommonMessageContext.java 2007-03-15
16:08:22 UTC (rev 2624)
@@ -78,7 +78,7 @@
this.opMetaData = msgContext.opMetaData;
this.soapMessage = msgContext.soapMessage;
this.serContext = msgContext.serContext;
- this.scopedProps = msgContext.scopedProps;
+ this.scopedProps = new HashMap<String,
ScopedProperty>(msgContext.scopedProps);
this.currentScope = msgContext.currentScope;
}
@@ -218,13 +218,6 @@
return isValidInScope(prop);
}
- private boolean isValidInScope(ScopedProperty prop)
- {
- // A property of scope APPLICATION is always visible
- boolean valid = (prop != null && (prop.getScope() == Scope.APPLICATION ||
currentScope == Scope.HANDLER));
- return valid;
- }
-
public boolean containsValue(Object value)
{
boolean valueFound = false;
@@ -292,17 +285,22 @@
public Set<String> keySet()
{
- return scopedProps.keySet();
+ Set<String> keys = new HashSet<String>(scopedProps.size());
+ for (ScopedProperty prop : scopedProps.values())
+ {
+ if (isValidInScope(prop))
+ keys.add(prop.getName());
+ }
+ return keys;
}
public Collection<Object> values()
{
- Collection<Object> values = new HashSet<Object>();
+ Collection<Object> values = new HashSet<Object>(scopedProps.size());
for (ScopedProperty prop : scopedProps.values())
{
if (isValidInScope(prop))
values.add(prop.getValue());
-
}
return values;
}
@@ -323,6 +321,13 @@
return entries;
}
+ private boolean isValidInScope(ScopedProperty prop)
+ {
+ // A property of scope APPLICATION is always visible
+ boolean valid = (prop != null && (prop.getScope() == Scope.APPLICATION ||
currentScope == Scope.HANDLER));
+ return valid;
+ }
+
private static class ImmutableEntry<K, V> implements Map.Entry<K, V>
{
final K k;
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/HandlerChainExecutor.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/HandlerChainExecutor.java 2007-03-15
13:47:10 UTC (rev 2623)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/HandlerChainExecutor.java 2007-03-15
16:08:22 UTC (rev 2624)
@@ -313,7 +313,6 @@
boolean doNext = false;
- Scope scope = msgContext.getCurrentScope();
try
{
msgContext.setCurrentScope(Scope.HANDLER);
@@ -321,7 +320,7 @@
}
finally
{
- msgContext.setCurrentScope(scope);
+ msgContext.setCurrentScope(Scope.APPLICATION);
}
return doNext;
@@ -342,7 +341,6 @@
closeHandlers.add(currHandler);
boolean doNext = false;
- Scope scope = msgContext.getCurrentScope();
try
{
msgContext.setCurrentScope(Scope.HANDLER);
@@ -350,7 +348,7 @@
}
finally
{
- msgContext.setCurrentScope(scope);
+ msgContext.setCurrentScope(Scope.APPLICATION);
}
return doNext;
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/MessageContextJAXWS.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/MessageContextJAXWS.java 2007-03-15
13:47:10 UTC (rev 2623)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/MessageContextJAXWS.java 2007-03-15
16:08:22 UTC (rev 2624)
@@ -23,11 +23,6 @@
// $Id: MessageContextImpl.java 275 2006-05-04 21:36:29Z jason.greene(a)jboss.com $
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
import javax.xml.ws.addressing.JAXWSAConstants;
import javax.xml.ws.addressing.soap.SOAPAddressingProperties;
import javax.xml.ws.handler.MessageContext;
@@ -125,6 +120,27 @@
resContext.setProperty(StubExt.PROPERTY_MTOM_ENABLED, mtomEnabled);
resContext.setProperty(MessageContext.MESSAGE_OUTBOUND_PROPERTY, outbound);
resContext.setProperty(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND,
addrProps);
+
+ // Copy the handler scoped properties
+ try
+ {
+ reqContext.setCurrentScope(Scope.HANDLER);
+ resContext.setCurrentScope(Scope.HANDLER);
+ for(String key : reqContext.keySet())
+ {
+ if (((MessageContextJAXWS)reqContext).getScope(key) == Scope.HANDLER)
+ {
+ Object value = reqContext.get(key);
+ resContext.put(key, value);
+ }
+ }
+ }
+ finally
+ {
+ reqContext.setCurrentScope(Scope.APPLICATION);
+ resContext.setCurrentScope(Scope.APPLICATION);
+ }
+
MessageContextAssociation.pushMessageContext(resContext);
return resContext;
Modified: trunk/jbossws-tests/ant-import/build-jars-jaxws.xml
===================================================================
--- trunk/jbossws-tests/ant-import/build-jars-jaxws.xml 2007-03-15 13:47:10 UTC (rev
2623)
+++ trunk/jbossws-tests/ant-import/build-jars-jaxws.xml 2007-03-15 16:08:22 UTC (rev
2624)
@@ -128,6 +128,7 @@
<include
name="org/jboss/test/ws/jaxws/handlerlifecycle/SOAPEndpointBean.class"/>
<include
name="org/jboss/test/ws/jaxws/handlerlifecycle/TrackerEndpointBean.class"/>
<include
name="org/jboss/test/ws/jaxws/handlerlifecycle/LifecycleHandler.class"/>
+ <include
name="org/jboss/test/ws/jaxws/handlerlifecycle/ServerHandler.class"/>
<include
name="org/jboss/test/ws/jaxws/handlerlifecycle/HandlerTracker.class"/>
<include
name="org/jboss/test/ws/jaxws/handlerlifecycle/jaxws-server-handlers.xml"/>
</classes>
@@ -139,6 +140,7 @@
<include
name="org/jboss/test/ws/jaxws/handlerlifecycle/ServletClient.class"/>
<include
name="org/jboss/test/ws/jaxws/handlerlifecycle/HandlerTracker.class"/>
<include
name="org/jboss/test/ws/jaxws/handlerlifecycle/LifecycleHandler.class"/>
+ <include
name="org/jboss/test/ws/jaxws/handlerlifecycle/ClientHandler.class"/>
<include
name="org/jboss/test/ws/jaxws/handlerlifecycle/jaxws-client-handlers.xml"/>
</classes>
</war>
Added:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ClientHandler.java
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ClientHandler.java
(rev 0)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ClientHandler.java 2007-03-15
16:08:22 UTC (rev 2624)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.handlerlifecycle;
+
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.MessageContext.Scope;
+
+public class ClientHandler extends LifecycleHandler
+{
+ @Override
+ public boolean handleOutbound(MessageContext msgContext)
+ {
+ // set a handler prop
+ msgContext.put("client-handler-prop", Boolean.TRUE);
+
+ if (msgContext.get("client-req-prop") != Boolean.TRUE)
+ throw new IllegalStateException("Cannot find client-req-prop");
+
+ return super.handleOutbound(msgContext);
+ }
+
+ @Override
+ public boolean handleInbound(MessageContext msgContext)
+ {
+ if (msgContext.get("client-handler-prop") != Boolean.TRUE)
+ throw new IllegalStateException("Cannot find client-handler-prop");
+
+ if (msgContext.get("client-app-prop") != null)
+ throw new IllegalStateException("Found client-app-prop");
+
+ // set a app prop
+ msgContext.put("client-res-prop", Boolean.TRUE);
+ msgContext.setScope("client-res-prop", Scope.APPLICATION);
+
+ return super.handleInbound(msgContext);
+ }
+}
Property changes on:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ClientHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/HandlerLifecycleClientTestCase.java
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/HandlerLifecycleClientTestCase.java 2007-03-15
13:47:10 UTC (rev 2623)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/HandlerLifecycleClientTestCase.java 2007-03-15
16:08:22 UTC (rev 2624)
@@ -24,8 +24,11 @@
// $Id$
import java.net.URL;
+import java.util.Map;
import javax.xml.namespace.QName;
+import javax.xml.ws.Binding;
+import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import junit.framework.Test;
@@ -69,8 +72,15 @@
public void testClientAccess() throws Exception
{
+ Map<String, Object> reqContext =
((BindingProvider)port).getRequestContext();
+ Map<String, Object> resContext =
((BindingProvider)port).getResponseContext();
+ reqContext.put("client-req-prop", Boolean.TRUE);
+
String retStr = port.echo("hello");
assertEquals("hello", retStr);
+
+ assertNull(resContext.get("client-handler-prop"));
+ assertEquals(Boolean.TRUE, resContext.get("client-res-prop"));
}
public void testTrackerMessages() throws Exception
Modified:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/LifecycleHandler.java
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/LifecycleHandler.java 2007-03-15
13:47:10 UTC (rev 2623)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/LifecycleHandler.java 2007-03-15
16:08:22 UTC (rev 2624)
@@ -23,17 +23,12 @@
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPMessage;
-import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.MessageContext;
-import javax.xml.ws.handler.soap.SOAPMessageContext;
import org.jboss.logging.Logger;
import org.jboss.ws.core.jaxws.handler.GenericSOAPHandler;
-public class LifecycleHandler extends GenericSOAPHandler
+public abstract class LifecycleHandler extends GenericSOAPHandler
{
private static Logger log = Logger.getLogger(LifecycleHandler.class);
Modified:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/SOAPEndpointBean.java
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/SOAPEndpointBean.java 2007-03-15
13:47:10 UTC (rev 2623)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/SOAPEndpointBean.java 2007-03-15
16:08:22 UTC (rev 2624)
@@ -23,11 +23,14 @@
// $Id$
+import javax.annotation.Resource;
import javax.jws.HandlerChain;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
import org.jboss.logging.Logger;
@@ -37,11 +40,22 @@
public class SOAPEndpointBean
{
private static Logger log = Logger.getLogger(SOAPEndpointBean.class);
+
+ @Resource
+ public WebServiceContext wsContext;
@WebMethod
public String echo(String msg)
{
log.info("echo: " + msg);
+
+ MessageContext msgContext = wsContext.getMessageContext();
+ if (msgContext.get("server-handler-prop") != null)
+ throw new IllegalStateException("Found server-handler-prop");
+
+ if (msgContext.get("server-app-prop") != Boolean.TRUE)
+ throw new IllegalStateException("Cannot find server-app-prop");
+
return msg;
}
}
Added:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ServerHandler.java
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ServerHandler.java
(rev 0)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ServerHandler.java 2007-03-15
16:08:22 UTC (rev 2624)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.handlerlifecycle;
+
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.MessageContext.Scope;
+
+public class ServerHandler extends LifecycleHandler
+{
+ @Override
+ public boolean handleInbound(MessageContext msgContext)
+ {
+ // set a handler prop
+ msgContext.put("server-handler-prop", Boolean.TRUE);
+
+ // set a app prop
+ msgContext.put("server-app-prop", Boolean.TRUE);
+ msgContext.setScope("server-app-prop", Scope.APPLICATION);
+
+ return super.handleInbound(msgContext);
+ }
+
+ @Override
+ public boolean handleOutbound(MessageContext msgContext)
+ {
+ if (msgContext.get("server-handler-prop") != Boolean.TRUE)
+ throw new IllegalStateException("Cannot find server-handler-prop");
+
+ // The response context should not contain this
+ if (msgContext.get("server-app-prop") != null)
+ throw new IllegalStateException("Found server-app-prop");
+
+ return super.handleOutbound(msgContext);
+ }
+}
Property changes on:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ServerHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ServletClient.java
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ServletClient.java 2007-03-15
13:47:10 UTC (rev 2623)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/ServletClient.java 2007-03-15
16:08:22 UTC (rev 2624)
@@ -26,11 +26,13 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.xml.ws.BindingProvider;
import javax.xml.ws.WebServiceRef;
import org.jboss.logging.Logger;
@@ -41,7 +43,7 @@
@WebServiceRef(wsdlLocation =
"http://localhost:8080/jaxws-handlerlifecycle/soap?wsdl")
public static SOAPEndpoint port;
-
+
@WebServiceRef(wsdlLocation =
"http://localhost:8080/jaxws-handlerlifecycle/tracker?wsdl")
private TrackerEndpoint trackerPort;
@@ -51,8 +53,8 @@
try
{
String methodName = req.getParameter("method");
- Method method = getClass().getMethod(methodName, new Class[]{});
- method.invoke(this, new Object[]{});
+ Method method = getClass().getMethod(methodName, new Class[] {});
+ method.invoke(this, new Object[] {});
message = "pass";
}
catch (InvocationTargetException ex)
@@ -65,38 +67,51 @@
log.error(ex);
message = ex.toString();
}
-
+
res.getWriter().println(message);
}
public void testClientAccess() throws Exception
{
+ Map<String, Object> reqContext =
((BindingProvider)port).getRequestContext();
+ Map<String, Object> resContext =
((BindingProvider)port).getResponseContext();
+ reqContext.put("client-req-prop", Boolean.TRUE);
+
String retStr = port.echo("hello");
assertEquals("hello", retStr);
+
+ assertNull(resContext.get("client-handler-prop"));
+ assertEquals(Boolean.TRUE, resContext.get("client-res-prop"));
}
-
+
public void testTrackerMessages() throws Exception
{
String retStr = HandlerTracker.getListMessages();
assertEquals("[ClientHandler:PostConstruct, ClientHandler:OutBound,
ClientHandler:InBound, ClientHandler:Close]", retStr);
-
+
retStr = trackerPort.getListMessages();
assertEquals("[ServerHandler:PostConstruct, ServerHandler:InBound,
ServerHandler:OutBound, ServerHandler:Close]", retStr);
-
+
}
public void testClearTrackerData() throws Exception
{
HandlerTracker.clearListMessages();
trackerPort.clearListMessages();
-
+
assertEquals("[]", HandlerTracker.getListMessages());
assertEquals("[]", trackerPort.getListMessages());
}
- private void assertEquals(String exp, String was)
+ private void assertEquals(Object exp, Object was)
{
if (exp.equals(was) == false)
throw new RuntimeException("Expected <" + exp + "> but was
<" + was + ">");
}
+
+ private void assertNull(Object object)
+ {
+ if (object != null)
+ throw new RuntimeException("Expected null");
+ }
}
Modified:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/jaxws-client-handlers.xml
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/jaxws-client-handlers.xml 2007-03-15
13:47:10 UTC (rev 2623)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/jaxws-client-handlers.xml 2007-03-15
16:08:22 UTC (rev 2624)
@@ -8,7 +8,7 @@
<handler-chain>
<handler>
<handler-name> ClientHandler </handler-name>
- <handler-class> org.jboss.test.ws.jaxws.handlerlifecycle.LifecycleHandler
</handler-class>
+ <handler-class> org.jboss.test.ws.jaxws.handlerlifecycle.ClientHandler
</handler-class>
</handler>
</handler-chain>
Modified:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/jaxws-server-handlers.xml
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/jaxws-server-handlers.xml 2007-03-15
13:47:10 UTC (rev 2623)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/handlerlifecycle/jaxws-server-handlers.xml 2007-03-15
16:08:22 UTC (rev 2624)
@@ -8,7 +8,7 @@
<handler-chain>
<handler>
<handler-name> ServerHandler </handler-name>
- <handler-class> org.jboss.test.ws.jaxws.handlerlifecycle.LifecycleHandler
</handler-class>
+ <handler-class> org.jboss.test.ws.jaxws.handlerlifecycle.ServerHandler
</handler-class>
</handler>
</handler-chain>