Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 7aa181a4d -> b69ab33a7


http://git-wip-us.apache.org/repos/asf/camel/blob/8dfd66bd/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/CamelSalesforceMojo.java
----------------------------------------------------------------------
diff --git 
a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/CamelSalesforceMojo.java
 
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/CamelSalesforceMojo.java
index 9fdadb8..995a810 100644
--- 
a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/CamelSalesforceMojo.java
+++ 
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/CamelSalesforceMojo.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.lang.reflect.Field;
+import java.net.URI;
 import java.security.GeneralSecurityException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -37,6 +38,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
 
 import org.apache.camel.component.salesforce.SalesforceEndpointConfig;
+import org.apache.camel.component.salesforce.SalesforceHttpClient;
 import org.apache.camel.component.salesforce.SalesforceLoginConfig;
 import org.apache.camel.component.salesforce.api.SalesforceException;
 import org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase;
@@ -66,10 +68,13 @@ import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.log.Log4JLogChute;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 import org.codehaus.jackson.map.ObjectMapper;
-import org.eclipse.jetty.client.Address;
-import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.client.RedirectListener;
-import org.eclipse.jetty.client.security.ProxyAuthorization;
+import org.eclipse.jetty.client.HttpProxy;
+import org.eclipse.jetty.client.Origin;
+import org.eclipse.jetty.client.ProxyConfiguration;
+import org.eclipse.jetty.client.Socks4Proxy;
+import org.eclipse.jetty.client.api.Authentication;
+import org.eclipse.jetty.client.util.BasicAuthentication;
+import org.eclipse.jetty.client.util.DigestAuthentication;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
 
 /**
@@ -116,6 +121,30 @@ public class CamelSalesforceMojo extends AbstractMojo {
     protected Integer httpProxyPort;
 
     /**
+     * Is it a SOCKS4 Proxy?
+     */
+    @Parameter(property = "camelSalesforce.isHttpProxySocks4")
+    private boolean isHttpProxySocks4;
+
+    /**
+     * Is HTTP Proxy secure, i.e. using secure sockets, true by default.
+     */
+    @Parameter(property = "camelSalesforce.isHttpProxySecure")
+    private boolean isHttpProxySecure = true;
+
+    /**
+     * Addresses to Proxy.
+     */
+    @Parameter(property = "camelSalesforce.httpProxyIncludedAddresses")
+    private Set<String> httpProxyIncludedAddresses;
+
+    /**
+     * Addresses to NOT Proxy.
+     */
+    @Parameter(property = "camelSalesforce.httpProxyIncludedAddresses")
+    private Set<String> httpProxyExcludedAddresses;
+
+    /**
      * Proxy authentication username.
      */
     @Parameter(property = "camelSalesforce.httpProxyUsername")
