camel-http-common - as a common module
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f685f361 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f685f361 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f685f361 Branch: refs/heads/master Commit: f685f36170832bfe20dab6ea49a1bd5c5ca049d1 Parents: e191504 Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Jul 23 09:49:15 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Jul 23 15:04:31 2015 +0200 ---------------------------------------------------------------------- components/camel-http-common/pom.xml | 7 +- .../services/org/apache/camel/TypeConverter | 18 + .../camel/component/http/CamelServlet.java | 248 --------- .../component/http/DefaultHttpBinding.java | 498 ------------------- .../camel/component/http/HttpBinding.java | 162 ------ .../component/http/HttpCommonComponent.java | 75 --- .../component/http/HttpCommonEndpoint.java | 383 -------------- .../camel/component/http/HttpComponent.java | 45 +- .../camel/component/http/HttpConfiguration.java | 146 ------ .../camel/component/http/HttpConstants.java | 29 -- .../camel/component/http/HttpConsumer.java | 83 ---- .../camel/component/http/HttpConverter.java | 100 ---- .../camel/component/http/HttpEndpoint.java | 14 +- .../http/HttpHeaderFilterStrategy.java | 52 -- .../camel/component/http/HttpMessage.java | 81 --- .../http/HttpOperationFailedException.java | 75 --- .../component/http/HttpPollingConsumer.java | 4 +- .../camel/component/http/HttpProducer.java | 8 +- .../http/HttpProtocolHeaderFilterStrategy.java | 88 ---- .../HttpServletResolveConsumerStrategy.java | 50 -- .../component/http/HttpServletUrlRewrite.java | 45 -- ...xtParametersSecureProtocolSocketFactory.java | 3 +- .../http/ServletResolveConsumerStrategy.java | 37 -- .../apache/camel/component/http/UrlRewrite.java | 41 -- .../http/helper/CamelFileDataSource.java | 53 -- .../camel/component/http/helper/HttpHelper.java | 461 ----------------- .../http/helper/HttpMethodsHelper.java | 52 ++ .../UrlRewriteHttpServletRequestAdapter.java | 50 -- .../services/org/apache/camel/TypeConverter | 1 - .../camel/component/http/GoogleUrlRewrite.java | 1 + .../http/HttpAuthMethodPriorityTest.java | 3 +- .../http/HttpConnectionManagerSettingTest.java | 1 + ...tpEndpointOptionsNotChangeComponentTest.java | 2 + .../camel/component/http/HttpGetTest.java | 1 - .../http/HttpHeaderFilterStrategyTest.java | 1 + .../component/http/HttpPostWithBodyTest.java | 1 + .../http/HttpProducerSelectMethodTest.java | 1 + .../component/http/HttpProxyAuthBasicTest.java | 3 +- .../component/http/HttpProxyAuthDigestTest.java | 3 +- .../component/http/HttpProxyAuthNTLMTest.java | 3 +- .../camel/component/http/HttpProxyTest.java | 1 + .../http/HttpQueryGoogleProxyTest.java | 3 +- .../http/HttpReferenceParameterTest.java | 1 + .../component/http/helper/HttpHelperTest.java | 41 +- .../http/helper/HttpMethodsHelperTest.java | 99 ++++ 45 files changed, 242 insertions(+), 2832 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http-common/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-http-common/pom.xml b/components/camel-http-common/pom.xml index 87b166e..4736089 100644 --- a/components/camel-http-common/pom.xml +++ b/components/camel-http-common/pom.xml @@ -33,7 +33,7 @@ <camel.osgi.import.before.defaults> javax.servlet.*;version="${servlet-version-range}" </camel.osgi.import.before.defaults> - <camel.osgi.export.pkg>org.apache.camel.http.*</camel.osgi.export.pkg> + <camel.osgi.export.pkg>org.apache.camel.http.common.*</camel.osgi.export.pkg> </properties> <dependencies> @@ -47,11 +47,6 @@ <artifactId>geronimo-servlet_3.0_spec</artifactId> </dependency> - <dependency> - <groupId>commons-codec</groupId> - <artifactId>commons-codec</artifactId> - </dependency> - <!-- testing --> <dependency> <groupId>org.apache.camel</groupId> http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http-common/src/main/resources/META-INF/services/org/apache/camel/TypeConverter ---------------------------------------------------------------------- diff --git a/components/camel-http-common/src/main/resources/META-INF/services/org/apache/camel/TypeConverter b/components/camel-http-common/src/main/resources/META-INF/services/org/apache/camel/TypeConverter new file mode 100644 index 0000000..adacd8d --- /dev/null +++ b/components/camel-http-common/src/main/resources/META-INF/services/org/apache/camel/TypeConverter @@ -0,0 +1,18 @@ +# +# 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. +# + +org.apache.camel.http.common.HttpConverter http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java b/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java deleted file mode 100644 index b6cece8..0000000 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java +++ /dev/null @@ -1,248 +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.http; - -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.camel.Exchange; -import org.apache.camel.ExchangePattern; -import org.apache.camel.component.http.helper.HttpHelper; -import org.apache.camel.impl.DefaultExchange; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @version - */ -public class CamelServlet extends HttpServlet { - private static final long serialVersionUID = -7061982839117697829L; - protected final Logger log = LoggerFactory.getLogger(getClass()); - - /** - * We have to define this explicitly so the name can be set as we can not always be - * sure that it is already set via the init method - */ - private String servletName; - - private ServletResolveConsumerStrategy servletResolveConsumerStrategy = new HttpServletResolveConsumerStrategy(); - private final ConcurrentMap<String, HttpConsumer> consumers = new ConcurrentHashMap<String, HttpConsumer>(); - - @Override - public void init(ServletConfig config) throws ServletException { - super.init(config); - this.servletName = config.getServletName(); - } - - @Override - protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - log.trace("Service: {}", request); - - // Is there a consumer registered for the request. - HttpConsumer consumer = resolve(request); - if (consumer == null) { - log.debug("No consumer to service request {}", request); - response.sendError(HttpServletResponse.SC_NOT_FOUND); - return; - } - - // are we suspended? - if (consumer.isSuspended()) { - log.debug("Consumer suspended, cannot service request {}", request); - response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); - return; - } - - // if its an OPTIONS request then return which method is allowed - if ("OPTIONS".equals(request.getMethod())) { - String s; - if (consumer.getEndpoint().getHttpMethodRestrict() != null) { - s = "OPTIONS," + consumer.getEndpoint().getHttpMethodRestrict(); - } else { - // allow them all - s = "GET,HEAD,POST,PUT,DELETE,TRACE,OPTIONS,CONNECT,PATCH"; - } - response.addHeader("Allow", s); - response.setStatus(HttpServletResponse.SC_OK); - return; - } - - if (consumer.getEndpoint().getHttpMethodRestrict() != null - && !consumer.getEndpoint().getHttpMethodRestrict().contains(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; - } - - // create exchange and set data on it - 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); - } - - // we override the classloader before building the HttpMessage just in case the binding - // does some class resolution - ClassLoader oldTccl = overrideTccl(exchange); - 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())); - } - - // we want to handle the UoW - try { - consumer.createUoW(exchange); - } catch (Exception e) { - log.error("Error processing request", e); - throw new ServletException(e); - } - - try { - if (log.isTraceEnabled()) { - log.trace("Processing request for exchangeId: {}", exchange.getExchangeId()); - } - // process the exchange - consumer.getProcessor().process(exchange); - } catch (Exception e) { - exchange.setException(e); - } - - try { - // now lets output to the response - if (log.isTraceEnabled()) { - log.trace("Writing response for exchangeId: {}", exchange.getExchangeId()); - } - Integer bs = consumer.getEndpoint().getResponseBufferSize(); - if (bs != null) { - log.trace("Using response buffer size: {}", bs); - response.setBufferSize(bs); - } - consumer.getBinding().writeResponse(exchange, 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(exchange); - restoreTccl(exchange, oldTccl); - } - } - - /** - * @deprecated use {@link ServletResolveConsumerStrategy#resolve(javax.servlet.http.HttpServletRequest, java.util.Map)} - */ - @Deprecated - protected HttpConsumer resolve(HttpServletRequest request) { - return getServletResolveConsumerStrategy().resolve(request, getConsumers()); - } - - public void connect(HttpConsumer consumer) { - log.debug("Connecting consumer: {}", consumer); - consumers.put(consumer.getEndpoint().getEndpointUri(), consumer); - } - - public void disconnect(HttpConsumer consumer) { - log.debug("Disconnecting consumer: {}", consumer); - consumers.remove(consumer.getEndpoint().getEndpointUri()); - } - - public String getServletName() { - return servletName; - } - - public void setServletName(String servletName) { - this.servletName = servletName; - } - - public ServletResolveConsumerStrategy getServletResolveConsumerStrategy() { - return servletResolveConsumerStrategy; - } - - public void setServletResolveConsumerStrategy(ServletResolveConsumerStrategy servletResolveConsumerStrategy) { - this.servletResolveConsumerStrategy = servletResolveConsumerStrategy; - } - - public Map<String, HttpConsumer> getConsumers() { - return Collections.unmodifiableMap(consumers); - } - - /** - * Override the Thread Context ClassLoader if need be. - * - * @param exchange - * @return old classloader if overridden; otherwise returns null - */ - protected ClassLoader overrideTccl(final Exchange exchange) { - ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); - ClassLoader appCtxCl = exchange.getContext().getApplicationContextClassLoader(); - if (oldClassLoader == null || appCtxCl == null) { - return null; - } - - if (!oldClassLoader.equals(appCtxCl)) { - Thread.currentThread().setContextClassLoader(appCtxCl); - if (log.isTraceEnabled()) { - log.trace("Overrode TCCL for exchangeId {} to {} on thread {}", - new Object[] {exchange.getExchangeId(), appCtxCl, Thread.currentThread().getName()}); - } - return oldClassLoader; - } - return null; - } - - /** - * Restore the Thread Context ClassLoader if the old TCCL is not null. - */ - protected void restoreTccl(final Exchange exchange, ClassLoader oldTccl) { - if (oldTccl == null) { - return; - } - Thread.currentThread().setContextClassLoader(oldTccl); - if (log.isTraceEnabled()) { - log.trace("Restored TCCL for exchangeId {} to {} on thread {}", - new String[] {exchange.getExchangeId(), oldTccl.toString(), Thread.currentThread().getName()}); - } - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java deleted file mode 100644 index ee5519f..0000000 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java +++ /dev/null @@ -1,498 +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.http; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.Serializable; -import java.net.URLDecoder; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.Map; -import javax.activation.DataHandler; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.camel.Endpoint; -import org.apache.camel.Exchange; -import org.apache.camel.InvalidPayloadException; -import org.apache.camel.Message; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.StreamCache; -import org.apache.camel.component.http.helper.CamelFileDataSource; -import org.apache.camel.component.http.helper.HttpHelper; -import org.apache.camel.converter.stream.CachedOutputStream; -import org.apache.camel.spi.HeaderFilterStrategy; -import org.apache.camel.util.GZIPHelper; -import org.apache.camel.util.IOHelper; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Binding between {@link HttpMessage} and {@link HttpServletResponse}. - * <p/> - * Uses by default the {@link org.apache.camel.component.http.HttpHeaderFilterStrategy} - * - * @version - */ -public class DefaultHttpBinding implements HttpBinding { - - private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpBinding.class); - private boolean useReaderForPayload; - private boolean eagerCheckContentAvailable; - private boolean transferException; - private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy(); - - public DefaultHttpBinding() { - } - - @Deprecated - public DefaultHttpBinding(HeaderFilterStrategy headerFilterStrategy) { - this.headerFilterStrategy = headerFilterStrategy; - } - - @Deprecated - public DefaultHttpBinding(HttpEndpoint endpoint) { - this.headerFilterStrategy = endpoint.getHeaderFilterStrategy(); - this.transferException = endpoint.isTransferException(); - } - - public void readRequest(HttpServletRequest request, HttpMessage message) { - LOG.trace("readRequest {}", request); - - // lets force a parse of the body and headers - message.getBody(); - // populate the headers from the request - Map<String, Object> headers = message.getHeaders(); - - //apply the headerFilterStrategy - Enumeration<?> names = request.getHeaderNames(); - while (names.hasMoreElements()) { - String name = (String)names.nextElement(); - String value = request.getHeader(name); - // use http helper to extract parameter value as it may contain multiple values - Object extracted = HttpHelper.extractHttpParameterValue(value); - // mapping the content-type - if (name.toLowerCase().equals("content-type")) { - name = Exchange.CONTENT_TYPE; - } - if (headerFilterStrategy != null - && !headerFilterStrategy.applyFilterToExternalHeaders(name, extracted, message.getExchange())) { - HttpHelper.appendHeader(headers, name, extracted); - } - } - - if (request.getCharacterEncoding() != null) { - headers.put(Exchange.HTTP_CHARACTER_ENCODING, request.getCharacterEncoding()); - message.getExchange().setProperty(Exchange.CHARSET_NAME, request.getCharacterEncoding()); - } - - try { - populateRequestParameters(request, message); - } catch (Exception e) { - throw new RuntimeCamelException("Cannot read request parameters due " + e.getMessage(), e); - } - - Object body = message.getBody(); - // reset the stream cache if the body is the instance of StreamCache - if (body instanceof StreamCache) { - ((StreamCache)body).reset(); - } - - // store the method and query and other info in headers as String types - headers.put(Exchange.HTTP_METHOD, request.getMethod()); - headers.put(Exchange.HTTP_QUERY, request.getQueryString()); - headers.put(Exchange.HTTP_URL, request.getRequestURL().toString()); - headers.put(Exchange.HTTP_URI, request.getRequestURI()); - headers.put(Exchange.HTTP_PATH, request.getPathInfo()); - headers.put(Exchange.CONTENT_TYPE, request.getContentType()); - - if (LOG.isTraceEnabled()) { - LOG.trace("HTTP method {}", request.getMethod()); - LOG.trace("HTTP query {}", request.getQueryString()); - LOG.trace("HTTP url {}", request.getRequestURL()); - LOG.trace("HTTP uri {}", request.getRequestURI()); - LOG.trace("HTTP path {}", request.getPathInfo()); - LOG.trace("HTTP content-type {}", request.getContentType()); - } - - // if content type is serialized java object, then de-serialize it to a Java object - if (request.getContentType() != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(request.getContentType())) { - try { - InputStream is = message.getExchange().getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, body); - Object object = HttpHelper.deserializeJavaObjectFromStream(is, message.getExchange().getContext()); - if (object != null) { - message.setBody(object); - } - } catch (Exception e) { - throw new RuntimeCamelException("Cannot deserialize body to Java object", e); - } - } - - populateAttachments(request, message); - } - - protected void populateRequestParameters(HttpServletRequest request, HttpMessage message) throws Exception { - //we populate the http request parameters without checking the request method - Map<String, Object> headers = message.getHeaders(); - Enumeration<?> names = request.getParameterNames(); - while (names.hasMoreElements()) { - String name = (String)names.nextElement(); - // there may be multiple values for the same name - String[] values = request.getParameterValues(name); - LOG.trace("HTTP parameter {} = {}", name, values); - - if (values != null) { - for (String value : values) { - if (headerFilterStrategy != null - && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) { - HttpHelper.appendHeader(headers, name, value); - } - } - } - } - - LOG.trace("HTTP method {} with Content-Type {}", request.getMethod(), request.getContentType()); - Boolean flag = message.getHeader(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.class); - boolean skipWwwFormUrlEncoding = flag != null ? flag : false; - if (request.getMethod().equals("POST") && request.getContentType() != null - && request.getContentType().startsWith(HttpConstants.CONTENT_TYPE_WWW_FORM_URLENCODED) - && !skipWwwFormUrlEncoding) { - String charset = request.getCharacterEncoding(); - if (charset == null) { - charset = "UTF-8"; - } - // Push POST form params into the headers to retain compatibility with DefaultHttpBinding - String body = message.getBody(String.class); - if (ObjectHelper.isNotEmpty(body)) { - for (String param : body.split("&")) { - String[] pair = param.split("=", 2); - if (pair.length == 2) { - String name = URLDecoder.decode(pair[0], charset); - String value = URLDecoder.decode(pair[1], charset); - if (headerFilterStrategy != null - && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) { - HttpHelper.appendHeader(headers, name, value); - } - } else { - throw new IllegalArgumentException("Invalid parameter, expected to be a pair but was " + param); - } - } - } - } - } - - protected void populateAttachments(HttpServletRequest request, HttpMessage message) { - // check if there is multipart files, if so will put it into DataHandler - Enumeration<?> names = request.getAttributeNames(); - while (names.hasMoreElements()) { - String name = (String) names.nextElement(); - Object object = request.getAttribute(name); - LOG.trace("HTTP attachment {} = {}", name, object); - if (object instanceof File) { - String fileName = request.getParameter(name); - message.addAttachment(fileName, new DataHandler(new CamelFileDataSource((File)object, fileName))); - } - } - } - - public void writeResponse(Exchange exchange, HttpServletResponse response) throws IOException { - Message target = exchange.hasOut() ? exchange.getOut() : exchange.getIn(); - if (exchange.isFailed()) { - if (exchange.getException() != null) { - doWriteExceptionResponse(exchange.getException(), response); - } else { - // it must be a fault, no need to check for the fault flag on the message - doWriteFaultResponse(target, response, exchange); - } - } else { - if (exchange.hasOut()) { - // just copy the protocol relates header if we do not have them - copyProtocolHeaders(exchange.getIn(), exchange.getOut()); - } - doWriteResponse(target, response, exchange); - } - } - - private void copyProtocolHeaders(Message request, Message response) { - if (request.getHeader(Exchange.CONTENT_ENCODING) != null) { - String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING, String.class); - response.setHeader(Exchange.CONTENT_ENCODING, contentEncoding); - } - if (checkChunked(response, response.getExchange())) { - response.setHeader(Exchange.TRANSFER_ENCODING, "chunked"); - } - } - - public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException { - // 500 for internal server error - response.setStatus(500); - - if (isTransferException()) { - // transfer the exception as a serialized java object - HttpHelper.writeObjectToServletResponse(response, exception); - } else { - // write stacktrace as plain text - response.setContentType("text/plain"); - PrintWriter pw = response.getWriter(); - exception.printStackTrace(pw); - pw.flush(); - } - } - - public void doWriteFaultResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException { - message.setHeader(Exchange.HTTP_RESPONSE_CODE, 500); - doWriteResponse(message, response, exchange); - } - - public void doWriteResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException { - // set the status code in the response. Default is 200. - if (message.getHeader(Exchange.HTTP_RESPONSE_CODE) != null) { - int code = message.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class); - response.setStatus(code); - } - // set the content type in the response. - String contentType = MessageHelper.getContentType(message); - if (contentType != null) { - response.setContentType(contentType); - } - - // append headers - // must use entrySet to ensure case of keys is preserved - for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); - // use an iterator as there can be multiple values. (must not use a delimiter) - final Iterator<?> it = ObjectHelper.createIterator(value, null); - while (it.hasNext()) { - String headerValue = exchange.getContext().getTypeConverter().convertTo(String.class, it.next()); - if (headerValue != null && headerFilterStrategy != null - && !headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue, exchange)) { - response.addHeader(key, headerValue); - } - } - } - - // write the body. - if (message.getBody() != null) { - if (GZIPHelper.isGzip(message)) { - doWriteGZIPResponse(message, response, exchange); - } else { - doWriteDirectResponse(message, response, exchange); - } - } - } - - protected boolean isText(String contentType) { - if (contentType != null) { - String temp = contentType.toLowerCase(); - if (temp.indexOf("text") >= 0 || temp.indexOf("html") >= 0) { - return true; - } - } - return false; - } - - protected int copyStream(InputStream is, OutputStream os, int bufferSize) throws IOException { - try { - // copy stream, and must flush on each write as etc Jetty has better performance when - // flushing after writing to its servlet output stream - return IOHelper.copy(is, os, bufferSize, true); - } finally { - IOHelper.close(os, is); - } - } - - protected void doWriteDirectResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException { - // if content type is serialized Java object, then serialize and write it to the response - String contentType = message.getHeader(Exchange.CONTENT_TYPE, String.class); - if (contentType != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(contentType)) { - try { - Object object = message.getMandatoryBody(Serializable.class); - HttpHelper.writeObjectToServletResponse(response, object); - // object is written so return - return; - } catch (InvalidPayloadException e) { - throw new IOException(e); - } - } - - // prefer streaming - InputStream is = null; - if (checkChunked(message, exchange)) { - is = message.getBody(InputStream.class); - } else { - // try to use input stream first, so we can copy directly - if (!isText(contentType)) { - is = exchange.getContext().getTypeConverter().tryConvertTo(InputStream.class, message.getBody()); - } - } - - if (is != null) { - ServletOutputStream os = response.getOutputStream(); - if (!checkChunked(message, exchange)) { - CachedOutputStream stream = new CachedOutputStream(exchange); - try { - // copy directly from input stream to the cached output stream to get the content length - int len = copyStream(is, stream, response.getBufferSize()); - // we need to setup the length if message is not chucked - response.setContentLength(len); - OutputStream current = stream.getCurrentStream(); - if (current instanceof ByteArrayOutputStream) { - if (LOG.isDebugEnabled()) { - LOG.debug("Streaming (direct) response in non-chunked mode with content-length {}"); - } - ByteArrayOutputStream bos = (ByteArrayOutputStream) current; - bos.writeTo(os); - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("Streaming response in non-chunked mode with content-length {} and buffer size: {}", len, len); - } - copyStream(stream.getInputStream(), os, len); - } - } finally { - IOHelper.close(is, os); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("Streaming response in chunked mode with buffer size {}", response.getBufferSize()); - } - copyStream(is, os, response.getBufferSize()); - } - } else { - // not convertable as a stream so fallback as a String - String data = message.getBody(String.class); - if (data != null) { - // set content length and encoding before we write data - String charset = IOHelper.getCharsetName(exchange, true); - final int dataByteLength = data.getBytes(charset).length; - response.setCharacterEncoding(charset); - response.setContentLength(dataByteLength); - if (LOG.isDebugEnabled()) { - LOG.debug("Writing response in non-chunked mode as plain text with content-length {} and buffer size: {}", dataByteLength, response.getBufferSize()); - } - try { - response.getWriter().print(data); - } finally { - response.getWriter().flush(); - } - } - } - } - - protected boolean checkChunked(Message message, Exchange exchange) { - boolean answer = true; - if (message.getHeader(Exchange.HTTP_CHUNKED) == null) { - // check the endpoint option - Endpoint endpoint = exchange.getFromEndpoint(); - if (endpoint instanceof HttpEndpoint) { - answer = ((HttpEndpoint)endpoint).isChunked(); - } - } else { - answer = message.getHeader(Exchange.HTTP_CHUNKED, boolean.class); - } - return answer; - } - - protected void doWriteGZIPResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException { - byte[] bytes; - try { - bytes = message.getMandatoryBody(byte[].class); - } catch (InvalidPayloadException e) { - throw ObjectHelper.wrapRuntimeCamelException(e); - } - - byte[] data = GZIPHelper.compressGZIP(bytes); - ServletOutputStream os = response.getOutputStream(); - try { - if (LOG.isDebugEnabled()) { - LOG.debug("Streaming response as GZIP in non-chunked mode with content-length {} and buffer size: {}", data.length, response.getBufferSize()); - } - response.setContentLength(data.length); - os.write(data); - os.flush(); - } finally { - IOHelper.close(os); - } - } - - public Object parseBody(HttpMessage httpMessage) throws IOException { - // lets assume the body is a reader - HttpServletRequest request = httpMessage.getRequest(); - // there is only a body if we have a content length, or its -1 to indicate unknown length - int len = request.getContentLength(); - LOG.trace("HttpServletRequest content-length: {}", len); - if (len == 0) { - return null; - } - if (isUseReaderForPayload()) { - // use reader to read the response body - return request.getReader(); - } else { - // if we do not know if there is any data at all, then make sure to check the stream first - if (len < 0 && isEagerCheckContentAvailable()) { - InputStream is = request.getInputStream(); - if (is.available() == 0) { - // no data so return null - return null; - } - } - // read the response body from servlet request - return HttpHelper.readRequestBodyFromServletRequest(request, httpMessage.getExchange()); - } - } - - public boolean isUseReaderForPayload() { - return useReaderForPayload; - } - - public void setUseReaderForPayload(boolean useReaderForPayload) { - this.useReaderForPayload = useReaderForPayload; - } - - public boolean isEagerCheckContentAvailable() { - return eagerCheckContentAvailable; - } - - public void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable) { - this.eagerCheckContentAvailable = eagerCheckContentAvailable; - } - - public boolean isTransferException() { - return transferException; - } - - public void setTransferException(boolean transferException) { - this.transferException = transferException; - } - - public HeaderFilterStrategy getHeaderFilterStrategy() { - return headerFilterStrategy; - } - - public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) { - this.headerFilterStrategy = headerFilterStrategy; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java deleted file mode 100644 index eb6670c..0000000 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java +++ /dev/null @@ -1,162 +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.http; - -import java.io.IOException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.spi.HeaderFilterStrategy; - -/** - * A pluggable strategy for configuring the http binding so reading request and writing response - * can be customized using the Java Servlet API. - * <p/> - * This is also used by the <tt>camel-jetty</tt> component in the <tt>JettyHttpConsumer</tt> class. - * - * @version - */ -public interface HttpBinding { - - /** - * Strategy to read the given request and bindings it to the given message. - * - * @param request the request - * @param message the message to populate with data from request - */ - void readRequest(HttpServletRequest request, HttpMessage message); - - /** - * Parses the body from a {@link org.apache.camel.component.http.HttpMessage} - * - * @param httpMessage the http message - * @return the parsed body returned as either a {@link java.io.InputStream} or a {@link java.io.Reader} - * depending on the {@link #setUseReaderForPayload(boolean)} property. - * @throws java.io.IOException can be thrown - */ - Object parseBody(HttpMessage httpMessage) throws IOException; - - /** - * Writes the exchange to the servlet response. - * <p/> - * Default implementation will delegate to the following methods depending on the status of the exchange - * <ul> - * <li>doWriteResponse - processing returns a OUT message </li> - * <li>doWriteFaultResponse - processing returns a fault message</li> - * <li>doWriteResponse - processing returns an exception and status code 500</li> - * </ul> - * - * @param exchange the exchange - * @param response the http response - * @throws java.io.IOException can be thrown from http response - */ - void writeResponse(Exchange exchange, HttpServletResponse response) throws IOException; - - /** - * Strategy method that writes the response to the http response stream when an exception occurred - * - * @param exception the exception occurred - * @param response the http response - * @throws java.io.IOException can be thrown from http response - */ - void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException; - - /** - * Strategy method that writes the response to the http response stream for a fault message - * - * @param message the fault message - * @param response the http response - * @param exchange the exchange to provide context for header filtering - * @throws java.io.IOException can be thrown from http response - */ - void doWriteFaultResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException; - - /** - * Strategy method that writes the response to the http response stream for an OUT message - * - * @param message the OUT message - * @param response the http response - * @param exchange the exchange to provide context for header filtering - * @throws java.io.IOException can be thrown from http response - */ - void doWriteResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException; - - /** - * Should reader by used instead of input stream. - * - * @see #setUseReaderForPayload(boolean) for more details - * @return <tt>true</tt> if reader should be used - */ - boolean isUseReaderForPayload(); - - /** - * Should the {@link javax.servlet.http.HttpServletRequest#getReader()} be exposed as the payload of input messages in the Camel - * {@link org.apache.camel.Message#getBody()} or not. If false then the {@link javax.servlet.http.HttpServletRequest#getInputStream()} will be exposed. - * <p/> - * Is default <tt>false</tt>. - * - * @param useReaderForPayload whether to use reader or not - */ - void setUseReaderForPayload(boolean useReaderForPayload); - - /** - * If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back - * serialized in the response as a application/x-java-serialized-object content type (for example using Jetty or - * Servlet Camel components). On the producer side the exception will be deserialized and thrown as is, - * instead of the HttpOperationFailedException. The caused exception is required to be serialized. - */ - boolean isTransferException(); - - /** - * Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. - * This can be turned on in case HTTP clients do not send streamed data. - */ - boolean isEagerCheckContentAvailable(); - - /** - * Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. - * This can be turned on in case HTTP clients do not send streamed data. - */ - void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable); - - /** - * If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back - * serialized in the response as a application/x-java-serialized-object content type (for example using Jetty or - * Servlet Camel components). On the producer side the exception will be deserialized and thrown as is, - * instead of the HttpOperationFailedException. The caused exception is required to be serialized. - */ - void setTransferException(boolean transferException); - - /** - * 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); - -} http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonComponent.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonComponent.java deleted file mode 100644 index 23b4455..0000000 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonComponent.java +++ /dev/null @@ -1,75 +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.http; - -import org.apache.camel.impl.HeaderFilterStrategyComponent; - -public abstract class HttpCommonComponent extends HeaderFilterStrategyComponent { - - protected HttpBinding httpBinding; - protected HttpConfiguration httpConfiguration; - - public HttpCommonComponent(Class<? extends HttpCommonEndpoint> endpointClass) { - super(endpointClass); - } - - /** - * Connects the URL specified on the endpoint to the specified processor. - * - * @param consumer the consumer - * @throws Exception can be thrown - */ - public void connect(HttpConsumer consumer) throws Exception { - } - - /** - * Disconnects the URL specified on the endpoint from the specified processor. - * - * @param consumer the consumer - * @throws Exception can be thrown - */ - public void disconnect(HttpConsumer consumer) throws Exception { - } - - @Override - protected boolean useIntrospectionOnEndpoint() { - return false; - } - - public HttpBinding getHttpBinding() { - return httpBinding; - } - - /** - * To use a custom HttpBinding to control the mapping between Camel message and HttpClient. - */ - public void setHttpBinding(HttpBinding httpBinding) { - this.httpBinding = httpBinding; - } - - public HttpConfiguration getHttpConfiguration() { - return httpConfiguration; - } - - /** - * To use the shared HttpConfiguration as base configuration. - */ - public void setHttpConfiguration(HttpConfiguration httpConfiguration) { - this.httpConfiguration = httpConfiguration; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonEndpoint.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonEndpoint.java deleted file mode 100644 index ae2e39e..0000000 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonEndpoint.java +++ /dev/null @@ -1,383 +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.http; - -import java.net.URI; -import java.net.URISyntaxException; - -import org.apache.camel.impl.DefaultEndpoint; -import org.apache.camel.spi.HeaderFilterStrategy; -import org.apache.camel.spi.HeaderFilterStrategyAware; -import org.apache.camel.spi.Metadata; -import org.apache.camel.spi.UriParam; -import org.apache.camel.spi.UriPath; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class HttpCommonEndpoint extends DefaultEndpoint implements HeaderFilterStrategyAware { - - // Note: all options must be documented with description in annotations so extended components can access the documentation - - private static final Logger LOG = LoggerFactory.getLogger(HttpCommonEndpoint.class); - - HttpCommonComponent component; - UrlRewrite urlRewrite; - - @UriPath(label = "producer", description = "The url of the HTTP endpoint to call.") @Metadata(required = "true") - URI httpUri; - @UriParam(description = "To use a custom HeaderFilterStrategy to filter header to and from Camel message.") - HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy(); - @UriParam(description = "To use a custom HttpBinding to control the mapping between Camel message and HttpClient.") - HttpBinding binding; - @UriParam(label = "producer", defaultValue = "true", - description = "Option to disable throwing the HttpOperationFailedException in case of failed responses from the remote server." - + " This allows you to get all responses regardless of the HTTP status code.") - boolean throwExceptionOnFailure = true; - @UriParam(label = "producer", - description = "If the option is true, HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request." - + " You may also set the option throwExceptionOnFailure to be false to let the HttpProducer send all the fault response back.") - boolean bridgeEndpoint; - @UriParam(label = "consumer", - description = "Whether or not the consumer should try to find a target consumer by matching the URI prefix if no exact match is found.") - boolean matchOnUriPrefix; - @UriParam(defaultValue = "true", description = "If this option is false Jetty servlet will disable the HTTP streaming and set the content-length header on the response") - boolean chunked = true; - @UriParam(label = "consumer", - description = "Determines whether or not the raw input stream from Jetty is cached or not" - + " (Camel will read the stream into a in memory/overflow to file, Stream caching) cache." - + " By default Camel will cache the Jetty input stream to support reading it multiple times to ensure it Camel" - + " can retrieve all data from the stream. However you can set this option to true when you for example need" - + " to access the raw stream, such as streaming it directly to a file or other persistent store." - + " DefaultHttpBinding will copy the request input stream into a stream cache and put it into message body" - + " if this option is false to support reading the stream multiple times." - + " If you use Jetty to bridge/proxy an endpoint then consider enabling this option to improve performance," - + " in case you do not need to read the message payload multiple times.") - boolean disableStreamCache; - @UriParam(label = "producer", description = "The proxy host name") - String proxyHost; - @UriParam(label = "producer", description = "The proxy port number") - int proxyPort; - @UriParam(label = "producer", enums = "Basic,Digest,NTLM", description = "Authentication method for proxy, either as Basic, Digest or NTLM.") - String authMethodPriority; - @UriParam(description = "Option to disable throwing the HttpOperationFailedException in case of failed responses from the remote server." - + " This allows you to get all responses regardless of the HTTP status code.") - boolean transferException; - @UriParam(label = "consumer", - description = "Specifies whether to enable HTTP TRACE for this Jetty consumer. By default TRACE is turned off.") - boolean traceEnabled; - @UriParam(label = "consumer", - description = "Used to only allow consuming if the HttpMethod matches, such as GET/POST/PUT etc. Multiple methods can be specified separated by comma.") - String httpMethodRestrict; - @UriParam(label = "consumer", - description = "To use a custom buffer size on the javax.servlet.ServletResponse.") - Integer responseBufferSize; - @UriParam(label = "producer", - description = "If this option is true, The http producer won't read response body and cache the input stream") - boolean ignoreResponseBody; - @UriParam(label = "producer", defaultValue = "true", - description = "If this option is true then IN exchange headers will be copied to OUT exchange headers according to copy strategy." - + " Setting this to false, allows to only include the headers from the HTTP response (not propagating IN headers).") - boolean copyHeaders = true; - @UriParam(label = "consumer", - description = "Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present." - + " This can be turned on in case HTTP clients do not send streamed data.") - boolean eagerCheckContentAvailable; - - public HttpCommonEndpoint() { - } - - public HttpCommonEndpoint(String endPointURI, HttpCommonComponent component, URI httpURI) throws URISyntaxException { - super(endPointURI, component); - this.component = component; - this.httpUri = httpURI; - } - - public void connect(HttpConsumer consumer) throws Exception { - component.connect(consumer); - } - - public void disconnect(HttpConsumer consumer) throws Exception { - component.disconnect(consumer); - } - - public boolean isLenientProperties() { - // true to allow dynamic URI options to be configured and passed to external system for eg. the HttpProducer - return true; - } - - public boolean isSingleton() { - return true; - } - - - // Properties - //------------------------------------------------------------------------- - - public HttpBinding getBinding() { - if (binding == null) { - // create a new binding and use the options from this endpoint - binding = new DefaultHttpBinding(); - binding.setHeaderFilterStrategy(getHeaderFilterStrategy()); - binding.setTransferException(isTransferException()); - binding.setEagerCheckContentAvailable(isEagerCheckContentAvailable()); - } - return binding; - } - - /** - * To use a custom HttpBinding to control the mapping between Camel message and HttpClient. - */ - public void setBinding(HttpBinding binding) { - this.binding = binding; - } - - public String getPath() { - //if the path is empty, we just return the default path here - return httpUri.getPath().length() == 0 ? "/" : httpUri.getPath(); - } - - public int getPort() { - if (httpUri.getPort() == -1) { - if ("https".equals(getProtocol())) { - return 443; - } else { - return 80; - } - } - return httpUri.getPort(); - } - - public String getProtocol() { - return httpUri.getScheme(); - } - - public URI getHttpUri() { - return httpUri; - } - - /** - * The url of the HTTP endpoint to call. - */ - public void setHttpUri(URI httpUri) { - this.httpUri = httpUri; - } - - public HeaderFilterStrategy getHeaderFilterStrategy() { - return headerFilterStrategy; - } - - /** - * To use a custom HeaderFilterStrategy to filter header to and from Camel message. - */ - public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) { - this.headerFilterStrategy = headerFilterStrategy; - } - - public boolean isThrowExceptionOnFailure() { - return throwExceptionOnFailure; - } - - /** - * Option to disable throwing the HttpOperationFailedException in case of failed responses from the remote server. - * This allows you to get all responses regardless of the HTTP status code. - */ - public void setThrowExceptionOnFailure(boolean throwExceptionOnFailure) { - this.throwExceptionOnFailure = throwExceptionOnFailure; - } - - public boolean isBridgeEndpoint() { - return bridgeEndpoint; - } - - /** - * If the option is true, HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. - * You may also set the option throwExceptionOnFailure to be false to let the HttpProducer send all the fault response back. - */ - public void setBridgeEndpoint(boolean bridge) { - this.bridgeEndpoint = bridge; - } - - public boolean isMatchOnUriPrefix() { - return matchOnUriPrefix; - } - - /** - * Whether or not the consumer should try to find a target consumer by matching the URI prefix if no exact match is found. - * <p/> - * See more details at: http://camel.apache.org/how-do-i-let-jetty-match-wildcards.html - */ - public void setMatchOnUriPrefix(boolean match) { - this.matchOnUriPrefix = match; - } - - public boolean isDisableStreamCache() { - return this.disableStreamCache; - } - - /** - * Determines whether or not the raw input stream from Jetty is cached or not - * (Camel will read the stream into a in memory/overflow to file, Stream caching) cache. - * By default Camel will cache the Jetty input stream to support reading it multiple times to ensure it Camel - * can retrieve all data from the stream. However you can set this option to true when you for example need - * to access the raw stream, such as streaming it directly to a file or other persistent store. - * DefaultHttpBinding will copy the request input stream into a stream cache and put it into message body - * if this option is false to support reading the stream multiple times. - * If you use Jetty to bridge/proxy an endpoint then consider enabling this option to improve performance, - * in case you do not need to read the message payload multiple times. - */ - public void setDisableStreamCache(boolean disable) { - this.disableStreamCache = disable; - } - - public boolean isChunked() { - return this.chunked; - } - - /** - * If this option is false Jetty servlet will disable the HTTP streaming and set the content-length header on the response - */ - public void setChunked(boolean chunked) { - this.chunked = chunked; - } - - public String getProxyHost() { - return proxyHost; - } - - /** - * The proxy host name - */ - public void setProxyHost(String proxyHost) { - this.proxyHost = proxyHost; - } - - public int getProxyPort() { - return proxyPort; - } - - /** - * The proxy port number - */ - public void setProxyPort(int proxyPort) { - this.proxyPort = proxyPort; - } - - public String getAuthMethodPriority() { - return authMethodPriority; - } - - /** - * Authentication method for proxy, either as Basic, Digest or NTLM. - */ - public void setAuthMethodPriority(String authMethodPriority) { - this.authMethodPriority = authMethodPriority; - } - - public boolean isTransferException() { - return transferException; - } - - /** - * Option to disable throwing the HttpOperationFailedException in case of failed responses from the remote server. - * This allows you to get all responses regardless of the HTTP status code. - */ - public void setTransferException(boolean transferException) { - this.transferException = transferException; - } - - public boolean isTraceEnabled() { - return this.traceEnabled; - } - - /** - * Specifies whether to enable HTTP TRACE for this Jetty consumer. By default TRACE is turned off. - */ - public void setTraceEnabled(boolean traceEnabled) { - this.traceEnabled = traceEnabled; - } - - public String getHttpMethodRestrict() { - return httpMethodRestrict; - } - - /** - * Used to only allow consuming if the HttpMethod matches, such as GET/POST/PUT etc. - * Multiple methods can be specified separated by comma. - */ - public void setHttpMethodRestrict(String httpMethodRestrict) { - this.httpMethodRestrict = httpMethodRestrict; - } - - public UrlRewrite getUrlRewrite() { - return urlRewrite; - } - - /** - * Refers to a custom org.apache.camel.component.http.UrlRewrite which allows you to rewrite urls when you bridge/proxy endpoints. - * See more details at http://camel.apache.org/urlrewrite.html - */ - public void setUrlRewrite(UrlRewrite urlRewrite) { - this.urlRewrite = urlRewrite; - } - - public Integer getResponseBufferSize() { - return responseBufferSize; - } - - /** - * To use a custom buffer size on the javax.servlet.ServletResponse. - */ - public void setResponseBufferSize(Integer responseBufferSize) { - this.responseBufferSize = responseBufferSize; - } - - public boolean isIgnoreResponseBody() { - return ignoreResponseBody; - } - - /** - * If this option is true, The http producer won't read response body and cache the input stream. - */ - public void setIgnoreResponseBody(boolean ignoreResponseBody) { - this.ignoreResponseBody = ignoreResponseBody; - } - - /** - * If this option is true then IN exchange headers will be copied to OUT exchange headers according to copy strategy. - * Setting this to false, allows to only include the headers from the HTTP response (not propagating IN headers). - */ - public boolean isCopyHeaders() { - return copyHeaders; - } - - public void setCopyHeaders(boolean copyHeaders) { - this.copyHeaders = copyHeaders; - } - - public boolean isEagerCheckContentAvailable() { - return eagerCheckContentAvailable; - } - - /** - * Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. - * This can be turned on in case HTTP clients do not send streamed data. - */ - public void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable) { - this.eagerCheckContentAvailable = eagerCheckContentAvailable; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java index e817d55..3599c64 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java @@ -25,6 +25,10 @@ import java.util.Set; import org.apache.camel.Endpoint; import org.apache.camel.ResolveEndpointFailedException; +import org.apache.camel.http.common.HttpBinding; +import org.apache.camel.http.common.HttpCommonComponent; +import org.apache.camel.http.common.HttpConfiguration; +import org.apache.camel.http.common.UrlRewrite; import org.apache.camel.spi.HeaderFilterStrategy; import org.apache.camel.util.CollectionHelper; import org.apache.camel.util.IntrospectionSupport; @@ -74,7 +78,7 @@ public class HttpComponent extends HttpCommonComponent { // authentication can be endpoint configured String authUsername = getAndRemoveParameter(parameters, "authUsername", String.class); - AuthMethod authMethod = getAndRemoveParameter(parameters, "authMethod", AuthMethod.class); + String authMethod = getAndRemoveParameter(parameters, "authMethod", String.class); // validate that if auth username is given then the auth method is also provided if (authUsername != null && authMethod == null) { throw new IllegalArgumentException("Option authMethod must be provided to use authentication"); @@ -92,7 +96,7 @@ public class HttpComponent extends HttpCommonComponent { // proxy authentication can be endpoint configured String proxyAuthUsername = getAndRemoveParameter(parameters, "proxyAuthUsername", String.class); - AuthMethod proxyAuthMethod = getAndRemoveParameter(parameters, "proxyAuthMethod", AuthMethod.class); + String proxyAuthMethod = getAndRemoveParameter(parameters, "proxyAuthMethod", String.class); // validate that if proxy auth username is given then the proxy auth method is also provided if (proxyAuthUsername != null && proxyAuthMethod == null) { throw new IllegalArgumentException("Option proxyAuthMethod must be provided to use proxy authentication"); @@ -116,7 +120,7 @@ public class HttpComponent extends HttpCommonComponent { * * @return configurer to used */ - protected HttpClientConfigurer configureAuth(HttpClientConfigurer configurer, AuthMethod authMethod, String username, + protected HttpClientConfigurer configureAuth(HttpClientConfigurer configurer, String authMethod, String username, String password, String domain, String host, Set<AuthMethod> authMethods) { // no auth is in use @@ -132,13 +136,15 @@ public class HttpComponent extends HttpCommonComponent { ObjectHelper.notNull(username, "authUsername"); ObjectHelper.notNull(password, "authPassword"); + AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod); + // add it as a auth method used - authMethods.add(authMethod); + authMethods.add(auth); - if (authMethod == AuthMethod.Basic || authMethod == AuthMethod.Digest) { + if (auth == AuthMethod.Basic || auth == AuthMethod.Digest) { return CompositeHttpConfigurer.combineConfigurers(configurer, new BasicAuthenticationHttpClientConfigurer(false, username, password)); - } else if (authMethod == AuthMethod.NTLM) { + } else if (auth == AuthMethod.NTLM) { // domain is mandatory for NTLM ObjectHelper.notNull(domain, "authDomain"); return CompositeHttpConfigurer.combineConfigurers(configurer, @@ -153,7 +159,7 @@ public class HttpComponent extends HttpCommonComponent { * * @return configurer to used */ - protected HttpClientConfigurer configureProxyAuth(HttpClientConfigurer configurer, AuthMethod authMethod, String username, + protected HttpClientConfigurer configureProxyAuth(HttpClientConfigurer configurer, String authMethod, String username, String password, String domain, String host, Set<AuthMethod> authMethods) { // no proxy auth is in use if (username == null && authMethod == null) { @@ -168,13 +174,15 @@ public class HttpComponent extends HttpCommonComponent { ObjectHelper.notNull(username, "proxyAuthUsername"); ObjectHelper.notNull(password, "proxyAuthPassword"); + AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod); + // add it as a auth method used - authMethods.add(authMethod); + authMethods.add(auth); - if (authMethod == AuthMethod.Basic || authMethod == AuthMethod.Digest) { + if (auth == AuthMethod.Basic || auth == AuthMethod.Digest) { return CompositeHttpConfigurer.combineConfigurers(configurer, new BasicAuthenticationHttpClientConfigurer(true, username, password)); - } else if (authMethod == AuthMethod.NTLM) { + } else if (auth == AuthMethod.NTLM) { // domain is mandatory for NTML ObjectHelper.notNull(domain, "proxyAuthDomain"); return CompositeHttpConfigurer.combineConfigurers(configurer, @@ -312,4 +320,21 @@ public class HttpComponent extends HttpCommonComponent { this.httpConnectionManager = httpConnectionManager; } + /** + * To use a custom HttpBinding to control the mapping between Camel message and HttpClient. + */ + @Override + public void setHttpBinding(HttpBinding httpBinding) { + // need to override and call super for component docs + super.setHttpBinding(httpBinding); + } + + /** + * To use the shared HttpConfiguration as base configuration. + */ + @Override + public void setHttpConfiguration(HttpConfiguration httpConfiguration) { + // need to override and call super for component docs + super.setHttpConfiguration(httpConfiguration); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConfiguration.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConfiguration.java deleted file mode 100644 index 20725ad..0000000 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConfiguration.java +++ /dev/null @@ -1,146 +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.http; - -import java.io.Serializable; - -/** - * @version - */ -public class HttpConfiguration implements Serializable { - private static final long serialVersionUID = 1L; - - private AuthMethod authMethod; - private String authUsername; - private String authPassword; - private String authDomain; - private String authHost; - - private AuthMethod proxyAuthMethod; - private String proxyAuthUsername; - private String proxyAuthPassword; - private String proxyAuthDomain; - private String proxyAuthHost; - - private String proxyHost; - private int proxyPort; - private String authMethodPriority; - - public String getAuthUsername() { - return authUsername; - } - - public void setAuthUsername(String authUsername) { - this.authUsername = authUsername; - } - - public String getAuthPassword() { - return authPassword; - } - - public void setAuthPassword(String authPassword) { - this.authPassword = authPassword; - } - - public String getAuthDomain() { - return authDomain; - } - - public void setAuthDomain(String authDomain) { - this.authDomain = authDomain; - } - - public String getAuthHost() { - return authHost; - } - - public void setAuthHost(String authHost) { - this.authHost = authHost; - } - - public String getProxyAuthUsername() { - return proxyAuthUsername; - } - - public void setProxyAuthUsername(String proxyAuthUsername) { - this.proxyAuthUsername = proxyAuthUsername; - } - - public String getProxyAuthPassword() { - return proxyAuthPassword; - } - - public void setProxyAuthPassword(String proxyAuthPassword) { - this.proxyAuthPassword = proxyAuthPassword; - } - - public String getProxyAuthDomain() { - return proxyAuthDomain; - } - - public void setProxyAuthDomain(String proxyAuthDomain) { - this.proxyAuthDomain = proxyAuthDomain; - } - - public String getProxyAuthHost() { - return proxyAuthHost; - } - - public void setProxyAuthHost(String proxyAuthHost) { - this.proxyAuthHost = proxyAuthHost; - } - - public AuthMethod getAuthMethod() { - return authMethod; - } - - public void setAuthMethod(AuthMethod authMethod) { - this.authMethod = authMethod; - } - - public AuthMethod getProxyAuthMethod() { - return proxyAuthMethod; - } - - public void setProxyAuthMethod(AuthMethod proxyAuthMethod) { - this.proxyAuthMethod = proxyAuthMethod; - } - - public String getProxyHost() { - return proxyHost; - } - - public void setProxyHost(String proxyHost) { - this.proxyHost = proxyHost; - } - - public int getProxyPort() { - return proxyPort; - } - - public void setProxyPort(int proxyPort) { - this.proxyPort = proxyPort; - } - - public String getAuthMethodPriority() { - return authMethodPriority; - } - - public void setAuthMethodPriority(String authMethodPriority) { - this.authMethodPriority = authMethodPriority; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java deleted file mode 100644 index d2fab26..0000000 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConstants.java +++ /dev/null @@ -1,29 +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.http; - -/** - * @version - */ -public final class HttpConstants { - - public static final String CONTENT_TYPE_JAVA_SERIALIZED_OBJECT = "application/x-java-serialized-object"; - public static final String CONTENT_TYPE_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded"; - - private HttpConstants() { - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java deleted file mode 100644 index 6d1d7d1..0000000 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java +++ /dev/null @@ -1,83 +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.http; - -import org.apache.camel.Processor; -import org.apache.camel.SuspendableService; -import org.apache.camel.impl.DefaultConsumer; - -/** - * @version - */ -public class HttpConsumer extends DefaultConsumer implements SuspendableService { - private volatile boolean suspended; - private boolean traceEnabled; - - public HttpConsumer(HttpEndpoint endpoint, Processor processor) { - super(endpoint, processor); - if (endpoint.isTraceEnabled()) { - setTraceEnabled(true); - } - } - - @Override - public HttpEndpoint getEndpoint() { - return (HttpEndpoint)super.getEndpoint(); - } - - public HttpBinding getBinding() { - return getEndpoint().getBinding(); - } - - public String getPath() { - return getEndpoint().getPath(); - } - - @Override - protected void doStart() throws Exception { - super.doStart(); - getEndpoint().connect(this); - suspended = false; - } - - @Override - protected void doStop() throws Exception { - suspended = false; - getEndpoint().disconnect(this); - super.doStop(); - } - - public void suspend() { - suspended = true; - } - - public void resume() { - suspended = false; - } - - public boolean isSuspended() { - return suspended; - } - - public boolean isTraceEnabled() { - return this.traceEnabled; - } - - public void setTraceEnabled(boolean traceEnabled) { - this.traceEnabled = traceEnabled; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java deleted file mode 100644 index 2b7138d..0000000 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java +++ /dev/null @@ -1,100 +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.http; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.camel.Converter; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.util.GZIPHelper; - -/** - * Some converter methods making it easy to convert the body of a message to servlet types or to switch between - * the underlying {@link ServletInputStream} or {@link BufferedReader} payloads etc. - * - * @version - */ -@Converter -public final class HttpConverter { - - private HttpConverter() { - } - - @Converter - public static HttpServletRequest toServletRequest(Message message) { - if (message == null) { - return null; - } - return message.getHeader(Exchange.HTTP_SERVLET_REQUEST, HttpServletRequest.class); - } - - @Converter - public static HttpServletResponse toServletResponse(Message message) { - if (message == null) { - return null; - } - return message.getHeader(Exchange.HTTP_SERVLET_RESPONSE, HttpServletResponse.class); - } - - @Converter - public static ServletInputStream toServletInputStream(HttpMessage message) throws IOException { - HttpServletRequest request = toServletRequest(message); - if (request != null) { - return request.getInputStream(); - } - return null; - } - - @Converter - public static InputStream toInputStream(HttpMessage message, Exchange exchange) throws Exception { - return toInputStream(toServletRequest(message), exchange); - } - - @Converter - public static BufferedReader toReader(HttpMessage message) throws IOException { - HttpServletRequest request = toServletRequest(message); - if (request != null) { - return request.getReader(); - } - return null; - } - - @Converter - public static InputStream toInputStream(HttpServletRequest request, Exchange exchange) throws IOException { - if (request == null) { - return null; - } - InputStream is = request.getInputStream(); - if (is != null && is.available() <= 0) { - // there is no data, so we cannot uncompress etc. - return is; - } - if (exchange == null || !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) { - String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING); - return GZIPHelper.uncompressGzip(contentEncoding, is); - } else { - return is; - } - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/f685f361/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java index 23b1a20..98df503 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java @@ -26,6 +26,7 @@ import org.apache.camel.Consumer; import org.apache.camel.PollingConsumer; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.http.common.HttpCommonEndpoint; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.util.ObjectHelper; import org.apache.commons.httpclient.HttpClient; @@ -70,7 +71,6 @@ public class HttpEndpoint extends HttpCommonEndpoint { public HttpEndpoint(String endPointURI, HttpComponent component, URI httpURI, HttpClientParams clientParams, HttpConnectionManager httpConnectionManager, HttpClientConfigurer clientConfigurer) throws URISyntaxException { super(endPointURI, component, httpURI); - this.component = component; this.clientParams = clientParams; this.httpClientConfigurer = clientConfigurer; this.httpConnectionManager = httpConnectionManager; @@ -108,20 +108,20 @@ public class HttpEndpoint extends HttpCommonEndpoint { answer.getHostConfiguration().setProxy(host, port); } - if (proxyHost != null) { - LOG.debug("Using proxy: {}:{}", proxyHost, proxyPort); - answer.getHostConfiguration().setProxy(proxyHost, proxyPort); + if (getProxyHost() != null) { + LOG.debug("Using proxy: {}:{}", getProxyHost(), getProxyPort()); + answer.getHostConfiguration().setProxy(getProxyHost(), getProxyPort()); } - if (authMethodPriority != null) { + if (getAuthMethodPriority() != null) { List<String> authPrefs = new ArrayList<String>(); - Iterator<?> it = getCamelContext().getTypeConverter().convertTo(Iterator.class, authMethodPriority); + Iterator<?> it = getCamelContext().getTypeConverter().convertTo(Iterator.class, getAuthMethodPriority()); int i = 1; while (it.hasNext()) { Object value = it.next(); AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, value); if (auth == null) { - throw new IllegalArgumentException("Unknown authMethod: " + value + " in authMethodPriority: " + authMethodPriority); + throw new IllegalArgumentException("Unknown authMethod: " + value + " in authMethodPriority: " + getAuthMethodPriority()); } LOG.debug("Using authSchemePriority #{}: {}", i, auth); authPrefs.add(auth.name());