Author: rott
Date: Mon May 11 21:03:18 2009
New Revision: 773696
URL: http://svn.apache.org/viewvc?rev=773696&view=rev
Log:
Improvement to SVN commit 702617; client apps should be able to share session cookies among
binding provider instances for async and async callback, not just sync.
Added:
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DispatchSharedSessionTest.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/proxy/ProxySharedSessionTest.java
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java?rev=773696&r1=773695&r2=773696&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
Mon May 11 21:03:18 2009
@@ -143,26 +143,8 @@
initMessageContext(obj, requestMsgCtx);
- /*
- * if SESSION_MAINTAIN_PROPERTY is true, and the client app has explicitly set
a HEADER_COOKIE on the request context, assume the client
- * app is expecting the HEADER_COOKIE to be the session id. If we were establishing
a new session, no cookie would be sent, and the
- * server would reply with a "Set-Cookie" header, which is copied as a "Cookie"-keyed
property to the service context during response.
- * In this case, if we succeed in using an existing server session, no "Set-Cookie"
header will be returned, and therefore no
- * "Cookie"-keyed property would be set on the service context. So, let's copy
our request context HEADER_COOKIE key to the service
- * context now to prevent the "no cookie" exception in BindingProvider.setupSessionContext.
It is possible the server does not support
- * sessions, in which case no error occurs, but the client app would assume it
is participating in a session.
- */
- if ((requestContext.containsKey(BindingProvider.SESSION_MAINTAIN_PROPERTY)) &&
((Boolean)requestContext.get(BindingProvider.SESSION_MAINTAIN_PROPERTY))) {
- if ((requestContext.containsKey(HTTPConstants.HEADER_COOKIE)) &&
(requestContext.get(HTTPConstants.HEADER_COOKIE) != null)) {
- if (invocationContext.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE)
== null) {
- invocationContext.getServiceClient().getServiceContext().setProperty(HTTPConstants.HEADER_COOKIE,
requestContext.get(HTTPConstants.HEADER_COOKIE));
- if (log.isDebugEnabled()) {
- log.debug("Client-app defined Cookie property (assume to be session
cookie) on request context copied to service context." +
- " Caution: server may or may not support sessions,
but client app will not be informed when not supported.");
- }
- }
- }
- }
+ // call common init method for all invoke* paths
+ preInvokeInit(invocationContext);
// Migrate the properties from the client request context bag to
// the request MessageContext.
@@ -270,6 +252,9 @@
initMessageContext(obj, requestMsgCtx);
+ // call common init method for all invoke* paths
+ preInvokeInit(invocationContext);
+
// Migrate the properties from the client request context bag to
// the request MessageContext.
ApplicationContextMigratorUtil.performMigrationToMessageContext(
@@ -335,6 +320,9 @@
initMessageContext(obj, requestMsgCtx);
+ // call common init method for all invoke* paths
+ preInvokeInit(invocationContext);
+
// Migrate the properties from the client request context bag to
// the request MessageContext.
ApplicationContextMigratorUtil.performMigrationToMessageContext(
@@ -411,6 +399,9 @@
initMessageContext(obj, requestMsgCtx);
+ // call common init method for all invoke* paths
+ preInvokeInit(invocationContext);
+
// Migrate the properties from the client request context bag to
// the request MessageContext.
ApplicationContextMigratorUtil.performMigrationToMessageContext(
@@ -589,4 +580,27 @@
}
return requestMsg;
}
+
+ private void preInvokeInit(InvocationContext requestIC) {
+ /*
+ * if SESSION_MAINTAIN_PROPERTY is true, and the client app has explicitly set a
HEADER_COOKIE on the request context, assume the client
+ * app is expecting the HEADER_COOKIE to be the session id. If we were establishing
a new session, no cookie would be sent, and the
+ * server would reply with a "Set-Cookie" header, which is copied as a "Cookie"-keyed
property to the service context during response.
+ * In this case, if we succeed in using an existing server session, no "Set-Cookie"
header will be returned, and therefore no
+ * "Cookie"-keyed property would be set on the service context. So, let's copy our
request context HEADER_COOKIE key to the service
+ * context now to prevent the "no cookie" exception in BindingProvider.setupSessionContext.
It is possible the server does not support
+ * sessions, in which case no error occurs, but the client app would assume it is
participating in a session.
+ */
+ if ((requestContext.containsKey(BindingProvider.SESSION_MAINTAIN_PROPERTY)) &&
((Boolean)requestContext.get(BindingProvider.SESSION_MAINTAIN_PROPERTY))) {
+ if ((requestContext.containsKey(HTTPConstants.HEADER_COOKIE)) && (requestContext.get(HTTPConstants.HEADER_COOKIE)
!= null)) {
+ if (requestIC.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE)
== null) {
+ requestIC.getServiceClient().getServiceContext().setProperty(HTTPConstants.HEADER_COOKIE,
requestContext.get(HTTPConstants.HEADER_COOKIE));
+ if (log.isDebugEnabled()) {
+ log.debug("Client-app defined Cookie property (assume to be session
cookie) on request context copied to service context." +
+ " Caution: server may or may not support sessions, but
client app will not be informed when not supported.");
+ }
+ }
+ }
+ }
+ }
}
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DispatchSharedSessionTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DispatchSharedSessionTest.java?rev=773696&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DispatchSharedSessionTest.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DispatchSharedSessionTest.java
Mon May 11 21:03:18 2009
@@ -0,0 +1,125 @@
+/*
+ * 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 org.apache.axis2.jaxws.client.dispatch;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Response;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.ws.wsaddressing.W3CEndpointReference;
+import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
+
+import org.apache.axis2.jaxws.addressing.SubmissionEndpointReferenceBuilder;
+import org.apache.axis2.jaxws.client.InterceptableClientTestCase;
+import org.apache.axis2.jaxws.client.TestClientInvocationController;
+import org.apache.axis2.jaxws.core.InvocationContext;
+import org.apache.axis2.transport.http.HTTPConstants;
+
+
+public class DispatchSharedSessionTest extends InterceptableClientTestCase {
+
+ private W3CEndpointReference w3cEPR;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ W3CEndpointReferenceBuilder w3cBuilder = new W3CEndpointReferenceBuilder();
+ w3cBuilder = w3cBuilder.address("http://somewhere.com/somehow");
+ w3cBuilder = w3cBuilder.serviceName(new QName("http://test", "TestService"));
+ w3cBuilder = w3cBuilder.endpointName(new QName("http://test", "TestPort"));
+ w3cEPR = w3cBuilder.build();
+
+ SubmissionEndpointReferenceBuilder subBuilder = new SubmissionEndpointReferenceBuilder();
+ subBuilder = subBuilder.address("http://somewhere.com/somehow");
+ subBuilder = subBuilder.serviceName(new QName("http://test", "TestService"));
+ subBuilder = subBuilder.endpointName(new QName("http://test", "TestPort"));
+ subBuilder.build();
+ }
+
+ public void testSharedSessionDispatch() {
+ Service svc = Service.create(new QName("http://test", "TestService"));
+ svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_BINDING,
"http://localhost");
+ Dispatch<Source> d = svc.createDispatch(w3cEPR, Source.class, Service.Mode.PAYLOAD);
+
+ d.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+ d.getRequestContext().put(HTTPConstants.COOKIE_STRING, "MyCookie");
+
+ d.invoke(null);
+
+ TestClientInvocationController testController = getInvocationController();
+ InvocationContext ic = testController.getInvocationContext();
+ testController.invoke(ic);
+
+ assertNotNull("Invocation of the proxy object should have caused COOKIE_STRING keyed
property to be on the ServiceContext", ic.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE));
+
+ }
+
+ public void testSharedSessionDispatchAsync() {
+ Service svc = Service.create(new QName("http://test", "TestService"));
+ svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_BINDING,
"http://localhost");
+ Dispatch<Source> d = svc.createDispatch(w3cEPR, Source.class, Service.Mode.PAYLOAD);
+
+ d.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+ d.getRequestContext().put(HTTPConstants.COOKIE_STRING, "MyCookie");
+
+ d.invokeAsync(null);
+
+ TestClientInvocationController testController = getInvocationController();
+ InvocationContext ic = testController.getInvocationContext();
+ testController.invoke(ic);
+
+ assertNotNull("Invocation of the proxy object should have caused COOKIE_STRING keyed
property to be on the ServiceContext", ic.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE));
+
+ }
+
+ public void testSharedSessionDispatchAsyncCallback() {
+ Service svc = Service.create(new QName("http://test", "TestService"));
+ svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_BINDING,
"http://localhost");
+ Dispatch<Source> d = svc.createDispatch(w3cEPR, Source.class, Service.Mode.PAYLOAD);
+
+ d.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+ d.getRequestContext().put(HTTPConstants.COOKIE_STRING, "MyCookie");
+
+ d.invokeAsync(null, new DummyAsyncHandler());
+
+ TestClientInvocationController testController = getInvocationController();
+ InvocationContext ic = testController.getInvocationContext();
+ testController.invoke(ic);
+
+ assertNotNull("Invocation of the proxy object should have caused COOKIE_STRING keyed
property to be on the ServiceContext", ic.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE));
+
+ }
+
+ public class DummyResponse {}
+
+ public class DummyAsyncHandler implements AsyncHandler<Source> {
+
+ public void handleResponse(Response<Source> arg0) {
+
+ }
+
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/proxy/ProxySharedSessionTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/proxy/ProxySharedSessionTest.java?rev=773696&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/proxy/ProxySharedSessionTest.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/proxy/ProxySharedSessionTest.java
Mon May 11 21:03:18 2009
@@ -0,0 +1,153 @@
+/*
+ * 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 org.apache.axis2.jaxws.client.proxy;
+
+import java.util.concurrent.Future;
+
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Response;
+import javax.xml.ws.Service;
+import javax.xml.ws.wsaddressing.W3CEndpointReference;
+import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.jaxws.TestLogger;
+import org.apache.axis2.jaxws.addressing.SubmissionEndpointReference;
+import org.apache.axis2.jaxws.addressing.SubmissionEndpointReferenceBuilder;
+import org.apache.axis2.jaxws.client.InterceptableClientTestCase;
+import org.apache.axis2.jaxws.client.TestClientInvocationController;
+import org.apache.axis2.jaxws.core.InvocationContext;
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.test.faults.FaultyWebServiceResponse;
+
+/**
+ * Testing shared session property
+ */
+public class ProxySharedSessionTest extends InterceptableClientTestCase {
+ private static final OMFactory OMF = OMAbstractFactory.getOMFactory();
+
+ private W3CEndpointReference w3cEPR;
+ private SubmissionEndpointReference subEPR;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ W3CEndpointReferenceBuilder w3cBuilder = new W3CEndpointReferenceBuilder();
+ w3cBuilder = w3cBuilder.address("http://somewhere.com/somehow");
+ w3cBuilder = w3cBuilder.serviceName(new QName("http://test", "ProxySessionService"));
+ w3cBuilder = w3cBuilder.endpointName(new QName("http://test", "TestPort"));
+ w3cEPR = w3cBuilder.build();
+
+ SubmissionEndpointReferenceBuilder subBuilder = new SubmissionEndpointReferenceBuilder();
+ subBuilder = subBuilder.address("http://somewhere.com/somehow");
+ subBuilder = subBuilder.serviceName(new QName("http://test", "ProxySessionService"));
+ subBuilder = subBuilder.endpointName(new QName("http://test", "TestPort"));
+ subEPR = subBuilder.build();
+ }
+
+
+ public void testCookieCopiedToServiceContext() {
+ Service svc = Service.create(new QName("http://test", "ProxySessionService"));
+ ProxySessionService proxy = svc.getPort(ProxySessionService.class);
+ assertNotNull(proxy);
+
+ BindingProvider p = (BindingProvider)proxy;
+ p.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+ p.getRequestContext().put(HTTPConstants.COOKIE_STRING, "MyCookie");
+
+ proxy.doSomething("12345");
+
+ TestClientInvocationController testController = getInvocationController();
+ InvocationContext ic = testController.getInvocationContext();
+ assertNotNull("Invocation of the proxy object should have caused COOKIE_STRING keyed
property to be on the ServiceContext", ic.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE));
+
+ }
+
+
+ public void testCookieCopiedToServiceContextAsync() {
+ Service svc = Service.create(new QName("http://test", "ProxySessionService"));
+ ProxySessionService proxy = svc.getPort(ProxySessionService.class);
+ assertNotNull(proxy);
+
+ BindingProvider p = (BindingProvider)proxy;
+ p.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+ p.getRequestContext().put(HTTPConstants.COOKIE_STRING, "MyCookie");
+
+ proxy.doSomethingAsync("12345");
+
+ TestClientInvocationController testController = getInvocationController();
+ InvocationContext ic = testController.getInvocationContext();
+ testController.invoke(ic);
+
+ assertNotNull("Invocation of the proxy object should have caused COOKIE_STRING keyed
property to be on the ServiceContext", ic.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE));
+
+ }
+
+ public void testCookieCopiedToServiceContextAsyncCallback() {
+ Service svc = Service.create(new QName("http://test", "ProxySessionService"));
+ ProxySessionService proxy = svc.getPort(ProxySessionService.class);
+ assertNotNull(proxy);
+
+ BindingProvider p = (BindingProvider)proxy;
+ p.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
+ p.getRequestContext().put(HTTPConstants.COOKIE_STRING, "MyCookie");
+
+ proxy.doSomethingAsync("12345", new DummyAsyncHandler());
+
+ TestClientInvocationController testController = getInvocationController();
+ InvocationContext ic = testController.getInvocationContext();
+ testController.invoke(ic);
+
+ assertNotNull("Invocation of the proxy object should have caused COOKIE_STRING keyed
property to be on the ServiceContext", ic.getServiceClient().getServiceContext().getProperty(HTTPConstants.HEADER_COOKIE));
+
+ }
+
+
+
+ @WebService()
+ public interface ProxySessionService {
+
+ public String doSomething(String id);
+
+ public Future<?> doSomethingAsync(String id, AsyncHandler<DummyResponse>
asyncHandler);
+
+ public Response<DummyResponse> doSomethingAsync(String id);
+
+ }
+
+ public class DummyResponse {}
+
+ public class DummyAsyncHandler implements AsyncHandler<DummyResponse> {
+
+ public void handleResponse(Response<DummyResponse> arg0) {
+
+ }
+
+ }
+
+}
|