You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2007/06/28 11:36:47 UTC

svn commit: r551517 - in /incubator/cxf/trunk: rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/ systests/src/test/java/org/apache/cxf/systest/http/

Author: ningjiang
Date: Thu Jun 28 02:36:46 2007
New Revision: 551517

URL: http://svn.apache.org/viewvc?view=rev&rev=551517
Log:
CXF-750 support using session in standalone mode

Added:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/SessionServer.java   (with props)
Modified:
    incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java

Modified: incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java?view=diff&rev=551517&r1=551516&r2=551517
==============================================================================
--- incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java (original)
+++ incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java Thu Jun 28 02:36:46 2007
@@ -36,6 +36,9 @@
 import org.mortbay.jetty.handler.ContextHandler;
 import org.mortbay.jetty.handler.ContextHandlerCollection;
 import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.servlet.HashSessionIdManager;
+import org.mortbay.jetty.servlet.HashSessionManager;
+import org.mortbay.jetty.servlet.SessionHandler;
 import org.mortbay.thread.BoundedThreadPool;
 
 
@@ -196,6 +199,14 @@
         ContextHandler context = new ContextHandler();
         context.setContextPath(contextName);
         context.setHandler(handler);
+        // just add the session manager here by code
+        // TODO adding the configuration support for session manager
+        HashSessionManager sessionManager = new HashSessionManager();
+        SessionHandler sessionHandler = new SessionHandler(sessionManager);
+        HashSessionIdManager idManager = new HashSessionIdManager();
+        sessionManager.setIdManager(idManager);
+        context.addHandler(sessionHandler);
+        
         contexts.addHandler(context);
         if (contexts.isStarted()) {           
             try {                

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java?view=auto&rev=551517
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java Thu Jun 28 02:36:46 2007
@@ -0,0 +1,97 @@
+/**
+ * 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.cxf.systest.http;
+
+import java.lang.reflect.UndeclaredThrowableException;
+
+import javax.xml.ws.BindingProvider;
+
+import org.apache.cxf.greeter_control.Greeter;
+import org.apache.cxf.greeter_control.GreeterService;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ClientServerSessionTest extends AbstractBusClientServerTestBase {
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly",
+                   launchServer(SessionServer.class));
+    }
+    
+    
+    @Test    
+    public void testInvocationWithSession() throws Exception {
+
+        GreeterService service = new GreeterService();
+        assertNotNull(service);
+
+        try {
+            Greeter greeter = service.getGreeterPort();
+            ((BindingProvider)greeter).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,
+                                                                   true);
+            String greeting = greeter.greetMe("Bonjour");
+            
+            assertNotNull("no response received from service", greeting);
+            assertEquals("Hello Bonjour", greeting);
+            
+            greeting = greeter.greetMe("Hello");
+            assertNotNull("no response received from service", greeting);
+            assertEquals("Hello Bonjour", greeting);
+            
+            
+            greeting = greeter.greetMe("NiHao");
+            assertNotNull("no response received from service", greeting);
+            assertEquals("Hello Hello", greeting);
+
+        } catch (UndeclaredThrowableException ex) {
+            throw (Exception)ex.getCause();
+        }
+    }
+    
+    @Test    
+    public void testInvocationWithoutSession() throws Exception {
+
+        GreeterService service = new GreeterService();
+        assertNotNull(service);
+
+        try {
+            Greeter greeter = service.getGreeterPort();
+
+            String greeting = greeter.greetMe("Bonjour");
+            
+            assertNotNull("no response received from service", greeting);
+            assertEquals("Hello Bonjour", greeting);
+            
+            greeting = greeter.greetMe("Hello");
+            assertNotNull("no response received from service", greeting);
+            assertEquals("Hello Hello", greeting);
+            
+            
+            greeting = greeter.greetMe("NiHao");
+            assertNotNull("no response received from service", greeting);
+            assertEquals("Hello NiHao", greeting);
+
+        } catch (UndeclaredThrowableException ex) {
+            throw (Exception)ex.getCause();
+        }
+    }
+    
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/ClientServerSessionTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java?view=auto&rev=551517
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java Thu Jun 28 02:36:46 2007
@@ -0,0 +1,124 @@
+/**
+ * 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.cxf.systest.http;
+
+import java.util.concurrent.Future;
+import java.util.logging.Logger;
+
+import javax.annotation.Resource;
+import javax.jws.WebService;
+import javax.servlet.http.HttpSession;
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.MessageContext;
+
+import org.apache.cxf.greeter_control.Greeter;
+import org.apache.cxf.greeter_control.types.GreetMeResponse;
+import org.apache.cxf.greeter_control.types.PingMeResponse;
+import org.apache.cxf.greeter_control.types.SayHiResponse;
+
+@WebService(serviceName = "GreeterService",
+            portName = "GreeterPort",
+            endpointInterface = "org.apache.cxf.greeter_control.Greeter", 
+            targetNamespace = "http://cxf.apache.org/greeter_control")
+public class GreeterSessionImpl implements Greeter {
+    private static final Logger LOG = 
+        Logger.getLogger(GreeterSessionImpl.class.getPackage().getName());
+    
+    @Resource
+    private WebServiceContext context;
+    
+    // greetMe will use session to return last called name
+    public String greetMe(String me) {
+        LOG.info("Executing operation greetMe");        
+        LOG.info("Message received: " + me);
+        MessageContext mc = context.getMessageContext();
+        HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST))
+            .getSession();
+        // Get a session property "counter" from context
+        if (session == null) {
+            throw new WebServiceException("No session in WebServiceContext");
+        }
+        String name = (String)session.getAttribute("name");
+        if (name == null) {
+            name = me;
+            LOG.info("Starting the Session");
+        } 
+        
+        session.setAttribute("name", me);
+        
+        return "Hello " + name;
+    }
+    
+
+    public String sayHi() {
+        LOG.info("Executing operation sayHi");
+        
+        return "Bonjour ";
+    }
+    
+    public void pingMe() {
+    }
+
+
+    public Future<?> greetMeAsync(String requestType, AsyncHandler<GreetMeResponse> asyncHandler) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Response<GreetMeResponse> greetMeAsync(String requestType) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public void greetMeOneWay(String requestType) {
+        // TODO Auto-generated method stub
+        
+    }
+
+
+    public Future<?> pingMeAsync(AsyncHandler<PingMeResponse> asyncHandler) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Response<PingMeResponse> pingMeAsync() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Future<?> sayHiAsync(AsyncHandler<SayHiResponse> asyncHandler) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Response<SayHiResponse> sayHiAsync() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/GreeterSessionImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/SessionServer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/SessionServer.java?view=auto&rev=551517
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/SessionServer.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/SessionServer.java Thu Jun 28 02:36:46 2007
@@ -0,0 +1,50 @@
+/**
+ * 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.cxf.systest.http;
+
+import javax.xml.ws.Endpoint;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+public class SessionServer extends AbstractBusTestServerBase {
+
+    @Override
+    protected void run() {
+        Object implementor;
+        String address;
+        
+        implementor = new GreeterSessionImpl();
+        address = "http://localhost:9020/SoapContext/GreeterPort";
+        Endpoint.publish(address, implementor);
+        
+    }
+    
+    public static void main(String[] args) {
+        try {
+            SessionServer s = new SessionServer();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/SessionServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/SessionServer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date