Return-Path: X-Original-To: apmail-chemistry-commits-archive@www.apache.org Delivered-To: apmail-chemistry-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7E9401783D for ; Mon, 6 Apr 2015 17:10:58 +0000 (UTC) Received: (qmail 21421 invoked by uid 500); 6 Apr 2015 17:10:58 -0000 Delivered-To: apmail-chemistry-commits-archive@chemistry.apache.org Received: (qmail 21314 invoked by uid 500); 6 Apr 2015 17:10:58 -0000 Mailing-List: contact commits-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list commits@chemistry.apache.org Received: (qmail 19670 invoked by uid 99); 6 Apr 2015 17:10:57 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Apr 2015 17:10:57 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 2991BAC0E2F for ; Mon, 6 Apr 2015 17:10:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1671596 [36/46] - in /chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings: ./ css/ images/ images/logos/ xref-test/ xref-test/org/ xref-test/org/apache/ xref-test/org/apache/chemistry... Date: Mon, 06 Apr 2015 17:10:52 -0000 To: commits@chemistry.apache.org From: gabriele@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150406171057.2991BAC0E2F@hades.apache.org> Added: chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/cookies/package-frame.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/cookies/package-frame.html?rev=1671596&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/cookies/package-frame.html (added) +++ chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/cookies/package-frame.html Mon Apr 6 17:10:50 2015 @@ -0,0 +1,33 @@ + + + + + + OpenCMIS Client Bindings Implementation 0.13.0 Reference Package org.apache.chemistry.opencmis.client.bindings.spi.cookies + + + + +

+ org.apache.chemistry.opencmis.client.bindings.spi.cookies +

+ +

Classes

+ + + + + \ No newline at end of file Added: chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/cookies/package-summary.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/cookies/package-summary.html?rev=1671596&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/cookies/package-summary.html (added) +++ chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/cookies/package-summary.html Mon Apr 6 17:10:50 2015 @@ -0,0 +1,82 @@ + + + + + + OpenCMIS Client Bindings Implementation 0.13.0 Reference Package org.apache.chemistry.opencmis.client.bindings.spi.cookies + + + +
+ +
+
+ +
+ +

Package org.apache.chemistry.opencmis.client.bindings.spi.cookies

