Author: ningjiang
Date: Sun Jul 6 22:05:24 2008
New Revision: 674401
URL: http://svn.apache.org/viewvc?rev=674401&view=rev
Log:
CAMEL-666 added SessionSupport option in the camel-jetty component
Modified:
activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java
Modified:
activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=674401&r1=674400&r2=674401&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
(original)
+++
activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
Sun Jul 6 22:05:24 2008
@@ -33,12 +33,15 @@
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.HashSessionIdManager;
+import org.mortbay.jetty.servlet.HashSessionManager;
import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.SessionHandler;
/**
* An HttpComponent which starts an embedded Jetty for to handle consuming from
* the http endpoints.
- *
+ *
* @version $Revision$
*/
public class JettyHttpComponent extends HttpComponent {
@@ -73,19 +76,22 @@
@Override
protected Endpoint<HttpExchange> createEndpoint(String uri, String
remaining, Map parameters) throws Exception {
URI httpURL = uri.startsWith("jetty:") ? new URI(remaining) : new
URI(uri);
- return new JettyHttpEndpoint(this, uri, httpURL,
getHttpConnectionManager());
+ JettyHttpEndpoint result =
+ new JettyHttpEndpoint(this, uri, httpURL,
getHttpConnectionManager());
+ setProperties(result, parameters);
+ return result;
}
/**
* Connects the URL specified on the endpoint to the specified processor.
- *
+ *
* @throws Exception
*/
@Override
public void connect(HttpConsumer consumer) throws Exception {
// Make sure that there is a connector for the requested endpoint.
- HttpEndpoint endpoint = (HttpEndpoint)consumer.getEndpoint();
+ JettyHttpEndpoint endpoint = (JettyHttpEndpoint)consumer.getEndpoint();
String connectorKey = endpoint.getProtocol() + ":" +
endpoint.getPort();
synchronized (connectors) {
@@ -99,22 +105,45 @@
}
connector.setPort(endpoint.getPort());
getServer().addConnector(connector);
+ // check the session support
+ if (endpoint.isSessionSupport()) {
+ enableSessionSupport();
+ }
connector.start();
connectorRef = new ConnectorRef(connector);
connectors.put(connectorKey, connectorRef);
} else {
// ref track the connector
connectorRef.increment();
+ // check the session support
+ if (endpoint.isSessionSupport()) {
+ enableSessionSupport();
+ }
}
+
}
camelServlet.connect(consumer);
}
+ private void enableSessionSupport() throws Exception {
+ Context context =
(Context)getServer().getChildHandlerByClass(Context.class);
+ if (context.getSessionHandler() == null) {
+ SessionHandler sessionHandler = new SessionHandler();
+ context.setSessionHandler(sessionHandler);
+ if (context.isStarted()) {
+ // restart the context
+ context.stop();
+ context.start();
+ }
+ }
+
+ }
+
/**
* Disconnects the URL specified on the endpoint from the specified
* processor.
- *
+ *
* @throws Exception
*/
@Override
@@ -166,13 +195,13 @@
public void setSslPassword(String sslPassword) {
this.sslPassword = sslPassword;
}
-
+
public void setKeystore(String sslKeystore) {
- this.sslKeystore = sslKeystore;
+ this.sslKeystore = sslKeystore;
}
-
+
public String getKeystore() {
- return sslKeystore;
+ return sslKeystore;
}
public synchronized SslSocketConnector getSslSocketConnector() {
@@ -188,11 +217,11 @@
}
return sslSocketConnector;
}
-
+
public void setSslSocketConnector(SslSocketConnector connector) {
sslSocketConnector = connector;
}
-
+
// Implementation methods
//
-------------------------------------------------------------------------
Modified:
activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java?rev=674401&r1=674400&r2=674401&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
(original)
+++
activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
Sun Jul 6 22:05:24 2008
@@ -34,6 +34,7 @@
*/
public class JettyHttpEndpoint extends HttpEndpoint {
private JettyHttpComponent component;
+ private boolean sessionSupport;
public JettyHttpEndpoint(JettyHttpComponent component, String uri, URI
httpURL, HttpConnectionManager httpConnectionManager) throws URISyntaxException
{
super(uri, component, httpURL, httpConnectionManager);
@@ -60,4 +61,12 @@
public JettyHttpComponent getComponent() {
return component;
}
+
+ public void setSessionSupport(boolean support) {
+ sessionSupport = support;
+ }
+
+ public boolean isSessionSupport() {
+ return sessionSupport;
+ }
}
Modified:
activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java?rev=674401&r1=674400&r2=674401&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java
(original)
+++
activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java
Sun Jul 6 22:05:24 2008
@@ -23,11 +23,14 @@
import java.util.List;
import java.util.Map;
+import javax.servlet.http.HttpSession;
+
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpExchange;
import org.apache.camel.component.mock.MockEndpoint;
/**
@@ -68,9 +71,9 @@
String data = new String(os.toByteArray());
assertEquals("<b>Hello World</b>", data);
-
+
}
-
+
protected void invokeHttpEndpoint() throws IOException {
template.sendBodyAndHeader("http://localhost:8080/test", expectedBody,
"Content-Type", "application/xml");
}
@@ -83,10 +86,17 @@
Processor proc = new Processor() {
public void process(Exchange exchange) throws Exception {
+ try {
+ HttpSession session =
+
((HttpExchange)exchange).getRequest().getSession();
+ assertNotNull("we should get session here",
session);
+ } catch (Exception e) {
+ exchange.getFault().setBody(e);
+ }
exchange.getOut(true).setBody("<b>Hello World</b>");
}
};
- from("jetty:http://localhost:8080/hello").process(proc);
+
from("jetty:http://localhost:8080/hello?sessionSupport=true").process(proc);
}
};
}