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 ng...@apache.org on 2006/10/31 08:47:51 UTC

svn commit: r469400 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: ./ client/ client/proxy/ core/ core/controller/ i18n/

Author: ngallardo
Date: Mon Oct 30 23:47:50 2006
New Revision: 469400

URL: http://svn.apache.org/viewvc?view=rev&rev=469400
Log:
AXIS2-1554
Contributor: Samuel Isokpunwu

Sam's patch for adding in the client side portion of JAX-WS session mgmt.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java?view=diff&rev=469400&r1=469399&r2=469400
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java Mon Oct 30 23:47:50 2006
@@ -1,18 +1,20 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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
- *
+ * 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.
+ *      
+ * 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;
@@ -23,6 +25,8 @@
 import javax.xml.ws.Binding;
 
 import org.apache.axis2.jaxws.binding.SOAPBinding;
+import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.transport.http.HTTPConstants;
 
 public class BindingProvider implements javax.xml.ws.BindingProvider {
 
@@ -67,5 +71,47 @@
 			getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY,
 					soapAction);
 		}
+    }
+    
+    /*
+     * Ensure that the next request context contains the session value returned
+     * from previous request
+     */
+    protected void setupSessionContext(Map<String, Object> properties){
+        String sessionKey = null;
+        String sessionValue = null;
+        
+        if(properties == null){
+            return;
+        }
+
+        if(properties.containsKey(HTTPConstants.HEADER_LOCATION)){
+            sessionKey = HTTPConstants.HEADER_LOCATION;
+            sessionValue = (String)properties.get(sessionKey);
+            if(sessionValue != null && !"".equals(sessionValue)){
+                requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,sessionValue);
+            }
+        }
+        else if(properties.containsKey(HTTPConstants.HEADER_COOKIE)){
+            sessionKey = HTTPConstants.HEADER_COOKIE;
+            sessionValue = (String)properties.get(sessionKey);
+            if(sessionValue != null && !"".equals(sessionValue)){
+                requestContext.put(HTTPConstants.COOKIE_STRING,sessionValue);
+            }
+        }
+        else if(properties.containsKey(HTTPConstants.HEADER_COOKIE2)){
+            sessionKey = HTTPConstants.HEADER_COOKIE2;
+            sessionValue = (String)properties.get(sessionKey);
+            if(sessionValue != null && !"".equals(sessionValue)){
+                requestContext.put(HTTPConstants.COOKIE_STRING,sessionValue);
+            }
+        }
+        else {
+            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("NoMaintainSessionProperty"));
+        }
+
+        if(sessionValue != null){
+            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("NullValueForMaintainSessionProperty",sessionKey));
+        }
     }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java?view=diff&rev=469400&r1=469399&r2=469400
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java Mon Oct 30 23:47:50 2006
@@ -16,6 +16,7 @@
  */
 package org.apache.axis2.jaxws.client;
 
+import java.util.Map;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Future;
 
@@ -35,11 +36,13 @@
 import org.apache.axis2.jaxws.core.controller.AxisInvocationController;
 import org.apache.axis2.jaxws.core.controller.InvocationController;
 import org.apache.axis2.jaxws.handler.PortData;
+import org.apache.axis2.jaxws.i18n.Messages;
 import org.apache.axis2.jaxws.impl.AsyncListener;
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
 import org.apache.axis2.jaxws.message.XMLFault;
 import org.apache.axis2.jaxws.spi.ServiceDelegate;
+import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -134,6 +137,12 @@
         
         Object returnObj = getValueFromMessage(responseMsg);
         
+        //Check to see if we need to maintain session state
+        if (requestMsgCtx.isMaintainSession()) {
+            //TODO: Need to figure out a cleaner way to make this call. 
+            setupSessionContext(invocationContext.getServiceClient().getServiceContext().getProperties());
+        }
+        
         if (log.isDebugEnabled()) {
             log.debug("Synchronous invocation completed: BaseDispatch.invoke()");
         }
@@ -171,6 +180,12 @@
        
         // Send the request using the InvocationController
         ic.invokeOneWay(invocationContext);