@@ -128,6 +157,24 @@ public class CamelSalesforceMojo extends AbstractMojo {
     protected String httpProxyPassword;
 
     /**
+     * Proxy authentication URI.
+     */
+    @Parameter(property = "camelSalesforce.httpProxyAuthUri")
+    protected String httpProxyAuthUri;
+
+    /**
+     * Proxy authentication realm.
+     */
+    @Parameter(property = "camelSalesforce.httpProxyRealm")
+    protected String httpProxyRealm;
+
+    /**
+     * Proxy uses Digest authentication.
+     */
+    @Parameter(property = "camelSalesforce.httpProxyUseDigestAuth")
+    protected boolean httpProxyUseDigestAuth;
+
+    /**
      * Salesforce client id.
      */
     @Parameter(property = "camelSalesforce.clientId", required = true)
@@ -224,10 +271,8 @@ public class CamelSalesforceMojo extends AbstractMojo {
         }
 
         // connect to Salesforce
-        final HttpClient httpClient = createHttpClient();
-
-        final SalesforceSession session = new SalesforceSession(httpClient,
-                new SalesforceLoginConfig(loginUrl, clientId, clientSecret, 
userName, password, false));
+        final SalesforceHttpClient httpClient = createHttpClient();
+        final SalesforceSession session = httpClient.getSession();
 
         getLog().info("Salesforce login...");
         try {
@@ -417,28 +462,33 @@ public class CamelSalesforceMojo extends AbstractMojo {
         getLog().info(String.format("Found %s matching Objects", 
objectNames.size()));
     }
 
-    protected HttpClient createHttpClient() throws MojoExecutionException {
+    protected SalesforceHttpClient createHttpClient() throws 
MojoExecutionException {
 
-        final HttpClient httpClient = new HttpClient();
-
-        // default settings
-        httpClient.registerListener(RedirectListener.class.getName());
-        httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
-        httpClient.setConnectTimeout(DEFAULT_TIMEOUT);
-        httpClient.setTimeout(DEFAULT_TIMEOUT);
+        final SalesforceHttpClient httpClient;
 
         // set ssl context parameters
         try {
+
             final SSLContextParameters contextParameters = 
sslContextParameters != null
                 ? sslContextParameters : new SSLContextParameters();
-            final SslContextFactory sslContextFactory = 
httpClient.getSslContextFactory();
+            final SslContextFactory sslContextFactory = new 
SslContextFactory();
             
sslContextFactory.setSslContext(contextParameters.createSSLContext());
+
+            httpClient = new SalesforceHttpClient(sslContextFactory);
+
         } catch (GeneralSecurityException e) {
             throw new MojoExecutionException("Error creating default SSL 
context: " + e.getMessage(), e);
         } catch (IOException e) {
             throw new MojoExecutionException("Error creating default SSL 
context: " + e.getMessage(), e);
         }
 
+        // default settings
+        httpClient.setConnectTimeout(DEFAULT_TIMEOUT);
+        httpClient.setTimeout(DEFAULT_TIMEOUT);
+
+        // enable redirects, no need for a RedirectListener class in Jetty 9
+        httpClient.setFollowRedirects(true);
+
         // set HTTP client parameters
         if (httpClientProperties != null && !httpClientProperties.isEmpty()) {
             try {
@@ -452,24 +502,44 @@ public class CamelSalesforceMojo extends AbstractMojo {
         responseTimeout = httpClient.getTimeout() + 1000L;
 
         // set http proxy settings
+        // set HTTP proxy settings
         if (this.httpProxyHost != null && httpProxyPort != null) {
-            httpClient.setProxy(new Address(this.httpProxyHost, 
this.httpProxyPort));
+            Origin.Address proxyAddress = new 
Origin.Address(this.httpProxyHost, this.httpProxyPort);
+            ProxyConfiguration.Proxy proxy;
+            if (isHttpProxySocks4) {
+                proxy = new Socks4Proxy(proxyAddress, isHttpProxySecure);
+            } else {
+                proxy = new HttpProxy(proxyAddress, isHttpProxySecure);
+            }
+            if (httpProxyIncludedAddresses != null && 
!httpProxyIncludedAddresses.isEmpty()) {
+                
proxy.getIncludedAddresses().addAll(httpProxyIncludedAddresses);
+            }
+            if (httpProxyExcludedAddresses != null && 
!httpProxyExcludedAddresses.isEmpty()) {
+                
proxy.getExcludedAddresses().addAll(httpProxyExcludedAddresses);
+            }
+            httpClient.getProxyConfiguration().getProxies().add(proxy);
         }
         if (this.httpProxyUsername != null && httpProxyPassword != null) {
-            try {
-                httpClient.setProxyAuthentication(new 
ProxyAuthorization(this.httpProxyUsername, this.httpProxyPassword));
-            } catch (IOException e) {
-                throw new MojoExecutionException("Error configuring proxy 
authorization: " + e.getMessage(), e);
+
+            ObjectHelper.notEmpty(httpProxyAuthUri, "httpProxyAuthUri");
+            ObjectHelper.notEmpty(httpProxyRealm, "httpProxyRealm");
+
+            final Authentication authentication;
+            if (httpProxyUseDigestAuth) {
+                authentication = new 
DigestAuthentication(URI.create(httpProxyAuthUri),
+                    httpProxyRealm, httpProxyUsername, httpProxyPassword);
+            } else {
+                authentication = new 
BasicAuthentication(URI.create(httpProxyAuthUri),
+                    httpProxyRealm, httpProxyUsername, httpProxyPassword);
             }
+            
httpClient.getAuthenticationStore().addAuthentication(authentication);
         }
 
-        // add redirect listener to handle Salesforce redirects
-        // this is ok to do since the RedirectListener is in the same 
classloader as Jetty client
-        String listenerClass = RedirectListener.class.getName();
-        if (httpClient.getRegisteredListeners() == null
-            || !httpClient.getRegisteredListeners().contains(listenerClass)) {
-            httpClient.registerListener(listenerClass);
-        }
+        // set session before calling start()
+        final SalesforceSession session = new SalesforceSession(httpClient,
+            httpClient.getTimeout(),
+            new SalesforceLoginConfig(loginUrl, clientId, clientSecret, 
userName, password, false));
+        httpClient.setSession(session);
 
         try {
             httpClient.start();

http://git-wip-us.apache.org/repos/asf/camel/blob/8dfd66bd/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/java/org/apache/camel/maven/HttpProxyMojoIntegrationTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/java/org/apache/camel/maven/HttpProxyMojoIntegrationTest.java
 
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/java/org/apache/camel/maven/HttpProxyMojoIntegrationTest.java
index 47d15fb..ba6a451 100644
--- 
a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/java/org/apache/camel/maven/HttpProxyMojoIntegrationTest.java
+++ 
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/java/org/apache/camel/maven/HttpProxyMojoIntegrationTest.java
@@ -18,23 +18,25 @@ package org.apache.camel.maven;
 
 import java.io.IOException;
 import java.util.HashMap;
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.camel.util.jsse.SSLContextParameters;
-import org.eclipse.jetty.http.HttpHeaders;
-import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.proxy.ConnectHandler;
 import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.ConnectHandler;
-import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.util.B64Code;
 import org.eclipse.jetty.util.StringUtil;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.eclipse.jetty.http.HttpHeader.PROXY_AUTHENTICATE;
+import static org.eclipse.jetty.http.HttpHeader.PROXY_AUTHORIZATION;
+
+@Ignore("Bug in Jetty9 causes java.lang.IllegalArgumentException: Invalid 
protocol login.salesforce.com")
 public class HttpProxyMojoIntegrationTest extends 
CamelSalesforceMojoIntegrationTest {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(HttpProxyMojoIntegrationTest.class);
@@ -42,6 +44,7 @@ public class HttpProxyMojoIntegrationTest extends 
CamelSalesforceMojoIntegration
     private static final String HTTP_PROXY_HOST = "localhost";
     private static final String HTTP_PROXY_USER_NAME = "camel-user";
     private static final String HTTP_PROXY_PASSWORD = "camel-user-password";
+    private static final String HTTP_PROXY_REALM = "proxy-realm";
 
     private static Server server;
     private static int httpProxyPort;
@@ -51,26 +54,36 @@ public class HttpProxyMojoIntegrationTest extends 
CamelSalesforceMojoIntegration
         // start a local HTTP proxy using Jetty server
         server = new Server();
 
-        Connector connector = new SelectChannelConnector();
+/*
+        final SSLContextParameters contextParameters = new 
SSLContextParameters();
+        final SslContextFactory sslContextFactory = new SslContextFactory();
+        sslContextFactory.setSslContext(contextParameters.createSSLContext());
+        ServerConnector connector = new ServerConnector(server, 
sslContextFactory);
+*/
+        ServerConnector connector = new ServerConnector(server);
+
         connector.setHost(HTTP_PROXY_HOST);
-        server.setConnectors(new Connector[]{connector});
+        server.addConnector(connector);
 
         final String authenticationString = "Basic "
             + B64Code.encode(HTTP_PROXY_USER_NAME + ":" + HTTP_PROXY_PASSWORD, 
StringUtil.__ISO_8859_1);
 
-        ConnectHandler handler = new ConnectHandler() {
+        ConnectHandler connectHandler = new ConnectHandler() {
             @Override
-            protected boolean handleAuthentication(HttpServletRequest request, 
HttpServletResponse response, String address) throws ServletException, 
IOException {
+            protected boolean handleAuthentication(HttpServletRequest request, 
HttpServletResponse response, String address) {
                 // validate proxy-authentication header
-                final String header = 
request.getHeader(HttpHeaders.PROXY_AUTHORIZATION);
+                final String header = 
request.getHeader(PROXY_AUTHORIZATION.toString());
                 if (!authenticationString.equals(header)) {
-                    throw new ServletException("Missing header " + 
HttpHeaders.PROXY_AUTHORIZATION);
+                    LOG.warn("Missing header " + PROXY_AUTHORIZATION);
+                    // ask for authentication header
+                    response.setHeader(PROXY_AUTHENTICATE.toString(), 
String.format("Basic realm=\"%s\"", HTTP_PROXY_REALM));
+                    return false;
                 }
-                LOG.info("CONNECT exchange contains required header " + 
HttpHeaders.PROXY_AUTHORIZATION);
-                return super.handleAuthentication(request, response, address);
+                LOG.info("Request contains required header " + 
PROXY_AUTHORIZATION);
+                return true;
             }
         };
-        server.setHandler(handler);
+        server.setHandler(connectHandler);
 
         LOG.info("Starting proxy server...");
         server.start();
@@ -91,6 +104,8 @@ public class HttpProxyMojoIntegrationTest extends 
CamelSalesforceMojoIntegration
         mojo.httpProxyPort = httpProxyPort;
         mojo.httpProxyUsername = HTTP_PROXY_USER_NAME;
         mojo.httpProxyPassword = HTTP_PROXY_PASSWORD;
+        mojo.httpProxyRealm = HTTP_PROXY_REALM;
+        mojo.httpProxyAuthUri = String.format("https://%s:%s";, 
HTTP_PROXY_HOST, httpProxyPort);
 
         // HTTP client properties
         mojo.httpClientProperties = new HashMap<String, Object>();

http://git-wip-us.apache.org/repos/asf/camel/blob/8dfd66bd/components/camel-salesforce/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/pom.xml 
b/components/camel-salesforce/pom.xml
index 2f6b11c..2ec8ca6 100644
--- a/components/camel-salesforce/pom.xml
+++ b/components/camel-salesforce/pom.xml
@@ -85,6 +85,7 @@
                 <includes>
                   <include>**/*Test.java</include>
                 </includes>
+                <trimStackTrace>false</trimStackTrace>
               </configuration>
             </plugin>
           </plugins>

http://git-wip-us.apache.org/repos/asf/camel/blob/8dfd66bd/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 08a47f4..d5bd624 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -97,7 +97,7 @@
     <classmate-version>1.3.1</classmate-version>
     <cmis-version>0.13.0</cmis-version>
     <cometd-bayeux-version>6.1.11</cometd-bayeux-version>
-    <cometd-java-client-version>2.4.3</cometd-java-client-version>
+    <cometd-java-client-version>3.0.9</cometd-java-client-version>
     
<cometd-java-server-bundle-version>2.3.1_2</cometd-java-server-bundle-version>
     <cometd-java-server>2.3.1</cometd-java-server>
     
<commons-beanutils-bundle-version>1.8.3_1</commons-beanutils-bundle-version>

Reply via email to