You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2012/08/17 09:56:24 UTC
svn commit: r1374169 [1/3] - in /servicemix/components/trunk: ./
bindings/servicemix-cxf-bc/ bindings/servicemix-http/
bindings/servicemix-http/src/main/java/org/apache/servicemix/http/
bindings/servicemix-http/src/main/java/org/apache/servicemix/http/...
Author: ffang
Date: Fri Aug 17 07:56:22 2012
New Revision: 1374169
URL: http://svn.apache.org/viewvc?rev=1374169&view=rev
Log:
[SMXCOMP-939]unify jetty version for JBI components
Modified:
servicemix/components/trunk/bindings/servicemix-cxf-bc/pom.xml
servicemix/components/trunk/bindings/servicemix-http/pom.xml
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/ManagedContextManager.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/AbstractHttpConsumerMarshaler.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/AbstractHttpProviderMarshaler.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerMarshaler.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderMarshaler.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/HttpTimeoutException.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/ContinuationHelper.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JCLLogger.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasJettyPrincipal.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasUserRealm.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/ServiceMixSslSocketConnector.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/SmxHttpExchange.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/CommonsHttpSSLSocketFactory.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
servicemix/components/trunk/bindings/servicemix-http/src/main/resources/OSGI-INF/blueprint/servicemix-http.xml
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/ConsumerEndpointTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/HttpAddressingTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/HttpBridgeServletTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/HttpConsumerTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/HttpProviderTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSoapTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/HttpURITest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/HttpWsdlTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/ProviderEndpointTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/WsdlRoundtripTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/addressing/AddressingConsumerTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshalerTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/HttpConsumerLateResponseHandlingTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/HttpProviderExpirationTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/HttpTimeoutExceptionTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/jetty/ContinuationHelperTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/jetty/JaasUserRealmTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/jetty/SmxHttpExchangeTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java
servicemix/components/trunk/bindings/servicemix-http/src/test/resources/log4j-tests.properties
servicemix/components/trunk/engines/servicemix-jsr181/pom.xml
servicemix/components/trunk/pom.xml
servicemix/components/trunk/shared-libraries/servicemix-common/src/test/java/org/apache/servicemix/common/util/MessageUtilTest.java
Modified: servicemix/components/trunk/bindings/servicemix-cxf-bc/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-cxf-bc/pom.xml?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-cxf-bc/pom.xml (original)
+++ servicemix/components/trunk/bindings/servicemix-cxf-bc/pom.xml Fri Aug 17 07:56:22 2012
@@ -47,7 +47,6 @@
</scm>
<properties>
- <cxf.jetty.version>7.3.1.v20110307</cxf.jetty.version>
<surefire.fork.mode>pertest</surefire.fork.mode>
<servicemix.osgi.import>
@@ -176,7 +175,6 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
- <version>${cxf.jetty.version}</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
@@ -187,12 +185,10 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
- <version>${cxf.jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
- <version>${cxf.jetty.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Modified: servicemix/components/trunk/bindings/servicemix-http/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/pom.xml?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/pom.xml (original)
+++ servicemix/components/trunk/bindings/servicemix-http/pom.xml Fri Aug 17 07:56:22 2012
@@ -52,10 +52,10 @@
org.apache.servicemix.nmr.api.security,
org.apache.woden*;resolution:=optional,
org.apache.xbean.spring.context.v2,
- org.mortbay.jetty.client*;resolution:=optional;version="[6.1.0,6.2.0)",
- org.mortbay*;version="[6.1.0,6.2.0)",
- org.mortbay.jetty.bio;resolution:=optional;version="[6.1.0,6.2.0)",
- org.springframework*;resolution:=optional;version="[2.5,4)",
+ org.eclipse.jetty.client*;resolution:=optional;version="[8.1.0,8.2.0)",
+ org.eclipse*;version="[8.1.0,8.2.0)",
+ org.eclipse.jetty.bio;resolution:=optional;version="[8.1.0,8.2.0)",
+ org.springframework*;resolution:=optional;version="[3.0,)",
sun.misc;resolution:=optional,
*
</servicemix.osgi.import>
@@ -87,37 +87,37 @@
<artifactId>servicemix-shared</artifactId>
</dependency>
<dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>servlet-api-2.5</artifactId>
- </exclusion>
- </exclusions>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-jmx</artifactId>
</dependency>
<dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty-management</artifactId>
- <exclusions>
- <exclusion>
- <groupId>mx4j</groupId>
- <artifactId>mx4j</artifactId>
- </exclusion>
- <exclusion>
- <groupId>mx4j</groupId>
- <artifactId>mx4j-tools</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>servlet-api-2.5</artifactId>
- </exclusion>
- </exclusions>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-client</artifactId>
</dependency>
<dependency>
- <groupId>org.mortbay.jetty</groupId>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-security</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlets</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-continuation</artifactId>
+ </dependency>
<!-- provided -->
<dependency>
@@ -191,6 +191,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jcl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-components</artifactId>
<version>${servicemix.version}</version>
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java Fri Aug 17 07:56:22 2012
@@ -25,9 +25,8 @@ import org.apache.servicemix.common.util
import org.apache.servicemix.common.xbean.BaseXBeanDeployer;
import org.apache.servicemix.http.endpoints.HttpConsumerEndpoint;
import org.apache.servicemix.http.endpoints.HttpProviderEndpoint;
-import org.apache.servicemix.http.jetty.JCLLogger;
import org.apache.servicemix.http.jetty.JettyContextManager;
-import org.mortbay.thread.QueuedThreadPool;
+import org.eclipse.jetty.util.thread.QueuedThreadPool;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.servicedesc.ServiceEndpoint;
@@ -46,14 +45,10 @@ public class HttpComponent extends Defau
public static final String[] EPR_PROTOCOLS = {"http:", "https"};
- static {
- JCLLogger.init();
- }
-
protected ContextManager server;
protected HttpClient client;
protected MultiThreadedHttpConnectionManager connectionManager;
- protected org.mortbay.jetty.client.HttpClient connectionPool;
+ protected org.eclipse.jetty.client.HttpClient connectionPool;
protected HttpConfiguration configuration = new HttpConfiguration();
protected HttpEndpointType[] endpoints;
@@ -160,18 +155,18 @@ public class HttpComponent extends Defau
this.client = client;
}
- public org.mortbay.jetty.client.HttpClient getConnectionPool() {
+ public org.eclipse.jetty.client.HttpClient getConnectionPool() {
return connectionPool;
}
- public org.mortbay.jetty.client.HttpClient createNewJettyClient() throws Exception {
- org.mortbay.jetty.client.HttpClient tempClient = new org.mortbay.jetty.client.HttpClient();
+ public org.eclipse.jetty.client.HttpClient createNewJettyClient() throws Exception {
+ org.eclipse.jetty.client.HttpClient tempClient = new org.eclipse.jetty.client.HttpClient();
QueuedThreadPool btp = new QueuedThreadPool();
btp.setMaxThreads(getConfiguration().getJettyClientThreadPoolSize());
tempClient.setThreadPool(btp);
- tempClient.setConnectorType(org.mortbay.jetty.client.HttpClient.CONNECTOR_SELECT_CHANNEL);
+ tempClient.setConnectorType(org.eclipse.jetty.client.HttpClient.CONNECTOR_SELECT_CHANNEL);
tempClient.setTimeout(getConfiguration().getProviderExpirationTime());
- tempClient.setSoTimeout(getConfiguration().getClientSoTimeout());
+ tempClient.setConnectTimeout(getConfiguration().getClientConnectTimeout());
tempClient.setMaxConnectionsPerAddress(getConfiguration().getMaxConnectionsPerAddress());
tempClient.start();
return tempClient;
@@ -184,7 +179,7 @@ public class HttpComponent extends Defau
* @param connectionPool a Jetty <code>HttpClient</code>
* @org.apache.xbean.Property description="a Jetty HTTP client instance maintaining a thread pool for client-side connections"
*/
- public void setConnectionPool(org.mortbay.jetty.client.HttpClient connectionPool) {
+ public void setConnectionPool(org.eclipse.jetty.client.HttpClient connectionPool) {
this.connectionPool = connectionPool;
}
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java Fri Aug 17 07:56:22 2012
@@ -16,14 +16,10 @@
*/
package org.apache.servicemix.http;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
-import org.mortbay.jetty.nio.SelectChannelConnector;
+import java.io.*;
+import java.util.Properties;
/**
* Class to hold the configuration for the Jetty instance used by an HTTP
@@ -125,9 +121,9 @@ public class HttpConfiguration implement
private int providerExpirationTime = 300000;
/***
- * HttpProvider endpoint clientSoTimeout when jettyClientPerProvider is false.
+ * HttpProvider endpoint clientConnectTimeout when jettyClientPerProvider is false.
*/
- private int clientSoTimeout = 10000;
+ private int clientConnectTimeout = 75000;
/***
* HttpProvider endpoint maxConnectionsPerAddress when jettyClientPerProvider is false.
@@ -168,6 +164,12 @@ public class HttpConfiguration implement
private boolean useHostPortForAuthScope;
+
+ /**
+ * Jetty server graceful timeout in ms, default is 0
+ **/
+ private int serverGracefulTimeout;
+
/**
* @return Returns the rootDir.
* @org.apache.xbean.Property hidden="true"
@@ -598,22 +600,22 @@ public class HttpConfiguration implement
}
/***
- * Gets the number of milliseconds for soTimeout parameter of JettyClient when JettyClient instance is shared among http:provider enpoints.
+ * Gets the number of milliseconds for soTimeout parameter of JettyClient when JettyClient instance is shared among http:provider endpoints.
* @return an int representing the JettyClient soTimeout.
*/
- public int getClientSoTimeout() {
- return clientSoTimeout;
+ public int getClientConnectTimeout() {
+ return clientConnectTimeout;
}
/**
- * Sets the number of milliseconds for soTimeout parameter of JettyClient when JettyClient instance is shared among http:provider enpoints.
+ * Sets the number of milliseconds for soTimeout parameter of JettyClient when JettyClient instance is shared among http:provider endpoints.
* The default default value for Jetty is 10000.
*
- * @param clientSoTimeout an int representing the JettyClient soTimeout.
- * @org.apache.xbean.Property description="the number of miliseconds representign shared JettyClient soTimeout. The default is 10000."
+ * @param clientConnectTimeout an int representing the JettyClient soTimeout.
+ * @org.apache.xbean.Property description="the number of miliseconds representign shared JettyClient connectTimeout. The default is 75000."
*/
- public void setClientSoTimeout(int clientSoTimeout) {
- this.clientSoTimeout = clientSoTimeout;
+ public void setClientConnectTimeout(int clientConnectTimeout) {
+ this.clientConnectTimeout = clientConnectTimeout;
save();
}
@@ -764,6 +766,25 @@ public class HttpConfiguration implement
save();
}
+
+ /**
+ * @return Returns the serverGracefulTimeout.
+ */
+ public int getServerGracefulTimeout() {
+ return this.serverGracefulTimeout;
+ }
+
+ /**
+ * @param serverGracefulTimeout The Jetty serverGracefulTimeout to set.
+ * @org.apache.xbean.Property description="the timeout for HTTP Jetty server to gracefully shutdown its contexts; default 0"
+ */
+ public void setServerGracefulTimeout(int serverGracefulTimeout) {
+ if (serverGracefulTimeout >=0 ) {
+ this.serverGracefulTimeout = serverGracefulTimeout;
+ save();
+ }
+ }
+
public void save() {
setProperty(componentName + ".jettyThreadPoolSize", Integer.toString(jettyThreadPoolSize));
setProperty(componentName + ".jettyClientThreadPoolSize", Integer.toString(jettyClientThreadPoolSize));
@@ -779,7 +800,7 @@ public class HttpConfiguration implement
setProperty(componentName + ".soLingerTime", Integer.toString(soLingerTime));
setProperty(componentName + ".consumerProcessorSuspendTime", Integer.toString(consumerProcessorSuspendTime));
setProperty(componentName + ".providerExpirationTime", Integer.toString(providerExpirationTime));
- setProperty(componentName + ".clientSoTimeout", Integer.toString(clientSoTimeout));
+ setProperty(componentName + ".clientConnectTimeout", Integer.toString(clientConnectTimeout));
setProperty(componentName + ".maxConnectionsPerAddress", Integer.toString(maxConnectionsPerAddress));
setProperty(componentName + ".retryCount", Integer.toString(retryCount));
setProperty(componentName + ".proxyHost", proxyHost);
@@ -788,6 +809,7 @@ public class HttpConfiguration implement
.toString(wantHeadersFromHttpIntoExchange));
setProperty(componentName + ".preemptiveAuthentication", Boolean.toString(preemptiveAuthentication));
setProperty(componentName + ".useHostPortForAuthScope", Boolean.toString(useHostPortForAuthScope));
+ setProperty(componentName + ".serverGracefulTimeout", Integer.toString(serverGracefulTimeout));
if (rootDir != null) {
File f = new File(rootDir, CONFIG_FILE);
try {
@@ -887,9 +909,9 @@ public class HttpConfiguration implement
providerExpirationTime = Integer.parseInt(properties
.getProperty(componentName + ".providerExpirationTime"));
}
- if (properties.getProperty(componentName + ".clientSoTimeout") != null) {
- clientSoTimeout = Integer.parseInt(properties
- .getProperty(componentName + ".clientSoTimeout"));
+ if (properties.getProperty(componentName + ".clientConnectTimeout") != null) {
+ clientConnectTimeout = Integer.parseInt(properties
+ .getProperty(componentName + ".clientConnectTimeout"));
}
if (properties.getProperty(componentName + ".maxConnectionsPerAddress") != null) {
maxConnectionsPerAddress = Integer.parseInt(properties
@@ -916,6 +938,9 @@ public class HttpConfiguration implement
if (properties.getProperty(componentName + ".useHostPortForAuthScope") != null) {
useHostPortForAuthScope = Boolean.valueOf(properties.getProperty(componentName + ".useHostPortForAuthScope")).booleanValue();
}
+ if (properties.getProperty(componentName + ".serverGracefulTimeout") != null) {
+ serverGracefulTimeout = Integer.parseInt(properties.getProperty(componentName + ".serverGracefulTimeout"));
+ }
return true;
}
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java Fri Aug 17 07:56:22 2012
@@ -16,31 +16,25 @@
*/
package org.apache.servicemix.http;
-import java.net.URI;
-
-import javax.jbi.management.DeploymentException;
-import javax.jbi.messaging.MessageExchange.Role;
-import javax.jbi.servicedesc.ServiceEndpoint;
-import javax.wsdl.Binding;
-import javax.wsdl.Definition;
-import javax.wsdl.Port;
-import javax.wsdl.PortType;
-import javax.wsdl.Service;
-import javax.wsdl.extensions.ExtensibilityElement;
-import javax.wsdl.extensions.http.HTTPAddress;
-import javax.xml.namespace.QName;
-
+import com.ibm.wsdl.extensions.http.HTTPAddressImpl;
import org.apache.servicemix.common.ExternalEndpoint;
import org.apache.servicemix.common.ManagementSupport;
-import org.apache.servicemix.common.tools.wsdl.PortTypeDecorator;
import org.apache.servicemix.common.security.AuthenticationService;
import org.apache.servicemix.common.security.KeystoreManager;
+import org.apache.servicemix.common.tools.wsdl.PortTypeDecorator;
import org.apache.servicemix.http.processors.ConsumerProcessor;
import org.apache.servicemix.http.processors.ProviderProcessor;
import org.apache.servicemix.soap.SoapEndpoint;
import org.apache.servicemix.soap.SoapExchangeProcessor;
-import com.ibm.wsdl.extensions.http.HTTPAddressImpl;
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.MessageExchange.Role;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.wsdl.*;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.http.HTTPAddress;
+import javax.xml.namespace.QName;
+import java.net.URI;
/**
* an HTTP endpoint. This is the base for all HTTP endpoints.
@@ -62,6 +56,8 @@ public class HttpEndpoint extends SoapEn
protected boolean wantContentTypeHeaderFromExchangeIntoHttpRequest;
protected int timeout;
protected boolean responseContentTypeCheck;
+ protected boolean supportAllHttpMethods;
+ protected String lateResponseStrategy;
public HttpEndpoint() {
}
@@ -456,4 +452,39 @@ public class HttpEndpoint extends SoapEn
return new DeploymentException(ManagementSupport.createComponentMessage(msg));
}
+
+ public boolean isSupportAllHttpMethods() {
+ return supportAllHttpMethods;
+ }
+
+ /**
+ * Sets the configuration information to support all HTTP methods by a HTTP consumer endpoint.
+ * Default (false) is to support only GET and POST
+ *
+ * @param supportAllHttpMethods Indicates whether all HTTP methods are supported by a HTTP consumer endpoint
+ * @org.apache.xbean.Property description="configuration indicator in order to support all HTTP methods by a HTTP consumer endpoint, otherwise only GET,POST methods are supported"
+ */
+ public void setSupportAllHttpMethods(boolean supportAllHttpMethods) {
+ this.supportAllHttpMethods = supportAllHttpMethods;
+ }
+
+
+ /**
+ * Set the strategy to be used for handling a late response from the ESB (i.e. a response that arrives after the HTTP request has timed out).
+ * Defaults to <code>error</code>
+ * <p/>
+ * <ul>
+ * <li><code>error</code> will terminate the exchange with an ERROR status and log an exception for the late response</li>
+ * <li><code>warning</code> will end the exchange with a DONE status and log a warning for the late response instead</li>
+ * </ul>
+ *
+ * @param value
+ */
+ public void setLateResponseStrategy(String value) {
+ this.lateResponseStrategy = value;
+ }
+
+ public String getLateResponseStrategy() {
+ return lateResponseStrategy;
+ }
}
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/ManagedContextManager.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/ManagedContextManager.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/ManagedContextManager.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/ManagedContextManager.java Fri Aug 17 07:56:22 2012
@@ -16,6 +16,12 @@
*/
package org.apache.servicemix.http;
+import org.eclipse.jetty.http.MimeTypes;
+import org.eclipse.jetty.util.ByteArrayISO8859Writer;
+import org.eclipse.jetty.util.StringUtil;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
@@ -24,14 +30,6 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-
-import org.mortbay.jetty.MimeTypes;
-import org.mortbay.util.ByteArrayISO8859Writer;
-import org.mortbay.util.StringUtil;
-
public class ManagedContextManager implements ContextManager {
private HttpConfiguration configuration;
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/AbstractHttpConsumerMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/AbstractHttpConsumerMarshaler.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/AbstractHttpConsumerMarshaler.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/AbstractHttpConsumerMarshaler.java Fri Aug 17 07:56:22 2012
@@ -16,21 +16,16 @@
*/
package org.apache.servicemix.http.endpoints;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.BufferedInputStream;
-import java.io.OutputStream;
-import java.io.BufferedOutputStream;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
+import org.eclipse.jetty.http.HttpHeaders;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jbi.messaging.MessageExchange;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
-import org.mortbay.jetty.HttpHeaders;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.io.*;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
public abstract class AbstractHttpConsumerMarshaler implements HttpConsumerMarshaler {
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/AbstractHttpProviderMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/AbstractHttpProviderMarshaler.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/AbstractHttpProviderMarshaler.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/AbstractHttpProviderMarshaler.java Fri Aug 17 07:56:22 2012
@@ -16,21 +16,17 @@
*/
package org.apache.servicemix.http.endpoints;
-import java.io.OutputStream;
-import java.io.IOException;
-import java.io.BufferedOutputStream;
-import java.io.InputStream;
-import java.io.BufferedInputStream;
-import java.util.zip.GZIPOutputStream;
-import java.util.zip.GZIPInputStream;
-import java.util.Arrays;
-import java.util.Set;
-import java.util.HashSet;
-
-import org.mortbay.jetty.HttpHeaders;
+import org.eclipse.jetty.http.HttpHeaders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.*;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
public abstract class AbstractHttpProviderMarshaler implements HttpProviderMarshaler {
private final Logger logger = LoggerFactory.getLogger(getClass());
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpConsumerMarshaler.java Fri Aug 17 07:56:22 2012
@@ -16,10 +16,10 @@
*/
package org.apache.servicemix.http.endpoints;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.OutputStream;
-import java.net.URI;
+import org.apache.servicemix.common.JbiConstants;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.XMLStreamHelper;
+import org.eclipse.jetty.http.HttpHeaders;
import javax.jbi.component.ComponentContext;
import javax.jbi.messaging.Fault;
@@ -30,11 +30,10 @@ import javax.servlet.http.HttpServletRes
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.stream.StreamSource;
-
-import org.apache.servicemix.jbi.jaxp.SourceTransformer;
-import org.apache.servicemix.jbi.jaxp.XMLStreamHelper;
-import org.apache.servicemix.common.JbiConstants;
-import org.mortbay.jetty.HttpHeaders;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.URI;
/**
* The default consumer marshaler used for non-soap consumer endpoints.
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/DefaultHttpProviderMarshaler.java Fri Aug 17 07:56:22 2012
@@ -16,29 +16,22 @@
*/
package org.apache.servicemix.http.endpoints;
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.Map;
-
-import javax.jbi.messaging.ExchangeStatus;
-import javax.jbi.messaging.Fault;
-import javax.jbi.messaging.InOnly;
-import javax.jbi.messaging.InOptionalOut;
-import javax.jbi.messaging.InOut;
-import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.NormalizedMessage;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
import org.apache.commons.httpclient.HttpStatus;
import org.apache.servicemix.expression.Expression;
import org.apache.servicemix.http.jetty.SmxHttpExchange;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
-import org.mortbay.io.ByteArrayBuffer;
-import org.mortbay.jetty.HttpHeaders;
-import org.mortbay.jetty.HttpMethods;
+import org.eclipse.jetty.http.HttpHeaders;
+import org.eclipse.jetty.http.HttpMethods;
+import org.eclipse.jetty.io.ByteArrayBuffer;
+
+import javax.jbi.messaging.*;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.Map;
/**
* Default marshaler used for non-soap provider endpoints.
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java Fri Aug 17 07:56:22 2012
@@ -16,12 +16,22 @@
*/
package org.apache.servicemix.http.endpoints;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import org.apache.servicemix.common.DefaultComponent;
+import org.apache.servicemix.common.JbiConstants;
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.endpoints.ConsumerEndpoint;
+import org.apache.servicemix.http.*;
+import org.apache.servicemix.http.exception.HttpTimeoutException;
+import org.apache.servicemix.http.exception.LateResponseException;
+import org.apache.servicemix.http.jetty.JaasJettyPrincipal;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.eclipse.jetty.continuation.Continuation;
+import org.eclipse.jetty.continuation.ContinuationSupport;
+import org.eclipse.jetty.server.Server;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import javax.jbi.management.DeploymentException;
import javax.jbi.messaging.ExchangeStatus;
@@ -37,42 +47,27 @@ import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-
-import org.apache.servicemix.http.exception.HttpTimeoutException;
-import org.apache.servicemix.http.exception.LateResponseException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.apache.servicemix.common.DefaultComponent;
-import org.apache.servicemix.common.ServiceUnit;
-import org.apache.servicemix.common.JbiConstants;
-import org.apache.servicemix.common.endpoints.ConsumerEndpoint;
-import org.apache.servicemix.http.ContextManager;
-import org.apache.servicemix.http.HttpComponent;
-import org.apache.servicemix.http.HttpEndpointType;
-import org.apache.servicemix.http.HttpProcessor;
-import org.apache.servicemix.http.SslParameters;
-import org.apache.servicemix.http.jetty.JaasJettyPrincipal;
-import org.apache.servicemix.jbi.jaxp.SourceTransformer;
-import org.mortbay.jetty.RetryRequest;
-import org.mortbay.util.ajax.Continuation;
-import org.mortbay.util.ajax.ContinuationSupport;
-
-import static org.apache.servicemix.http.jetty.ContinuationHelper.isNewContinuation;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Plain HTTP consumer endpoint. This endpoint can be used to handle plain HTTP request (without SOAP) or to be able to
* process the request in a non standard way. For HTTP requests, a WSDL2 HTTP binding can be used.
*
* @author gnodet
- * @since 3.2
* @org.apache.xbean.XBean element="consumer"
+ * @since 3.2
*/
public class HttpConsumerEndpoint extends ConsumerEndpoint implements HttpProcessor, HttpEndpointType {
public static final String MAIN_WSDL = "main.wsdl";
+ private static final String EXCHANGE = MessageExchange.class.getName();
+ private static final String MUTEX = MessageExchange.class.getName() + "Mutex";
+ private static final String EXCHANGEID = MessageExchange.class.getName() + "Mutex";
private String authMethod;
private SslParameters ssl;
private String locationURI;
@@ -82,6 +77,7 @@ public class HttpConsumerEndpoint extend
private Map<String, Object> resources = new HashMap<String, Object>();
private Map<String, Continuation> continuations = new ConcurrentHashMap<String, Continuation>();
private Map<String, Object> mutexes = new ConcurrentHashMap<String, Object>();
+ private Map<String, MessageExchange> sentExchanges = new ConcurrentHashMap<String, MessageExchange>();
private Object httpContext;
private boolean started = false;
private LateResponseStrategy lateResponseStrategy = LateResponseStrategy.error;
@@ -131,8 +127,8 @@ public class HttpConsumerEndpoint extend
* Specifies the timeout value for an HTTP consumer endpoint. The timeout is specified in milliseconds. The default value is 0
* which means that the endpoint will never timeout.
*
- * @org.apache.xbean.Property description="the timeout is specified in milliseconds. The default value is 0 which means that the endpoint will never timeout."
* @param timeout the length time, in milliseconds, to wait before timing out
+ * @org.apache.xbean.Property description="the timeout is specified in milliseconds. The default value is 0 which means that the endpoint will never timeout."
*/
public void setTimeout(long timeout) {
this.timeout = timeout;
@@ -219,10 +215,10 @@ public class HttpConsumerEndpoint extend
/**
* Set the strategy to be used for handling a late response from the ESB (i.e. a response that arrives after the HTTP request has timed out).
* Defaults to <code>error</code>
- *
+ * <p/>
* <ul>
- * <li><code>error</code> will terminate the exchange with an ERROR status and log an exception for the late response</li>
- * <li><code>warning</code> will end the exchange with a DONE status and log a warning for the late response instead</li>
+ * <li><code>error</code> will terminate the exchange with an ERROR status and log an exception for the late response</li>
+ * <li><code>warning</code> will end the exchange with a DONE status and log a warning for the late response instead</li>
* </ul>
*
* @param value
@@ -230,17 +226,17 @@ public class HttpConsumerEndpoint extend
public void setLateResponseStrategy(String value) {
this.lateResponseStrategy = LateResponseStrategy.valueOf(value);
}
-
+
public boolean isRewriteSoapAddress() {
- return rewriteSoapAddress;
- }
+ return rewriteSoapAddress;
+ }
/**
* Toggles the rewriting of the soap address based on the request info.
* <p>
* When active, the soap address in the wsdl will be updated according
* to the protocol, host and port of the request. This is useful when
- * listening on 0.0.0.0 or when behind a NAT (or reverse-proxy in some
+ * listening on 0.0.0.0 or when behind a NAT (or reverse-proxy in some
* cases).<br />
* This function only works on the main wsdl, not in imported wsdl-parts.
* This means the service with its port must be declared in the main
@@ -248,16 +244,18 @@ public class HttpConsumerEndpoint extend
* </p><p>
* By default it is activated.
* </p>
+ *
* @param value
*/
- public void setRewriteSoapAddress(boolean value) {
- this.rewriteSoapAddress = value;
- }
+ public void setRewriteSoapAddress(boolean value) {
+ this.rewriteSoapAddress = value;
+ }
- public void activate() throws Exception {
+ public void activate() throws Exception {
super.activate();
loadStaticResources();
httpContext = getServerManager().createContext(locationURI, this);
+
}
public void deactivate() throws Exception {
@@ -269,9 +267,16 @@ public class HttpConsumerEndpoint extend
public void start() throws Exception {
super.start();
started = true;
+ if (httpContext instanceof Server.Graceful){
+ ((Server.Graceful)httpContext).setShutdown(false);
+ }
+
}
public void stop() throws Exception {
+ if (httpContext instanceof Server.Graceful){
+ ((Server.Graceful)httpContext).setShutdown(true);
+ }
started = false;
super.stop();
}
@@ -281,36 +286,41 @@ public class HttpConsumerEndpoint extend
*/
public void process(MessageExchange exchange) throws Exception {
final String id = exchange.getExchangeId();
- final Object mutex = mutexes.get(id);
- // if the mutex is no longer available, the HTTP request timed out before the message exchange got handled by the ESB
- if (mutex == null) {
- handleLateResponse(exchange);
- return;
- }
+ // Synchronize on the mutex object while we're tinkering with the continuation object,
+ // this is still jetty, so do not trust jetty locks anymore
+ final Continuation continuation = continuations.get(id);
+ if (continuation != null){
+ final Object mutex = continuation.getAttribute(MUTEX);
+ if (mutex == null) {
+ handleLateResponse(exchange);
+ return;
+ }
+ synchronized (mutex) {
+ if (!continuation.isExpired() && !continuation.isResumed()) {
+ logger.debug("Resuming continuation for exchange: {}", id);
- // Synchronize on the mutex object while we're tinkering with the continuation object
- synchronized (mutex) {
- final Continuation continuation = continuations.get(id);
- if (continuation != null && continuation.isPending()) {
- logger.debug("Resuming continuation for exchange: {}", id);
+ // in case of the JMS/JCA flow, you might have a different instance of the message exchange here
+ continuation.setAttribute(EXCHANGE, exchange);
- // in case of the JMS/JCA flow, you might have a different instance of the message exchange here
- continuation.setObject(exchange);
+ continuation.resume();
- continuation.resume();
- // if the continuation could no longer be resumed, the HTTP request might have timed out before the message
- // exchange got handled by the ESB
- if (!continuation.isResumed()) {
+ // if the continuation could no longer be resumed, the HTTP request might have timed out before the message
+ // exchange got handled by the ESB
+ if (!continuation.isResumed()) {
+ handleLateResponse(exchange);
+ }
+ } else {
+ // it the continuation is no longer available or no longer pending, the HTTP request has time out before
+ // the message exchange got handled by the ESB
handleLateResponse(exchange);
}
- } else {
- // it the continuation is no longer available or no longer pending, the HTTP request has time out before
- // the message exchange got handled by the ESB
- handleLateResponse(exchange);
}
+ } else {
+ handleLateResponse(exchange);
}
+
}
/*
@@ -320,77 +330,82 @@ public class HttpConsumerEndpoint extend
* (either because the exchange was received or because the request timed out)
*/
public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
- MessageExchange exchange = null;
+ MessageExchange exchange;
+ Continuation continuation = null;
+ Object mutex = null;
+ String id = null;
try {
// Handle WSDLs, XSDs
if (handleStaticResource(request, response)) {
return;
}
+ continuation = ContinuationSupport.getContinuation(request);
+ mutex = getOrCreateMutex(continuation);
- // configure the timeout
- long to = this.timeout;
- if (to == 0) {
- to = ((HttpComponent) getServiceUnit().getComponent()).getConfiguration().getConsumerProcessorSuspendTime();
- }
+ boolean sendExchange = false;
+ synchronized (mutex) {
+ exchange = (MessageExchange) continuation.getAttribute(EXCHANGE);
+ id = (String)continuation.getAttribute(EXCHANGEID);
- final Continuation continuation = ContinuationSupport.getContinuation(request, null);
- exchange = (MessageExchange) continuation.getObject();
- final Object mutex = getOrCreateMutex(exchange);
+ if (exchange == null) {
+ // well, new request.. hope so
+ long timeoutMs = obtainTimeout();
+ // Synchronize on the mutex object while we're (s)tinkering with the continuation object
+ // if this is a timeout
+ if (continuation.isExpired()) {
+ throw new HttpTimeoutException(id);
+ }
- // Synchronize on the mutex object while we're tinkering with the continuation object
- synchronized (mutex) {
- if (isNewContinuation(continuation)) {
logger.debug("Receiving HTTP request: {}", request);
- // send back HTTP status 503 (Not Avaialble) to reject any new requests if the endpoint is not started
+ // send back HTTP status 503 (Not Available) to reject any new requests if the endpoint is not started
if (!started) {
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Endpoint is stopped");
return;
}
+ continuation.setTimeout(timeoutMs);
+
// Create the exchange
exchange = createExchange(request);
- final String id = exchange.getExchangeId();
+ id = exchange.getExchangeId();
- // Put the exchange into the continuation for later retrieval and store the mutex/continuation objects
- continuation.setObject(exchange);
+ continuation.setAttribute(MUTEX, mutex);
+ continuation.setAttribute(EXCHANGEID, id);
mutexes.put(id, mutex);
continuations.put(id, continuation);
+ sentExchanges.put(id, exchange);
- // Send the exchange and then suspend the HTTP request until the message exchange gets answered
- send(exchange);
-
- // Right after this if-block, we will try suspending the continuation
- // If a SelectConnector is being used, the call to suspend will throw a RetryRequest
- // This will free the thread - this method will be invoked again when the continuation gets resumed
logger.debug("Suspending continuation for exchange: {}", id);
- } else {
- logger.debug("Resuming HTTP request: {}", request);
+ continuation.suspend(response);
+ sendExchange = true;
}
+ }
- boolean istimeout = !continuation.suspend(to);
-
- // Continuation is being ended (either because the message exchange was handled or the continuation timed out)
- // Cleaning up the stored objects for this continuation now
- exchange = doEndContinuation(continuation);
-
- // Throw exception when HTTP time-out has occurred
- if (istimeout) {
- throw new HttpTimeoutException(exchange);
- }
+ if (sendExchange) {
+ send(exchange);
+ return;
}
+
// message exchange has been completed, so we're ready to send back an HTTP response now
+ logger.debug("Resuming HTTP request: {}", request);
+ doClean(mutex, continuation, id);
handleResponse(exchange, request, response);
- } catch (RetryRequest e) {
- // retrow the RetryRequest to allow Jetty to re-invoke this method when the continuation is being resumed
- throw e;
} catch (Exception e) {
- sendError(exchange, e, request, response);
+ sendError(doClean(mutex, continuation, id), e, request, response);
}
}
+ private long obtainTimeout() {
+ long to = this.timeout;
+ if (to == 0) {
+ to = ((HttpComponent) getServiceUnit().getComponent()).getConfiguration().getConsumerProcessorSuspendTime();
+ }
+ return to;
+ }
+
/*
* Handle the HTTP response based on the information in the message exchange we received
*/
@@ -428,13 +443,13 @@ public class HttpConsumerEndpoint extend
*/
private void handleLateResponse(MessageExchange exchange) throws Exception {
// if the exchange is no longer active by now, something else probably went wrong in the meanwhile
+ logger.warn(LateResponseException.createMessage(exchange));
if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
if (lateResponseStrategy == LateResponseStrategy.error) {
// ends the exchange in ERROR
fail(exchange, new LateResponseException(exchange));
} else {
// let's log the exception message text, but end the exchange with DONE
- logger.warn(LateResponseException.createMessage(exchange));
done(exchange);
}
}
@@ -443,12 +458,12 @@ public class HttpConsumerEndpoint extend
/*
* Get or create an object that can be used for synchronizing code blocks for a given exchange
*/
- private Object getOrCreateMutex(MessageExchange exchange) {
+ private Object getOrCreateMutex(Continuation continuation) {
Object result = null;
// let's try to find the object that corresponds to the exchange first
- if (exchange != null) {
- result = mutexes.get(exchange.getExchangeId());
+ if (continuation != null) {
+ result = continuation.getAttribute(MUTEX);
}
// no luck finding an existing object, let's create a new one
@@ -459,18 +474,28 @@ public class HttpConsumerEndpoint extend
return result;
}
- /*
- * End the continuation by removing all objects stored on/for the continuation
- * and returning the MessageExchange that was represented by the continuation
- */
- private MessageExchange doEndContinuation(Continuation continuation) {
- final MessageExchange exchange = (MessageExchange) continuation.getObject();
- final String id = exchange.getExchangeId();
-
- continuation.setObject(null);
- mutexes.remove(id);
- continuations.remove(id);
- return exchange;
+ private MessageExchange doClean(Object mutex, Continuation continuation, String exchangeId) {
+ if (mutex != null) {
+ synchronized (mutex) {
+ if (exchangeId == null && continuation != null) {
+ exchangeId = (String) continuation.getAttribute(EXCHANGEID);
+ }
+ if (exchangeId != null && continuation == null) {
+ continuation = continuations.remove(exchangeId);
+ }
+ if (continuation != null) {
+ continuation.removeAttribute(EXCHANGEID);
+ continuation.removeAttribute(EXCHANGE);
+ continuation.removeAttribute(MUTEX);
+ }
+ if (exchangeId != null) {
+ mutexes.remove(exchangeId);
+ continuations.remove(exchangeId);
+ return sentExchanges.remove(exchangeId);
+ }
+ }
+ }
+ return null;
}
protected void loadStaticResources() throws Exception {
@@ -479,7 +504,7 @@ public class HttpConsumerEndpoint extend
/**
* Handle static resources
*
- * @param request the http request
+ * @param request the http request
* @param response the http response
* @return <code>true</code> if the request has been handled
* @throws IOException
@@ -506,7 +531,7 @@ public class HttpConsumerEndpoint extend
}
Object res;
if (rewriteSoapAddress && path.equals(MAIN_WSDL) && getResource(path) instanceof Document) {
- // determine the location based on the request
+ // determine the location based on the request
String location = getLocationURI();
try {
URL listUrl = new URL(getLocationURI());
@@ -514,18 +539,18 @@ public class HttpConsumerEndpoint extend
URL acceptUri = new URL(requestUrl.getProtocol(), requestUrl.getHost(), requestUrl.getPort(),
listUrl.getFile());
location = acceptUri.toExternalForm();
-
- //Update the location for this request
- Document copy = (Document) ((Document) getResource(path)).cloneNode(true);
- updateSoapLocations(location, copy.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/soap12/", "address"));
- updateSoapLocations(location, copy.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/soap/", "address"));
- res = copy;
+
+ //Update the location for this request
+ Document copy = (Document) ((Document) getResource(path)).cloneNode(true);
+ updateSoapLocations(location, copy.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/soap12/", "address"));
+ updateSoapLocations(location, copy.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/soap/", "address"));
+ res = copy;
} catch (Exception e) {
logger.warn("Could not update soap location, using default", e);
res = getResource(path);
}
} else {
- res = getResource(path);
+ res = getResource(path);
}
if (res == null) {
return false;
@@ -610,7 +635,7 @@ public class HttpConsumerEndpoint extend
((DefaultHttpConsumerMarshaler) marshaler).setDefaultMep(getDefaultMep());
}
}
-
+
protected void updateSoapLocations(String location, NodeList addresses) {
int i = 0;
while (i < addresses.getLength()) {
@@ -621,21 +646,5 @@ public class HttpConsumerEndpoint extend
i++;
}
}
-
- /**
- * Determines how the HTTP consumer endpoint should handle a late response from the NMR
- */
- protected enum LateResponseStrategy {
-
- /**
- * Terminate the exchange with an ERROR status and log an exception for the late response
- */
- error,
-
- /**
- * End the exchange with a DONE status and log a warning for the late response
- */
- warning
-
- }
}
+
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java Fri Aug 17 07:56:22 2012
@@ -26,13 +26,13 @@ import org.apache.servicemix.http.HttpCo
import org.apache.servicemix.http.HttpEndpointType;
import org.apache.servicemix.http.SslParameters;
import org.apache.servicemix.http.jetty.SmxHttpExchange;
-import org.mortbay.jetty.client.Address;
-import org.mortbay.jetty.client.HttpClient;
-import org.mortbay.jetty.client.security.ProxyAuthorization;
-import org.mortbay.jetty.client.security.Realm;
-import org.mortbay.jetty.client.security.SimpleRealmResolver;
-import org.mortbay.resource.Resource;
-import org.mortbay.thread.QueuedThreadPool;
+import org.eclipse.jetty.client.Address;
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.client.security.ProxyAuthorization;
+import org.eclipse.jetty.client.security.Realm;
+import org.eclipse.jetty.client.security.SimpleRealmResolver;
+import org.eclipse.jetty.util.resource.Resource;
+import org.eclipse.jetty.util.thread.QueuedThreadPool;
import javax.jbi.management.DeploymentException;
import javax.jbi.messaging.ExchangeStatus;
@@ -43,7 +43,6 @@ import javax.net.ssl.*;
import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.InputStream;
-import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.SecureRandom;
@@ -57,8 +56,9 @@ import java.security.SecureRandom;
public class HttpProviderEndpoint extends ProviderEndpoint implements HttpEndpointType {
private HttpProviderMarshaler marshaler;
+ private HttpProviderListener listener;
private String locationURI;
- private int clientSoTimeout = 60000;
+ private int clientConnectTimeout = 75000;
private int providerExpirationTime = 300000;
private int maxConnectionsPerAddress = 32;
private HttpClient jettyClient;
@@ -126,6 +126,20 @@ public class HttpProviderEndpoint extend
this.marshaler = marshaler;
}
+ public HttpProviderListener getListener() {
+ return listener;
+ }
+
+ /**
+ * Sets the class used to marshal messages.
+ *
+ * @param listener the marshaler to set
+ * @org.apache.xbean.Property description="the bean used monitor Jetty Client instance and to handle some Jetty Client events"
+ */
+ public void setListener(HttpProviderListener listener) {
+ this.listener = listener;
+ }
+
public String getProxyHost() {
return proxyHost;
}
@@ -262,8 +276,12 @@ public class HttpProviderEndpoint extend
throw new IllegalStateException("Exchange has no input message");
}
SmxHttpExchange httpEx = new Exchange(exchange);
- marshaler.createRequest(exchange, nm, httpEx);
- jettyClient.send(httpEx);
+ try {
+ marshaler.createRequest(exchange, nm, httpEx);
+ jettyClient.send(httpEx);
+ } catch (Exception e){
+ handleException(httpEx, exchange, e);
+ }
}
}
@@ -274,6 +292,9 @@ public class HttpProviderEndpoint extend
@Override
public synchronized void stop() throws Exception {
+ if (listener != null){
+ listener.stopJettyClientMonitoring(jettyClient);
+ }
if (ownClient && jettyClient != null) {
jettyClient.stop();
jettyClient = null;
@@ -316,7 +337,7 @@ public class HttpProviderEndpoint extend
}
}
- protected org.mortbay.jetty.client.HttpClient getConnectionPool() throws Exception {
+ protected org.eclipse.jetty.client.HttpClient getConnectionPool() throws Exception {
if (jettyClient == null) {
HttpComponent comp = (HttpComponent) getServiceUnit().getComponent();
if (comp.getConfiguration().isJettyClientPerProvider() || proxyHost != null || ssl != null) {
@@ -330,7 +351,7 @@ public class HttpProviderEndpoint extend
jettyClient.setProxyAuthentication(new ProxyAuthorization(proxyUsername, proxyPassword));
}
}
- jettyClient.setSoTimeout(getClientSoTimeout());
+ jettyClient.setConnectTimeout(getClientConnectTimeout());
jettyClient.setTimeout(getProviderExpirationTime());
jettyClient.setMaxConnectionsPerAddress(getMaxConnectionsPerAddress());
if (principal != null && credentials != null) {
@@ -353,22 +374,25 @@ public class HttpProviderEndpoint extend
jettyClient = comp.getConnectionPool();
}
}
+ if (listener != null){
+ listener.startJettyClientMonitoring(jettyClient);
+ }
return jettyClient;
}
- public int getClientSoTimeout() {
- return clientSoTimeout;
+ public int getClientConnectTimeout() {
+ return clientConnectTimeout;
}
/**
* Sets the number of milliseconds the endpoint will block while attempting to read a request. The default value is 60000.
* Setting this to 0 specifies that the endpoint will never timeout.
*
- * @param clientTimeout an int specifying the number of milliseconds the socket will block while attempting to read a request
+ * @param clientConnectTimeout an int specifying the number of milliseconds the socket will block while attempting to read a request
* @org.apache.xbean.Property description="the number of milliseconds the endpoint will block while attempting to read a request. The default value is 60000. Setting this to 0 specifies that the endpoint will never timeout."
*/
- public void setClientSoTimeout(int clientTimeout) {
- this.clientSoTimeout = clientTimeout;
+ public void setClientConnectTimeout(int clientConnectTimeout) {
+ this.clientConnectTimeout = clientConnectTimeout;
}
public int getProviderExpirationTime() {
@@ -445,20 +469,34 @@ public class HttpProviderEndpoint extend
protected void onExpire() {
handleException(this, jbiExchange, new Exception("Http request expired."));
}
-
+
+
+ @Override
+ protected void onRequestCommitted() throws IOException {
+ if (listener != null){
+ listener.onRequestCommited(jbiExchange, this);
+ }
+ }
+
+ @Override
+ protected void onRequestComplete() throws IOException {
+ if (listener != null){
+ listener.onRequestComplete(jbiExchange, this);
+ }
+ }
}
protected class SSLManagedHttpClient extends HttpClient {
- protected SSLContext getSSLContext() throws IOException {
- if (ssl.getKeyStore() != null) {
+ protected SSLContext getSSLContext() {
+ if (ssl != null && ssl.getKeyStore() != null) {
return getStrictSSLContext();
} else {
- return getLooseSSLContext();
+ return super.getSSLContext();
}
}
- protected SSLContext getStrictSSLContext() throws IOException {
+ protected SSLContext getStrictSSLContext() {
try {
if (ssl.isManaged()) {
KeystoreManager keystoreMgr = KeystoreManager.Proxy.create(getConfiguration().getKeystoreManager());
@@ -497,8 +535,8 @@ public class HttpProviderEndpoint extend
context.init(keyManagers, trustManagers, new SecureRandom());
return context;
}
- } catch (GeneralSecurityException e) {
- throw (IOException) new IOException("Unable to create SSL context").initCause(e);
+ } catch (Exception e) {
+ throw new RuntimeException("Unable to create SSL context", e);
}
}
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerMarshaler.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerMarshaler.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapConsumerMarshaler.java Fri Aug 17 07:56:22 2012
@@ -16,30 +16,29 @@
*/
package org.apache.servicemix.http.endpoints;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jbi.component.ComponentContext;
-import javax.jbi.messaging.Fault;
-import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.NormalizedMessage;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.xml.namespace.QName;
-
import org.apache.servicemix.soap.api.InterceptorChain;
+import org.apache.servicemix.soap.api.InterceptorProvider.Phase;
import org.apache.servicemix.soap.api.Message;
import org.apache.servicemix.soap.api.Policy;
-import org.apache.servicemix.soap.api.InterceptorProvider.Phase;
import org.apache.servicemix.soap.api.model.Binding;
import org.apache.servicemix.soap.bindings.http.HttpConstants;
import org.apache.servicemix.soap.bindings.soap.SoapFault;
import org.apache.servicemix.soap.bindings.soap.SoapVersion;
import org.apache.servicemix.soap.interceptors.jbi.JbiConstants;
-import org.mortbay.jetty.HttpHeaders;
+import org.eclipse.jetty.http.HttpHeaders;
+
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.namespace.QName;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
/**
*
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderMarshaler.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderMarshaler.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpSoapProviderMarshaler.java Fri Aug 17 07:56:22 2012
@@ -16,15 +16,6 @@
*/
package org.apache.servicemix.http.endpoints;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Map;
-import java.util.HashMap;
-
-import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.NormalizedMessage;
-
import org.apache.servicemix.http.jetty.SmxHttpExchange;
import org.apache.servicemix.soap.api.InterceptorChain;
import org.apache.servicemix.soap.api.InterceptorProvider.Phase;
@@ -33,9 +24,17 @@ import org.apache.servicemix.soap.api.Po
import org.apache.servicemix.soap.api.model.Binding;
import org.apache.servicemix.soap.interceptors.jbi.JbiConstants;
import org.apache.servicemix.soap.interceptors.xml.StaxInInterceptor;
-import org.mortbay.io.ByteArrayBuffer;
-import org.mortbay.jetty.HttpMethods;
-import org.mortbay.jetty.HttpHeaders;
+import org.eclipse.jetty.http.HttpHeaders;
+import org.eclipse.jetty.http.HttpMethods;
+import org.eclipse.jetty.io.ByteArrayBuffer;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
/**
*
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/HttpTimeoutException.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/HttpTimeoutException.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/HttpTimeoutException.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/HttpTimeoutException.java Fri Aug 17 07:56:22 2012
@@ -24,14 +24,18 @@ import javax.jbi.messaging.MessageExchan
public class HttpTimeoutException extends Exception {
public HttpTimeoutException(MessageExchange exchange) {
- super(createMessage(exchange));
+ super(createMessage(exchange != null ? exchange.getExchangeId() : null ));
}
- private static String createMessage(MessageExchange exchange) {
- if (exchange == null) {
+ public HttpTimeoutException(String id) {
+ super(createMessage(id));
+ }
+
+ private static String createMessage(String id) {
+ if (id == null) {
return "HTTP request has timed out";
} else {
- return String.format("HTTP request has timed out for exchange: %s", exchange.getExchangeId());
+ return String.format("HTTP request has timed out for exchange: %s", id);
}
}
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/ContinuationHelper.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/ContinuationHelper.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/ContinuationHelper.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/ContinuationHelper.java Fri Aug 17 07:56:22 2012
@@ -1,40 +0,0 @@
-/*
- * 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.servicemix.http.jetty;
-
-import org.mortbay.util.ajax.Continuation;
-
-/**
- * A few helper methods for working with Jetty continuations
- */
-public class ContinuationHelper {
-
- private ContinuationHelper() {
- // static helper methods only - no need for a public constructor
- }
-
- /**
- * Is this a new continuation object?
- *
- * @param continuation
- * @return <code>true</code> for a new continuation object
- */
- public static boolean isNewContinuation(Continuation continuation) {
- return continuation.isNew() ||
- (!continuation.isPending() && !continuation.isResumed());
- }
-}
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JCLLogger.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JCLLogger.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JCLLogger.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JCLLogger.java Fri Aug 17 07:56:22 2012
@@ -1,154 +0,0 @@
-/*
- * 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.servicemix.http.jetty;
-
-import org.mortbay.log.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A jetty6 logger implementation on top of commons-logging
- *
- * @author gnodet
- */
-public class JCLLogger implements Logger {
-
- static final char DELIM_START = '{';
- static final char DELIM_STOP = '}';
-
- private final String name;
- private final org.slf4j.Logger logger;
-
- public JCLLogger() {
- this("org.mortbay.jetty");
- }
-
- public JCLLogger(String name) {
- this.name = name;
- this.logger = LoggerFactory.getLogger(name);
- }
-
- public static void init() {
- // TODO: use org.mortbay.log.Log#setLog when available (beta18)
- String old = System.getProperty("org.mortbay.log.class");
- ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
- try {
- System.setProperty("org.mortbay.log.class", JCLLogger.class.getName());
- // For the class to be loaded by invoking a public static method
- Class<?> cl = Logger.class.getClassLoader().loadClass("org.mortbay.log.Log");
- Thread.currentThread().setContextClassLoader(JCLLogger.class.getClassLoader());
- cl.getMethod("isDebugEnabled", new Class[0]).invoke(null);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (old != null) {
- System.setProperty("org.mortbay.log.class", old);
- } else {
- System.getProperties().remove("org.mortbay.log.class");
- }
- Thread.currentThread().setContextClassLoader(oldLoader);
- }
- }
-
- public void debug(String msg, Throwable th) {
- logger.debug(msg, th);
- }
-
- public void debug(String msg, Object arg0, Object arg1) {
- logger.debug(arrayFormat(msg, new Object[] {arg0, arg1}));
- }
-
- public Logger getLogger(String loggerName) {
- if (loggerName == null) {
- return null;
- }
- return new JCLLogger(this.name + "." + loggerName);
- }
-
- public void info(String msg, Object arg0, Object arg1) {
- logger.info(arrayFormat(msg, new Object[] {arg0, arg1}));
- }
-
- public boolean isDebugEnabled() {
- return logger.isDebugEnabled();
- }
-
- public void setDebugEnabled(boolean enabled) {
- logger.warn("setDebugEnabled not supported");
- }
-
- public void warn(String msg, Throwable th) {
- logger.warn(msg, th);
- }
-
- public void warn(String msg, Object arg0, Object arg1) {
- logger.warn(arrayFormat(msg, new Object[] {arg0, arg1}));
- }
-
- public static String arrayFormat(String messagePattern, Object[] argArray) {
- if (messagePattern == null) {
- return null;
- }
- int i = 0;
- int len = messagePattern.length();
- int j = messagePattern.indexOf(DELIM_START);
-
- StringBuffer sbuf = new StringBuffer(messagePattern.length() + 50);
-
- for (int index = 0; index < argArray.length; index++) {
-
- char escape = 'x';
-
- j = messagePattern.indexOf(DELIM_START, i);
-
- if (j == -1 || (j + 1 == len)) {
- // no more variables
- if (i == 0) { // this is a simple string
- return messagePattern;
- } else { // add the tail string which contains no variables
- // and return the result.
- sbuf.append(messagePattern.substring(i, messagePattern.length()));
- return sbuf.toString();
- }
- } else {
- char delimStop = messagePattern.charAt(j + 1);
- if (j > 0) {
- escape = messagePattern.charAt(j - 1);
- }
-
- if (escape == '\\') {
- index--; // DELIM_START was escaped, thus should not be
- // incremented
- sbuf.append(messagePattern.substring(i, j - 1));
- sbuf.append(DELIM_START);
- i = j + 1;
- } else if (delimStop != DELIM_STOP) {
- // invalid DELIM_START/DELIM_STOP pair
- sbuf.append(messagePattern.substring(i, messagePattern.length()));
- return sbuf.toString();
- } else {
- // normal case
- sbuf.append(messagePattern.substring(i, j));
- sbuf.append(argArray[index]);
- i = j + 2;
- }
- }
- }
- // append the characters following the second {} pair.
- sbuf.append(messagePattern.substring(i, messagePattern.length()));
- return sbuf.toString();
- }
-}
Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasJettyPrincipal.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasJettyPrincipal.java?rev=1374169&r1=1374168&r2=1374169&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasJettyPrincipal.java (original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JaasJettyPrincipal.java Fri Aug 17 07:56:22 2012
@@ -16,29 +16,52 @@
*/
package org.apache.servicemix.http.jetty;
-import java.security.Principal;
+import org.eclipse.jetty.server.UserIdentity;
import javax.security.auth.Subject;
+import java.security.Principal;
-public class JaasJettyPrincipal implements Principal {
+public class JaasJettyPrincipal implements UserIdentity, Principal {
- private final String name;
- private Subject subject;
+ private final String _name;
+ private final Subject _subject;
+ private final String[] _roles;
+
+ public JaasJettyPrincipal(Subject subject, String name, String[] roles)
+ {
+ _name = name;
+ _subject=subject;
+ _roles=roles;
+ }
- public JaasJettyPrincipal(String name) {
- this.name = name;
+ public Subject getSubject()
+ {
+ return _subject;
}
- public String getName() {
- return name;
+ public Principal getUserPrincipal()
+ {
+ return this;
}
- public Subject getSubject() {
- return subject;
+ public boolean isUserInRole(String role, Scope scope)
+ {
+ if (scope!=null && scope.getRoleRefMap()!=null)
+ role=scope.getRoleRefMap().get(role);
+
+ for (String r :_roles)
+ if (r.equals(role))
+ return true;
+ return false;
}
- public void setSubject(Subject subject) {
- this.subject = subject;
+ @Override
+ public String toString()
+ {
+ return JaasJettyPrincipal.class.getSimpleName()+"('"+_name+"')";
}
+ public String getName() {
+ return _name;
+ }
}