You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cs...@apache.org on 2015/01/15 09:48:57 UTC
[21/23] camel git commit: CAMEL-8239 Split jetty8 and jetty9 support
into separate modules
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-jetty/pom.xml b/components/camel-jetty/pom.xml
deleted file mode 100644
index b2d3270..0000000
--- a/components/camel-jetty/pom.xml
+++ /dev/null
@@ -1,198 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components</artifactId>
- <version>2.15-SNAPSHOT</version>
- </parent>
-
- <artifactId>camel-jetty</artifactId>
- <packaging>bundle</packaging>
- <name>Camel :: Jetty</name>
- <description>Camel Jetty support</description>
-
- <properties>
- <camel.osgi.import.before.defaults>
- javax.servlet.*;version="${servlet-version-range}"
- </camel.osgi.import.before.defaults>
- <camel.osgi.export.pkg>org.apache.camel.component.jetty*</camel.osgi.export.pkg>
- <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=jetty</camel.osgi.export.service>
- </properties>
-
- <dependencies>
-
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-http</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-servlet_3.0_spec</artifactId>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-server</artifactId>
- <exclusions>
- <exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.eclipse.jetty.orbit</groupId>
- <artifactId>javax.servlet</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-servlet</artifactId>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-security</artifactId>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-servlets</artifactId>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-client</artifactId>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-jmx</artifactId>
- </dependency>
-
- <!-- test dependencies -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test-spring</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-spring</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <optional>true</optional>
- <scope>test</scope>
- </dependency>
- <!-- for testing rest-dsl -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-jackson</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-jaxb</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <profiles>
- <profile>
- <id>jetty9</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <phase>generate-sources</phase>
- <goals>
- <goal>add-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>src/main/jetty9</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- <profile>
- <id>jetty8</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <phase>generate-sources</phase>
- <goals>
- <goal>add-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>src/main/jetty8</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
- <build>
- <plugins>
- <!-- use per test fork mode to avoid side effects -->
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <forkCount>1</forkCount>
- <reuseForks>false</reuseForks>
- <forkedProcessTimeoutInSeconds>1800</forkedProcessTimeoutInSeconds>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
deleted file mode 100644
index 3ab15f2..0000000
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
+++ /dev/null
@@ -1,212 +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.camel.component.jetty;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.component.http.CamelServlet;
-import org.apache.camel.component.http.HttpConsumer;
-import org.apache.camel.component.http.HttpMessage;
-import org.apache.camel.component.http.helper.HttpHelper;
-import org.apache.camel.impl.DefaultExchange;
-import org.eclipse.jetty.continuation.Continuation;
-import org.eclipse.jetty.continuation.ContinuationSupport;
-
-/**
- * Servlet which leverage <a href="http://wiki.eclipse.org/Jetty/Feature/Continuations">Jetty Continuations</a>.
- *
- * @version
- */
-public class CamelContinuationServlet extends CamelServlet {
-
- static final String EXCHANGE_ATTRIBUTE_NAME = "CamelExchange";
- static final String EXCHANGE_ATTRIBUTE_ID = "CamelExchangeId";
-
- private static final long serialVersionUID = 1L;
- // jetty will by default use 30000 millis as default timeout
- private Long continuationTimeout;
- // we must remember expired exchanges as Jetty will initiate a new continuation when we send
- // back the error when timeout occurred, and thus in the async callback we cannot check the
- // continuation if it was previously expired. So that's why we have our own map for that
- private final Map<String, String> expiredExchanges = new ConcurrentHashMap<String, String>();
-
- @Override
- protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
- log.trace("Service: {}", request);
-
- // is there a consumer registered for the request.
- HttpConsumer consumer = getServletResolveConsumerStrategy().resolve(request, getConsumers());
- if (consumer == null) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- if (consumer.getEndpoint().getHttpMethodRestrict() != null
- && !consumer.getEndpoint().getHttpMethodRestrict().equals(request.getMethod())) {
- response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- return;
- }
-
- if ("TRACE".equals(request.getMethod()) && !consumer.isTraceEnabled()) {
- response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- return;
- }
-
- final Exchange result = (Exchange) request.getAttribute(EXCHANGE_ATTRIBUTE_NAME);
- if (result == null) {
- // no asynchronous result so leverage continuation
- final Continuation continuation = ContinuationSupport.getContinuation(request);
- if (continuation.isInitial() && continuationTimeout != null) {
- // set timeout on initial
- continuation.setTimeout(continuationTimeout);
- }
-
- // are we suspended and a request is dispatched initially?
- if (consumer.isSuspended() && continuation.isInitial()) {
- response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
- return;
- }
-
- if (continuation.isExpired()) {
- String id = (String) continuation.getAttribute(EXCHANGE_ATTRIBUTE_ID);
- // remember this id as expired
- expiredExchanges.put(id, id);
- log.warn("Continuation expired of exchangeId: {}", id);
- response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
- return;
- }
-
- // a new request so create an exchange
- final Exchange exchange = new DefaultExchange(consumer.getEndpoint(), ExchangePattern.InOut);
-
- if (consumer.getEndpoint().isBridgeEndpoint()) {
- exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
- exchange.setProperty(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.TRUE);
- }
- if (consumer.getEndpoint().isDisableStreamCache()) {
- exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.TRUE);
- }
-
- HttpHelper.setCharsetFromContentType(request.getContentType(), exchange);
-
- exchange.setIn(new HttpMessage(exchange, request, response));
- // set context path as header
- String contextPath = consumer.getEndpoint().getPath();
- exchange.getIn().setHeader("CamelServletContextPath", contextPath);
-
- String httpPath = (String)exchange.getIn().getHeader(Exchange.HTTP_PATH);
- // here we just remove the CamelServletContextPath part from the HTTP_PATH
- if (contextPath != null
- && httpPath.startsWith(contextPath)) {
- exchange.getIn().setHeader(Exchange.HTTP_PATH,
- httpPath.substring(contextPath.length()));
- }
-
- if (log.isTraceEnabled()) {
- log.trace("Suspending continuation of exchangeId: {}", exchange.getExchangeId());
- }
- continuation.setAttribute(EXCHANGE_ATTRIBUTE_ID, exchange.getExchangeId());
-
- // we want to handle the UoW
- try {
- consumer.createUoW(exchange);
- } catch (Exception e) {
- log.error("Error processing request", e);
- throw new ServletException(e);
- }
-
- // must suspend before we process the exchange
- continuation.suspend();
-
- ClassLoader oldTccl = overrideTccl(exchange);
-
- if (log.isTraceEnabled()) {
- log.trace("Processing request for exchangeId: {}", exchange.getExchangeId());
- }
- // use the asynchronous API to process the exchange
-
- consumer.getAsyncProcessor().process(exchange, new AsyncCallback() {
- public void done(boolean doneSync) {
- // check if the exchange id is already expired
- boolean expired = expiredExchanges.remove(exchange.getExchangeId()) != null;
- if (!expired) {
- if (log.isTraceEnabled()) {
- log.trace("Resuming continuation of exchangeId: {}", exchange.getExchangeId());
- }
- // resume processing after both, sync and async callbacks
- continuation.setAttribute(EXCHANGE_ATTRIBUTE_NAME, exchange);
- continuation.resume();
- } else {
- log.warn("Cannot resume expired continuation of exchangeId: {}", exchange.getExchangeId());
- }
- }
- });
-
- if (oldTccl != null) {
- restoreTccl(exchange, oldTccl);
- }
-
- // return to let Jetty continuation to work as it will resubmit and invoke the service
- // method again when its resumed
- return;
- }
-
- try {
- // now lets output to the response
- if (log.isTraceEnabled()) {
- log.trace("Resumed continuation and writing response for exchangeId: {}", result.getExchangeId());
- }
- Integer bs = consumer.getEndpoint().getResponseBufferSize();
- if (bs != null) {
- log.trace("Using response buffer size: {}", bs);
- response.setBufferSize(bs);
- }
- consumer.getBinding().writeResponse(result, response);
- } catch (IOException e) {
- log.error("Error processing request", e);
- throw e;
- } catch (Exception e) {
- log.error("Error processing request", e);
- throw new ServletException(e);
- } finally {
- consumer.doneUoW(result);
- }
- }
-
- public Long getContinuationTimeout() {
- return continuationTimeout;
- }
-
- public void setContinuationTimeout(Long continuationTimeout) {
- this.continuationTimeout = continuationTimeout;
- }
-
- @Override
- public void destroy() {
- expiredExchanges.clear();
- super.destroy();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelFilterWrapper.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelFilterWrapper.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelFilterWrapper.java
deleted file mode 100644
index f247e5f..0000000
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelFilterWrapper.java
+++ /dev/null
@@ -1,71 +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.camel.component.jetty;
-
-import java.io.File;
-import java.io.IOException;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-/**
- * The camel filter wrapper that processes only initially dispatched requests.
- * Re-dispatched requests are ignored.
- */
-public class CamelFilterWrapper implements Filter {
-
- private Filter wrapped;
-
- public CamelFilterWrapper(Filter wrapped) {
- this.wrapped = wrapped;
- }
-
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
- if (request.getAttribute(CamelContinuationServlet.EXCHANGE_ATTRIBUTE_NAME) == null) {
- wrapped.doFilter(request, response, chain);
- } else {
- chain.doFilter(request, response);
- }
- }
-
- public void destroy() {
- wrapped.destroy();
- }
-
- public void init(FilterConfig config) throws ServletException {
- Object o = config.getServletContext().getAttribute("javax.servlet.context.tempdir");
- if (o == null) {
- //when run in embedded mode, Jetty 8 will forget to set this property,
- //but the MultiPartFilter requires it (will NPE if not set) so we'll
- //go ahead and set it to the default tmp dir on the system.
- try {
- File file = File.createTempFile("camel", "");
- file.delete();
- config.getServletContext().setAttribute("javax.servlet.context.tempdir",
- file.getParentFile());
- } catch (IOException e) {
- //ignore
- }
- }
- wrapped.init(config);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
deleted file mode 100644
index 1f4504c..0000000
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
+++ /dev/null
@@ -1,78 +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.camel.component.jetty;
-
-import java.util.concurrent.Executor;
-
-import javax.net.ssl.SSLContext;
-
-import org.apache.camel.util.ObjectHelper;
-import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-import org.eclipse.jetty.util.thread.QueuedThreadPool;
-
-public abstract class CamelHttpClient extends HttpClient {
-
- private boolean supportRedirect;
-
- public CamelHttpClient(SslContextFactory sslContextFactory) {
- super(sslContextFactory);
- }
-
- @Deprecated
- /**
- * It does nothing here, please setup SslContextFactory directly, it will be removed in Camel 2.16.0
- * @param context
- */
- public void setSSLContext(SSLContext context) {
- // do nothing here, please setup SslContextFactory directly.
- }
-
- @Override
- protected void doStart() throws Exception {
- if (!hasThreadPool()) {
- // if there is no thread pool then create a default thread pool using daemon threads
- QueuedThreadPool qtp = new QueuedThreadPool();
- // 16 max threads is the default in the http client
- qtp.setMaxThreads(16);
- qtp.setDaemon(true);
- // let the thread names indicate they are from the client
- qtp.setName("CamelJettyClient(" + ObjectHelper.getIdentityHashCode(this) + ")");
- setThreadPoolOrExecutor(qtp);
- }
- super.doStart();
- }
-
- protected abstract boolean hasThreadPool();
-
- protected abstract void setThreadPoolOrExecutor(Executor pool);
-
- public abstract void setProxy(String host, int port);
-
- public boolean isSupportRedirect() {
- return supportRedirect;
- }
-
- public void setSupportRedirect(boolean supportRedirect) {
- this.supportRedirect = supportRedirect;
- }
-
- public abstract String getProxyHost();
-
- public abstract int getProxyPort();
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelMultipartFilter.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelMultipartFilter.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelMultipartFilter.java
deleted file mode 100644
index 9a0c6ea..0000000
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelMultipartFilter.java
+++ /dev/null
@@ -1,31 +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.camel.component.jetty;
-
-import javax.servlet.Filter;
-
-/**
- * Please use the CamelFilterWrapper instead of using this classs
- */
-@Deprecated
-class CamelMultipartFilter extends CamelFilterWrapper {
-
- public CamelMultipartFilter(Filter wrapped) {
- super(wrapped);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
deleted file mode 100644
index 7b73a8a..0000000
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
+++ /dev/null
@@ -1,194 +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.camel.component.jetty;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.component.http.HttpConstants;
-import org.apache.camel.component.http.HttpHeaderFilterStrategy;
-import org.apache.camel.component.http.HttpOperationFailedException;
-import org.apache.camel.component.http.helper.HttpHelper;
-import org.apache.camel.spi.HeaderFilterStrategy;
-import org.apache.camel.util.IOHelper;
-import org.apache.camel.util.MessageHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @version
- */
-public class DefaultJettyHttpBinding implements JettyHttpBinding {
-
- private static final Logger LOG = LoggerFactory.getLogger(DefaultJettyHttpBinding.class);
- private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
- private boolean throwExceptionOnFailure;
- private boolean transferException;
- public DefaultJettyHttpBinding() {
-
- }
-
- public void populateResponse(Exchange exchange, JettyContentExchange httpExchange) throws Exception {
- int responseCode = httpExchange.getResponseStatus();
-
- LOG.debug("HTTP responseCode: {}", responseCode);
-
- Message in = exchange.getIn();
- if (!isThrowExceptionOnFailure()) {
- // if we do not use failed exception then populate response for all response codes
- populateResponse(exchange, httpExchange, in, getHeaderFilterStrategy(), responseCode);
- } else {
- if (responseCode >= 100 && responseCode < 300) {
- // only populate response for OK response
- populateResponse(exchange, httpExchange, in, getHeaderFilterStrategy(), responseCode);
- } else {
- // operation failed so populate exception to throw
- Exception ex = populateHttpOperationFailedException(exchange, httpExchange, responseCode);
- if (ex != null) {
- throw ex;
- } else {
- populateResponse(exchange, httpExchange, in, getHeaderFilterStrategy(), responseCode);
- }
- }
- }
- }
-
- public HeaderFilterStrategy getHeaderFilterStrategy() {
- return headerFilterStrategy;
- }
-
- public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) {
- this.headerFilterStrategy = headerFilterStrategy;
- }
-
- public boolean isThrowExceptionOnFailure() {
- return throwExceptionOnFailure;
- }
-
- public void setThrowExceptionOnFailure(boolean throwExceptionOnFailure) {
- this.throwExceptionOnFailure = throwExceptionOnFailure;
- }
-
- public boolean isTransferException() {
- return transferException;
- }
-
- public void setTransferException(boolean transferException) {
- this.transferException = transferException;
- }
-
- protected void populateResponse(Exchange exchange, JettyContentExchange httpExchange,
- Message in, HeaderFilterStrategy strategy, int responseCode) throws IOException {
- Message answer = exchange.getOut();
-
- answer.setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode);
-
- // must use response fields to get the http headers as
- // httpExchange.getHeaders() does not work well with multi valued headers
- Map<String, Collection<String>> headers = httpExchange.getResponseHeaders();
- for (Map.Entry<String, Collection<String>> ent : headers.entrySet()) {
- String name = ent.getKey();
- Collection<String> values = ent.getValue();
- for (String value : values) {
- if (name.toLowerCase().equals("content-type")) {
- name = Exchange.CONTENT_TYPE;
- exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.getCharsetNameFromContentType(value));
- }
- if (strategy != null && !strategy.applyFilterToExternalHeaders(name, value, exchange)) {
- HttpHelper.appendHeader(answer.getHeaders(), name, value);
- }
- }
- }
-
- // preserve headers from in by copying any non existing headers
- // to avoid overriding existing headers with old values
- MessageHelper.copyHeaders(exchange.getIn(), answer, false);
-
- // extract body after headers has been set as we want to ensure content-type from Jetty HttpExchange
- // has been populated first
- answer.setBody(extractResponseBody(exchange, httpExchange));
- }
-
- protected Exception populateHttpOperationFailedException(Exchange exchange, JettyContentExchange httpExchange,
- int responseCode) throws IOException {
- HttpOperationFailedException answer;
- String uri = httpExchange.getUrl();
- Map<String, String> headers = getSimpleMap(httpExchange.getResponseHeaders());
- Object responseBody = extractResponseBody(exchange, httpExchange);
-
- if (transferException && responseBody != null && responseBody instanceof Exception) {
- // if the response was a serialized exception then use that
- return (Exception) responseBody;
- }
-
- // make a defensive copy of the response body in the exception so its detached from the cache
- String copy = null;
- if (responseBody != null) {
- copy = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, responseBody);
- }
-
- if (responseCode >= 300 && responseCode < 400) {
- Collection<String> loc = httpExchange.getResponseHeaders().get("location");
- if (loc != null && !loc.isEmpty()) {
- String locationHeader = loc.iterator().next();
- answer = new HttpOperationFailedException(uri, responseCode, null, locationHeader, headers, copy);
- } else {
- // no redirect location
- answer = new HttpOperationFailedException(uri, responseCode, null, null, headers, copy);
- }
- } else {
- // internal server error (error code 500)
- answer = new HttpOperationFailedException(uri, responseCode, null, null, headers, copy);
- }
-
- return answer;
- }
-
- protected Object extractResponseBody(Exchange exchange, JettyContentExchange httpExchange) throws IOException {
- Map<String, String> headers = getSimpleMap(httpExchange.getResponseHeaders());
- String contentType = headers.get(Exchange.CONTENT_TYPE);
-
- // if content type is serialized java object, then de-serialize it to a Java object
- if (contentType != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(contentType)) {
- try {
- InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, httpExchange.getResponseContentBytes());
- return HttpHelper.deserializeJavaObjectFromStream(is);
- } catch (Exception e) {
- throw new RuntimeCamelException("Cannot deserialize body to Java object", e);
- }
- } else {
- // just grab the raw content body
- return httpExchange.getBody();
- }
- }
-
- Map<String, String> getSimpleMap(Map<String, Collection<String>> headers) {
- Map<String, String> result = new HashMap<String , String>();
- for (String key : headers.keySet()) {
- Collection<String> valueCol = headers.get(key);
- String value = (valueCol == null) ? null : valueCol.iterator().next();
- result.put(key, value);
- }
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
deleted file mode 100644
index 94d272a..0000000
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
+++ /dev/null
@@ -1,70 +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.camel.component.jetty;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Collection;
-import java.util.Map;
-
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.Exchange;
-import org.eclipse.jetty.client.HttpClient;
-
-public interface JettyContentExchange {
- void init(Exchange exchange, JettyHttpBinding jettyBinding,
- final HttpClient client, AsyncCallback callback);
-
- // Methods to prepare the request
- void setRequestContentType(String contentType);
-
- void setMethod(String method);
-
- void setTimeout(long timeout);
-
- void setURL(String url);
-
- void setRequestContent(byte[] byteArray);
-
- void setRequestContent(String data, String charset) throws UnsupportedEncodingException;
-
- void setRequestContent(InputStream ins);
-
- void addRequestHeader(String key, String s);
-
- void setSupportRedirect(boolean supportRedirect);
-
- /*
- * Send using jetty HttpClient and return. The callback will be called when the response
- * arrives
- */
- void send(HttpClient client) throws IOException;
-
- // Methods to retrieve the response
-
- byte[] getBody();
-
- String getUrl();
-
- int getResponseStatus();
-
- byte[] getResponseContentBytes();
-
- Map<String, Collection<String>> getResponseHeaders();
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyConverter.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyConverter.java
deleted file mode 100644
index 6ed174f..0000000
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyConverter.java
+++ /dev/null
@@ -1,53 +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.camel.component.jetty;
-
-import org.apache.camel.Converter;
-import org.apache.camel.Exchange;
-import org.apache.camel.FallbackConverter;
-import org.apache.camel.spi.TypeConverterRegistry;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.server.Response;
-
-/**
- * @version
- */
-@Converter
-public final class JettyConverter {
- private JettyConverter() {
- //Helper class
- }
-
- @Converter
- public static String toString(Response response) {
- return response.toString();
- }
-
- @FallbackConverter
- @SuppressWarnings("unchecked")
- public static <T> T convertTo(Class<T> type, Exchange exchange, Object value, TypeConverterRegistry registry) {
- if (value != null) {
- // should not try to convert Request as its not possible
- if (Request.class.isAssignableFrom(value.getClass())) {
- return (T) Void.TYPE;
- }
- }
-
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpBinding.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpBinding.java
deleted file mode 100644
index 75e9863..0000000
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpBinding.java
+++ /dev/null
@@ -1,86 +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.camel.component.jetty;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.spi.HeaderFilterStrategy;
-
-/**
- * Jetty specific binding to parse the response when using {@link org.apache.camel.component.jetty.JettyHttpProducer}
- *
- * @version
- */
-public interface JettyHttpBinding {
-
- /**
- * Parses the response from the Jetty client.
- *
- * @param exchange the Exchange which to populate with the response
- * @param httpExchange the response from the Jetty client
- * @throws Exception is thrown if error parsing response
- */
- void populateResponse(Exchange exchange, JettyContentExchange httpExchange) throws Exception;
-
- /**
- * Gets the header filter strategy
- *
- * @return the strategy
- */
- HeaderFilterStrategy getHeaderFilterStrategy();
-
- /**
- * Sets the header filter strategy to use.
- * <p/>
- * Will default use {@link org.apache.camel.component.http.HttpHeaderFilterStrategy}
- *
- * @param headerFilterStrategy the custom strategy
- */
- void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy);
-
- /**
- * Whether to throw {@link org.apache.camel.component.http.HttpOperationFailedException}
- * in case of response code != 200.
- *
- * @param throwExceptionOnFailure <tt>true</tt> to throw exception
- */
- void setThrowExceptionOnFailure(boolean throwExceptionOnFailure);
-
- /**
- * Whether to throw {@link org.apache.camel.component.http.HttpOperationFailedException}
- * in case of response code != 200.
- *
- * @return <tt>true</tt> to throw exception
- */
- boolean isThrowExceptionOnFailure();
-
- /**
- * Whether to transfer exception back as a serialized java object
- * if processing failed due to an exception
- *
- * @param transferException <tt>true</tt> to transfer exception
- */
- void setTransferException(boolean transferException);
-
- /**
- * Whether to transfer exception back as a serialized java object
- * if processing failed due to an exception
- *
- * @return <tt>true</tt> to transfer exception
- */
- boolean isTransferException();
-
-}