+        
+        //Check to see if we need to maintain session state
+        if (requestMsgCtx.isMaintainSession()) {
+            //TODO: Need to figure out a cleaner way to make this call. 
+            setupSessionContext(invocationContext.getServiceClient().getServiceContext().getProperties());
+        }
        
         if (log.isDebugEnabled()) {
             log.debug("One-way invocation completed: BaseDispatch.invokeOneWay()");
@@ -220,6 +235,12 @@
         
         // Send the request using the InvocationController
         Future<?> asyncResponse = ic.invokeAsync(invocationContext, asynchandler);
+        
+        //Check to see if we need to maintain session state
+        if (requestMsgCtx.isMaintainSession()) {
+            //TODO: Need to figure out a cleaner way to make this call. 
+            setupSessionContext(invocationContext.getServiceClient().getServiceContext().getProperties());
+        }
         
         if (log.isDebugEnabled()) {
             log.debug("Asynchronous (callback) invocation sent: BaseDispatch.invokeAsync()");

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java?view=diff&rev=469400&r1=469399&r2=469400
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java Mon Oct 30 23:47:50 2006
@@ -1,24 +1,27 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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
- *
+ * 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.
+ *      
+ * 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.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.Map;
 import java.util.concurrent.Future;
 
 import javax.jws.soap.SOAPBinding;
@@ -48,11 +51,10 @@
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.spi.ServiceDelegate;
 import org.apache.axis2.jaxws.util.WSDLWrapper;
+import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-// import com.sun.xml.bind.v2.runtime.reflect.Lister;
-
 /**
  * ProxyHandler is the java.lang.reflect.InvocationHandler implementation.
  * When jaxws client calls the method on proxy object that it gets using the getPort
@@ -188,6 +190,12 @@
 				log.debug("OneWay Call");
 			}
 			controller.invokeOneWay(requestIC);
+			
+            //Check to see if we need to maintain session state
+            if (requestContext.isMaintainSession()) {
+                //TODO: Need to figure out a cleaner way to make this call. 
+                setupSessionContext(requestIC.getServiceClient().getServiceContext().getProperties());
+            }
 		}
 		
 		if(method.getReturnType().isAssignableFrom(Future.class)){
@@ -208,7 +216,16 @@
 			AsyncListener listener = createProxyListener(args);
 			requestIC.setAsyncListener(listener);
 			requestIC.setExecutor(delegate.getExecutor());
-			return controller.invokeAsync(requestIC, asyncHandler);
+				        
+	        Future<?> future = controller.invokeAsync(requestIC, asyncHandler);
+	        
+            //Check to see if we need to maintain session state
+            if (requestContext.isMaintainSession()) {
+                //TODO: Need to figure out a cleaner way to make this call. 
+                setupSessionContext(requestIC.getServiceClient().getServiceContext().getProperties());
+            }
+	        
+	        return future;
 		}
 		
 		if(method.getReturnType().isAssignableFrom(Response.class)){
@@ -218,12 +235,27 @@
 			AsyncListener listener = createProxyListener(args);
 			requestIC.setAsyncListener(listener);
 			requestIC.setExecutor(delegate.getExecutor());
-			return controller.invokeAsync(requestIC);
+	        
+			Response response = controller.invokeAsync(requestIC);
+			
+            //Check to see if we need to maintain session state
+            if (requestContext.isMaintainSession()) {
+                //TODO: Need to figure out a cleaner way to make this call. 
+                setupSessionContext(requestIC.getServiceClient().getServiceContext().getProperties());
+            }
+	        
+	        return response;
 		}
 		
 		if(!operationDesc.isOneWay()){
 			InvocationContext responseIC = controller.invoke(requestIC);
 		
+            //Check to see if we need to maintain session state
+            if (requestContext.isMaintainSession()) {
+                //TODO: Need to figure out a cleaner way to make this call. 
+                setupSessionContext(requestIC.getServiceClient().getServiceContext().getProperties());
+            }
+	        
 			MessageContext responseContext = responseIC.getResponseMessageContext();
 			Object responseObj = createResponse(method, args, responseContext);
 			return responseObj;

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java?view=diff&rev=469400&r1=469399&r2=469400
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java Mon Oct 30 23:47:50 2006
@@ -20,6 +20,7 @@
 import java.util.Map;
 
 import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Service.Mode;
 
 import org.apache.axis2.description.AxisService;
@@ -128,5 +129,20 @@
             return svc.getClassLoader();
         else
             return null;
+    }
+    
+    /**
+     * Used to determine whether or not session state has been enabled.
+     * @return
+     */
+    public boolean isMaintainSession(){
+        boolean maintainSession = false;
+        
+        Boolean value = (Boolean) properties.get(BindingProvider.SESSION_MAINTAIN_PROPERTY);
+        if(value != null && value.booleanValue()){
+            maintainSession = true;
+        }
+
+        return maintainSession;
     }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java?view=diff&rev=469400&r1=469399&r2=469400
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java Mon Oct 30 23:47:50 2006
@@ -1,39 +1,36 @@
 /*
- * Copyright 2006 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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
- *
+ * 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.
+ *      
+ * 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.core.controller;
 
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 
-import javax.activation.DataHandler;
 import javax.xml.namespace.QName;
 import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Response;
 
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMText;
-import org.apache.axiom.om.impl.MTOMConstants;
-import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants.Configuration;
 import org.apache.axis2.addressing.EndpointReference;
@@ -54,10 +51,8 @@
 import org.apache.axis2.jaxws.i18n.Messages;
 import org.apache.axis2.jaxws.impl.AsyncListener;
 import org.apache.axis2.jaxws.impl.AsyncListenerWrapper;
-import org.apache.axis2.jaxws.message.Attachment;
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
-import org.apache.axis2.jaxws.message.attachments.AttachmentUtils;
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
 import org.apache.axis2.jaxws.message.util.MessageUtils;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
@@ -479,6 +474,11 @@
         Message msg = mc.getMessage();
         if (msg.isMTOMEnabled()) {
             ops.setProperty(Configuration.ENABLE_MTOM, "true");
+        }
+        
+        // Enable session management
+        if(mc.isMaintainSession()){
+            ops.setManageSession(true);
         }
         
         // Check to see if BASIC_AUTH is enabled.  If so, make sure

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties?view=diff&rev=469400&r1=469399&r2=469400
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties Mon Oct 30 23:47:50 2006
@@ -116,6 +116,8 @@
 validateUserName=Error: A value must be specified when setting the javax.xml.ws.security.auth.username property.
 validatePassword=Error: A value must be specified when setting the javax.xml.ws.security.auth.password property.
 checkUsernameAndPassword=Error: The javax.xml.ws.security.auth.username user name and the javax.xml.ws.security.auth.password password must be specified.
+NoMaintainSessionProperty=Error: Maintain Session is enabled but none of the Session Properties (Cookies, Over-written URL) is returned.
+NullValueForMaintainSessionProperty=Error: The value of {0} Session property is NULL.
 JAXBBlockFactoryErr1=An internal assertion error occurred.  The context parameter of JAXBBlockFactory should be a JAXBBlockContext object, but a {0} object was found.
 WebServiceContextInjectionImplErr1=Cannot inject Resource on a null Service Instance.
 WebServiceContextInjectionImplErr2=Injection on Private and Protected set methods not supported yet.



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org