+ + + + + + + + + + + + + + + + + + + + + +
Class Summary
+ CmisCookieManager +
+ CmisCookieStoreImpl +
+ CmisHttpCookie +
+ Setter +
+ +
+ +
+
+ +
+
+ Copyright © 2009-2015 The Apache Software Foundation. All Rights Reserved. + + \ No newline at end of file Added: chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.html?rev=1671596&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.html (added) +++ chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.html Mon Apr 6 17:10:50 2015 @@ -0,0 +1,387 @@ + + + + +AbstractApacheClientHttpInvoker xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.client.bindings.spi.http;
+20  
+21  import static org.apache.chemistry.opencmis.commons.impl.CollectionsHelper.isNotEmpty;
+22  
+23  import java.io.BufferedOutputStream;
+24  import java.io.ByteArrayInputStream;
+25  import java.io.IOException;
+26  import java.io.InputStream;
+27  import java.io.OutputStream;
+28  import java.math.BigInteger;
+29  import java.net.Socket;
+30  import java.util.ArrayList;
+31  import java.util.HashMap;
+32  import java.util.List;
+33  import java.util.Map;
+34  import java.util.zip.GZIPOutputStream;
+35  
+36  import javax.net.ssl.HostnameVerifier;
+37  import javax.net.ssl.SSLException;
+38  import javax.net.ssl.SSLSocket;
+39  
+40  import org.apache.chemistry.opencmis.client.bindings.impl.ClientVersion;
+41  import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper;
+42  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
+43  import org.apache.chemistry.opencmis.commons.SessionParameter;
+44  import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
+45  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+46  import org.apache.chemistry.opencmis.commons.impl.IOUtils;
+47  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
+48  import org.apache.chemistry.opencmis.commons.spi.AuthenticationProvider;
+49  import org.apache.http.Header;
+50  import org.apache.http.HttpEntity;
+51  import org.apache.http.HttpResponse;
+52  import org.apache.http.HttpVersion;
+53  import org.apache.http.client.HttpClient;
+54  import org.apache.http.client.methods.HttpDelete;
+55  import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+56  import org.apache.http.client.methods.HttpGet;
+57  import org.apache.http.client.methods.HttpPost;
+58  import org.apache.http.client.methods.HttpPut;
+59  import org.apache.http.client.methods.HttpRequestBase;
+60  import org.apache.http.conn.ssl.X509HostnameVerifier;
+61  import org.apache.http.entity.AbstractHttpEntity;
+62  import org.apache.http.impl.client.DefaultHttpClient;
+63  import org.apache.http.params.BasicHttpParams;
+64  import org.apache.http.params.HttpConnectionParams;
+65  import org.apache.http.params.HttpParams;
+66  import org.apache.http.params.HttpProtocolParams;
+67  import org.slf4j.Logger;
+68  import org.slf4j.LoggerFactory;
+69  
+70  /**
+71   * A {@link HttpInvoker} that uses The Apache HTTP client.
+72   */
+73  public abstract class AbstractApacheClientHttpInvoker implements HttpInvoker {
+74  
+75      protected static final Logger LOG = LoggerFactory.getLogger(AbstractApacheClientHttpInvoker.class);
+76  
+77      protected static final String HTTP_CLIENT = "org.apache.chemistry.opencmis.client.bindings.spi.http.ApacheClientHttpInvoker.httpClient";
+78      protected static final int BUFFER_SIZE = 2 * 1024 * 1024;
+79  
+80      public Response invokeGET(UrlBuilder url, BindingSession session) {
+81          return invoke(url, "GET", null, null, null, session, null, null);
+82      }
+83  
+84      public Response invokeGET(UrlBuilder url, BindingSession session, BigInteger offset, BigInteger length) {
+85          return invoke(url, "GET", null, null, null, session, offset, length);
+86      }
+87  
+88      public Response invokePOST(UrlBuilder url, String contentType, Output writer, BindingSession session) {
+89          return invoke(url, "POST", contentType, null, writer, session, null, null);
+90      }
+91  
+92      public Response invokePUT(UrlBuilder url, String contentType, Map<String, String> headers, Output writer,
+93              BindingSession session) {
+94          return invoke(url, "PUT", contentType, headers, writer, session, null, null);
+95      }
+96  
+97      public Response invokeDELETE(UrlBuilder url, BindingSession session) {
+98          return invoke(url, "DELETE", null, null, null, session, null, null);
+99      }
+100 
+101     protected Response invoke(UrlBuilder url, String method, String contentType, Map<String, String> headers,
+102             final Output writer, final BindingSession session, BigInteger offset, BigInteger length) {
+103         int respCode = -1;
+104 
+105         try {
+106             // log before connect
+107             if (LOG.isDebugEnabled()) {
+108                 LOG.debug("Session {}: {} {}", session.getSessionId(), method, url);
+109             }
+110 
+111             // get HTTP client object from session
+112             DefaultHttpClient httpclient = (DefaultHttpClient) session.get(HTTP_CLIENT);
+113             if (httpclient == null) {
+114                 session.writeLock();
+115                 try {
+116                     httpclient = (DefaultHttpClient) session.get(HTTP_CLIENT);
+117                     if (httpclient == null) {
+118                         httpclient = createHttpClient(url, session);
+119                         session.put(HTTP_CLIENT, httpclient, true);
+120                     }
+121                 } finally {
+122                     session.writeUnlock();
+123                 }
+124             }
+125 
+126             HttpRequestBase request = null;
+127 
+128             if ("GET".equals(method)) {
+129                 request = new HttpGet(url.toString());
+130             } else if ("POST".equals(method)) {
+131                 request = new HttpPost(url.toString());
+132             } else if ("PUT".equals(method)) {
+133                 request = new HttpPut(url.toString());
+134             } else if ("DELETE".equals(method)) {
+135                 request = new HttpDelete(url.toString());
+136             } else {
+137                 throw new CmisRuntimeException("Invalid HTTP method!");
+138             }
+139 
+140             // set content type
+141             if (contentType != null) {
+142                 request.setHeader("Content-Type", contentType);
+143             }
+144             // set other headers
+145             if (headers != null) {
+146                 for (Map.Entry<String, String> header : headers.entrySet()) {
+147                     request.addHeader(header.getKey(), header.getValue());
+148                 }
+149             }
+150 
+151             // authenticate
+152             AuthenticationProvider authProvider = CmisBindingsHelper.getAuthenticationProvider(session);
+153             if (authProvider != null) {
+154                 Map<String, List<String>> httpHeaders = authProvider.getHTTPHeaders(url.toString());
+155                 if (httpHeaders != null) {
+156                     for (Map.Entry<String, List<String>> header : httpHeaders.entrySet()) {
+157                         if (header.getKey() != null && isNotEmpty(header.getValue())) {
+158                             String key = header.getKey();
+159                             if (key.equalsIgnoreCase("user-agent")) {
+160                                 request.setHeader("User-Agent", header.getValue().get(0));
+161                             } else {
+162                                 for (String value : header.getValue()) {
+163                                     if (value != null) {
+164                                         request.addHeader(key, value);
+165                                     }
+166                                 }
+167                             }
+168                         }
+169                     }
+170                 }
+171             }
+172 
+173             // range
+174             if ((offset != null) || (length != null)) {
+175                 StringBuilder sb = new StringBuilder("bytes=");
+176 
+177                 if ((offset == null) || (offset.signum() == -1)) {
+178                     offset = BigInteger.ZERO;
+179                 }
+180 
+181                 sb.append(offset.toString());
+182                 sb.append('-');
+183 
+184                 if ((length != null) && (length.signum() == 1)) {
+185                     sb.append(offset.add(length.subtract(BigInteger.ONE)).toString());
+186                 }
+187 
+188                 request.setHeader("Range", sb.toString());
+189             }
+190 
+191             // compression
+192             Object compression = session.get(SessionParameter.COMPRESSION);
+193             if ((compression != null) && Boolean.parseBoolean(compression.toString())) {
+194                 request.setHeader("Accept-Encoding", "gzip,deflate");
+195             }
+196 
+197             // locale
+198             if (session.get(CmisBindingsHelper.ACCEPT_LANGUAGE) instanceof String) {
+199                 request.setHeader("Accept-Language", session.get(CmisBindingsHelper.ACCEPT_LANGUAGE).toString());
+200             }
+201 
+202             // send data
+203             if (writer != null) {
+204                 Object clientCompression = session.get(SessionParameter.CLIENT_COMPRESSION);
+205                 final boolean clientCompressionFlag = (clientCompression != null)
+206                         && Boolean.parseBoolean(clientCompression.toString());
+207                 if (clientCompressionFlag) {
+208                     request.setHeader("Content-Encoding", "gzip");
+209                 }
+210 
+211                 AbstractHttpEntity streamEntity = new AbstractHttpEntity() {
+212                     @Override
+213                     public boolean isChunked() {
+214                         return true;
+215                     }
+216 
+217                     public boolean isRepeatable() {
+218                         return false;
+219                     }
+220 
+221                     public long getContentLength() {
+222                         return -1;
+223                     }
+224 
+225                     public boolean isStreaming() {
+226                         return false;
+227                     }
+228 
+229                     public InputStream getContent() throws IOException {
+230                         throw new UnsupportedOperationException();
+231                     }
+232 
+233                     public void writeTo(final OutputStream outstream) throws IOException {
+234                         OutputStream connOut = null;
+235 
+236                         if (clientCompressionFlag) {
+237                             connOut = new GZIPOutputStream(outstream, 4096);
+238                         } else {
+239                             connOut = outstream;
+240                         }
+241 
+242                         OutputStream out = new BufferedOutputStream(connOut, BUFFER_SIZE);
+243                         try {
+244                             writer.write(out);
+245                         } catch (IOException ioe) {
+246                             throw ioe;
+247                         } catch (Exception e) {
+248                             throw new IOException(e);
+249                         }
+250                         out.flush();
+251 
+252                         if (connOut instanceof GZIPOutputStream) {
+253                             ((GZIPOutputStream) connOut).finish();
+254                         }
+255                     }
+256                 };
+257                 ((HttpEntityEnclosingRequestBase) request).setEntity(streamEntity);
+258             }
+259 
+260             // connect
+261             HttpResponse response = httpclient.execute(request);
+262             HttpEntity entity = response.getEntity();
+263 
+264             // get stream, if present
+265             respCode = response.getStatusLine().getStatusCode();
+266             InputStream inputStream = null;
+267             InputStream errorStream = null;
+268 
+269             if ((respCode == 200) || (respCode == 201) || (respCode == 203) || (respCode == 206)) {
+270                 if (entity != null) {
+271                     inputStream = entity.getContent();
+272                 } else {
+273                     inputStream = new ByteArrayInputStream(new byte[0]);
+274                 }
+275             } else {
+276                 if (entity != null) {
+277                     errorStream = entity.getContent();
+278                 } else {
+279                     errorStream = new ByteArrayInputStream(new byte[0]);
+280                 }
+281             }
+282 
+283             // collect headers
+284             Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
+285             for (Header header : response.getAllHeaders()) {
+286                 List<String> values = responseHeaders.get(header.getName());
+287                 if (values == null) {
+288                     values = new ArrayList<String>();
+289                     responseHeaders.put(header.getName(), values);
+290                 }
+291                 values.add(header.getValue());
+292             }
+293 
+294             // log after connect
+295             if (LOG.isTraceEnabled()) {
+296                 LOG.trace("Session {}: {} {} > Headers: {}", session.getSessionId(), method, url,
+297                         responseHeaders.toString());
+298             }
+299 
+300             // forward response HTTP headers
+301             if (authProvider != null) {
+302                 authProvider.putResponseHeaders(url.toString(), respCode, responseHeaders);
+303             }
+304 
+305             // get the response
+306             return new Response(respCode, response.getStatusLine().getReasonPhrase(), responseHeaders, inputStream,
+307                     errorStream);
+308         } catch (IOException e) {
+309             String status = (respCode > 0 ? " (HTTP status code " + respCode + ")" : "");
+310             throw new CmisConnectionException("Cannot access \"" + url + "\"" + status + ": " + e.getMessage(), e);
+311         }
+312     }
+313 
+314     /**
+315      * Creates default params for the Apache HTTP Client.
+316      */
+317     protected HttpParams createDefaultHttpParams(BindingSession session) {
+318         HttpParams params = new BasicHttpParams();
+319 
+320         HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
+321         HttpProtocolParams.setUserAgent(params, ClientVersion.OPENCMIS_CLIENT);
+322         HttpProtocolParams.setContentCharset(params, IOUtils.UTF8);
+323         HttpProtocolParams.setUseExpectContinue(params, true);
+324 
+325         HttpConnectionParams.setStaleCheckingEnabled(params, true);
+326 
+327         int connectTimeout = session.get(SessionParameter.CONNECT_TIMEOUT, -1);
+328         if (connectTimeout >= 0) {
+329             HttpConnectionParams.setConnectionTimeout(params, connectTimeout);
+330         }
+331 
+332         int readTimeout = session.get(SessionParameter.READ_TIMEOUT, -1);
+333         if (readTimeout >= 0) {
+334             HttpConnectionParams.setSoTimeout(params, readTimeout);
+335         }
+336 
+337         return params;
+338     }
+339 
+340     /**
+341      * Verifies a hostname with the given verifier.
+342      */
+343     protected void verify(HostnameVerifier verifier, String host, SSLSocket sslSocket) throws IOException {
+344         try {
+345             if (verifier instanceof X509HostnameVerifier) {
+346                 ((X509HostnameVerifier) verifier).verify(host, sslSocket);
+347             } else {
+348                 if (!verifier.verify(host, sslSocket.getSession())) {
+349                     throw new SSLException("Hostname in certificate didn't match: <" + host + ">");
+350                 }
+351             }
+352         } catch (IOException ioe) {
+353             closeSocket(sslSocket);
+354             throw ioe;
+355         }
+356     }
+357 
+358     /**
+359      * Closes the given socket and ignores exceptions.
+360      */
+361     protected void closeSocket(Socket socket) {
+362         try {
+363             socket.close();
+364         } catch (IOException ioe) {
+365             // ignore
+366         }
+367     }
+368 
+369     /**
+370      * Creates the {@link HttpClient} instance.
+371      */
+372     protected abstract DefaultHttpClient createHttpClient(UrlBuilder url, BindingSession session);
+373 }
+
+
+ + Added: chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/http/ApacheClientHttpInvoker.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/http/ApacheClientHttpInvoker.html?rev=1671596&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/http/ApacheClientHttpInvoker.html (added) +++ chemistry/site/trunk/content/java/0.13.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/http/ApacheClientHttpInvoker.html Mon Apr 6 17:10:50 2015 @@ -0,0 +1,187 @@ + + + + +ApacheClientHttpInvoker xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.client.bindings.spi.http;
+20  
+21  import java.io.IOException;
+22  import java.net.InetSocketAddress;
+23  import java.net.Socket;
+24  import java.net.SocketTimeoutException;
+25  
+26  import javax.net.ssl.HostnameVerifier;
+27  import javax.net.ssl.SSLSocket;
+28  import javax.net.ssl.SSLSocketFactory;
+29  
+30  import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper;
+31  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
+32  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
+33  import org.apache.chemistry.opencmis.commons.spi.AuthenticationProvider;
+34  import org.apache.http.client.params.ClientPNames;
+35  import org.apache.http.client.params.CookiePolicy;
+36  import org.apache.http.conn.ConnectTimeoutException;
+37  import org.apache.http.conn.HttpInetSocketAddress;
+38  import org.apache.http.conn.scheme.PlainSocketFactory;
+39  import org.apache.http.conn.scheme.Scheme;
+40  import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
+41  import org.apache.http.conn.scheme.SchemeRegistry;
+42  import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
+43  import org.apache.http.conn.ssl.X509HostnameVerifier;
+44  import org.apache.http.impl.client.DefaultHttpClient;
+45  import org.apache.http.impl.conn.PoolingClientConnectionManager;
+46  import org.apache.http.impl.conn.ProxySelectorRoutePlanner;
+47  import org.apache.http.params.HttpConnectionParams;
+48  import org.apache.http.params.HttpParams;
+49  
+50  /**
+51   * A {@link HttpInvoker} that uses The Apache HTTP client.
+52   */
+53  public class ApacheClientHttpInvoker extends AbstractApacheClientHttpInvoker {
+54  
+55      protected DefaultHttpClient createHttpClient(UrlBuilder url, BindingSession session) {
+56          // set params
+57          HttpParams params = createDefaultHttpParams(session);
+58          params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
+59  
+60          // set up scheme registry and connection manager
+61          SchemeRegistry registry = new SchemeRegistry();
+62          registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
+63          registry.register(new Scheme("https", 443, getSSLSocketFactory(url, session)));
+64  
+65          // set up connection manager
+66          PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(registry);
+67  
+68          // set max connection a
+69          String keepAliveStr = System.getProperty("http.keepAlive", "true");
+70          if ("true".equalsIgnoreCase(keepAliveStr)) {
+71              String maxConnStr = System.getProperty("http.maxConnections", "5");
+72              int maxConn = 5;
+73              try {
+74                  maxConn = Integer.parseInt(maxConnStr);
+75              } catch (NumberFormatException nfe) {
+76                  // ignore
+77              }
+78              connManager.setDefaultMaxPerRoute(maxConn);
+79              connManager.setMaxTotal(4 * maxConn);
+80          }
+81  
+82          // set up proxy
+83          ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(registry, null);
+84  
+85          // set up client
+86          DefaultHttpClient httpclient = new DefaultHttpClient(connManager, params);
+87          httpclient.setRoutePlanner(routePlanner);
+88  
+89          return httpclient;
+90      }
+91  
+92      /**
+93       * Builds a SSL Socket Factory for the Apache HTTP Client.
+94       */
+95      private SchemeLayeredSocketFactory getSSLSocketFactory(final UrlBuilder url, final BindingSession session) {
+96          // get authentication provider
+97          AuthenticationProvider authProvider = CmisBindingsHelper.getAuthenticationProvider(session);
+98  
+99          // check SSL Socket Factory
+100         final SSLSocketFactory sf = authProvider.getSSLSocketFactory();
+101         if (sf == null) {
+102             // no custom factory -> return default factory
+103             return org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory();
+104         }
+105 
+106         // check hostame verifier and use default if not set
+107         final HostnameVerifier hv = (authProvider.getHostnameVerifier() == null ? new BrowserCompatHostnameVerifier()
+108                 : authProvider.getHostnameVerifier());
+109 
+110         if (hv instanceof X509HostnameVerifier) {
+111             return new org.apache.http.conn.ssl.SSLSocketFactory(sf, (X509HostnameVerifier) hv);
+112         }
+113 
+114         // build new socket factory
+115         return new SchemeLayeredSocketFactory() {
+116 
+117             public boolean isSecure(Socket sock) {
+118                 return true;
+119             }
+120 
+121             public Socket createSocket(HttpParams params) throws IOException {
+122                 return sf.createSocket();
+123             }
+124 
+125             public Socket connectSocket(final Socket socket, final InetSocketAddress remoteAddress,
+126                     final InetSocketAddress localAddress, final HttpParams params) throws IOException {
+127 
+128                 Socket sock = (socket != null ? socket : createSocket(params));
+129                 if (localAddress != null) {
+130                     sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
+131                     sock.bind(localAddress);
+132                 }
+133 
+134                 int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
+135                 int soTimeout = HttpConnectionParams.getSoTimeout(params);
+136 
+137                 try {
+138                     sock.setSoTimeout(soTimeout);
+139                     sock.connect(remoteAddress, connTimeout);
+140                 } catch (SocketTimeoutException ex) {
+141                     closeSocket(sock);
+142                     throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out!");
+143                 }
+144 
+145                 String host;
+146                 if (remoteAddress instanceof HttpInetSocketAddress) {
+147                     host = ((HttpInetSocketAddress) remoteAddress).getHttpHost().getHostName();
+148                 } else {
+149                     host = remoteAddress.getHostName();
+150                 }
+151 
+152                 SSLSocket sslSocket;
+153                 if (sock instanceof SSLSocket) {
+154                     sslSocket = (SSLSocket) sock;
+155                 } else {
+156                     int port = remoteAddress.getPort();
+157                     sslSocket = (SSLSocket) sf.createSocket(sock, host, port, true);
+158                 }
+159                 verify(hv, host, sslSocket);
+160 
+161                 return sslSocket;
+162             }
+163 
+164             public Socket createLayeredSocket(final Socket socket, final String host, final int port,
+165                     final HttpParams params) throws IOException {
+166                 SSLSocket sslSocket = (SSLSocket) sf.createSocket(socket, host, port, true);
+167                 verify(hv, host, sslSocket);
+168 
+169                 return sslSocket;
+170             }
+171         };
+172     }
+173 }
+
+
+ +