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 0954FD7DB for ; Mon, 27 May 2013 17:22:21 +0000 (UTC) Received: (qmail 69863 invoked by uid 500); 27 May 2013 17:22:20 -0000 Delivered-To: apmail-chemistry-commits-archive@chemistry.apache.org Received: (qmail 69771 invoked by uid 500); 27 May 2013 17:22:20 -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 69708 invoked by uid 99); 27 May 2013 17:22:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 May 2013 17:22:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 May 2013 17:22:13 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A58FB2388C7D; Mon, 27 May 2013 17:20:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1486674 [39/44] - in /chemistry/site/trunk/content/java/0.9.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, 27 May 2013 17:20:22 -0000 To: commits@chemistry.apache.org From: gabriele@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130527172035.A58FB2388C7D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.html?rev=1486674&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.html (added) +++ chemistry/site/trunk/content/java/0.9.0/maven/chemistry-opencmis-client/chemistry-opencmis-client-bindings/xref/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.html Mon May 27 17:20:16 2013 @@ -0,0 +1,694 @@ + + + + +AbstractPortProvider 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.webservices;
+20  
+21  import java.io.BufferedInputStream;
+22  import java.io.IOException;
+23  import java.io.InputStream;
+24  import java.lang.ref.SoftReference;
+25  import java.lang.reflect.Constructor;
+26  import java.math.BigInteger;
+27  import java.net.MalformedURLException;
+28  import java.net.URL;
+29  import java.util.Collections;
+30  import java.util.EnumMap;
+31  import java.util.HashMap;
+32  import java.util.Iterator;
+33  import java.util.LinkedList;
+34  import java.util.List;
+35  import java.util.Map;
+36  import java.util.concurrent.locks.ReentrantLock;
+37  
+38  import javax.xml.namespace.QName;
+39  import javax.xml.parsers.ParserConfigurationException;
+40  import javax.xml.ws.BindingProvider;
+41  import javax.xml.ws.Service;
+42  import javax.xml.ws.WebServiceFeature;
+43  import javax.xml.ws.handler.MessageContext;
+44  import javax.xml.ws.http.HTTPException;
+45  
+46  import org.apache.chemistry.opencmis.client.bindings.impl.ClientVersion;
+47  import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper;
+48  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
+49  import org.apache.chemistry.opencmis.client.bindings.spi.http.HttpInvoker;
+50  import org.apache.chemistry.opencmis.client.bindings.spi.http.Response;
+51  import org.apache.chemistry.opencmis.commons.SessionParameter;
+52  import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
+53  import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
+54  import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
+55  import org.apache.chemistry.opencmis.commons.exceptions.CmisProxyAuthenticationException;
+56  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+57  import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException;
+58  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
+59  import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
+60  import org.apache.chemistry.opencmis.commons.impl.jaxb.ACLService;
+61  import org.apache.chemistry.opencmis.commons.impl.jaxb.ACLServicePort;
+62  import org.apache.chemistry.opencmis.commons.impl.jaxb.DiscoveryService;
+63  import org.apache.chemistry.opencmis.commons.impl.jaxb.DiscoveryServicePort;
+64  import org.apache.chemistry.opencmis.commons.impl.jaxb.MultiFilingService;
+65  import org.apache.chemistry.opencmis.commons.impl.jaxb.MultiFilingServicePort;
+66  import org.apache.chemistry.opencmis.commons.impl.jaxb.NavigationService;
+67  import org.apache.chemistry.opencmis.commons.impl.jaxb.NavigationServicePort;
+68  import org.apache.chemistry.opencmis.commons.impl.jaxb.ObjectService;
+69  import org.apache.chemistry.opencmis.commons.impl.jaxb.ObjectServicePort;
+70  import org.apache.chemistry.opencmis.commons.impl.jaxb.PolicyService;
+71  import org.apache.chemistry.opencmis.commons.impl.jaxb.PolicyServicePort;
+72  import org.apache.chemistry.opencmis.commons.impl.jaxb.RelationshipService;
+73  import org.apache.chemistry.opencmis.commons.impl.jaxb.RelationshipServicePort;
+74  import org.apache.chemistry.opencmis.commons.impl.jaxb.RepositoryService;
+75  import org.apache.chemistry.opencmis.commons.impl.jaxb.RepositoryServicePort;
+76  import org.apache.chemistry.opencmis.commons.impl.jaxb.VersioningService;
+77  import org.apache.chemistry.opencmis.commons.impl.jaxb.VersioningServicePort;
+78  import org.apache.chemistry.opencmis.commons.spi.AuthenticationProvider;
+79  import org.slf4j.Logger;
+80  import org.slf4j.LoggerFactory;
+81  import org.w3c.dom.Document;
+82  import org.w3c.dom.Element;
+83  import org.w3c.dom.NodeList;
+84  import org.xml.sax.SAXException;
+85  
+86  public abstract class AbstractPortProvider {
+87  
+88      private static final Logger LOG = LoggerFactory.getLogger(AbstractPortProvider.class);
+89  
+90      private static final int PORT_CACHE_SIZE = 5;
+91  
+92      protected static final int CHUNK_SIZE = (64 * 1024) - 1;
+93  
+94      protected enum CmisWebSerivcesService {
+95          REPOSITORY_SERVICE("RepositoryService", false, RepositoryService.class, RepositoryServicePort.class,
+96                  SessionParameter.WEBSERVICES_REPOSITORY_SERVICE,
+97                  SessionParameter.WEBSERVICES_REPOSITORY_SERVICE_ENDPOINT),
+98  
+99          NAVIGATION_SERVICE("NavigationService", false, NavigationService.class, NavigationServicePort.class,
+100                 SessionParameter.WEBSERVICES_NAVIGATION_SERVICE,
+101                 SessionParameter.WEBSERVICES_NAVIGATION_SERVICE_ENDPOINT),
+102 
+103         OBJECT_SERVICE("ObjectService", true, ObjectService.class, ObjectServicePort.class,
+104                 SessionParameter.WEBSERVICES_OBJECT_SERVICE, SessionParameter.WEBSERVICES_OBJECT_SERVICE_ENDPOINT),
+105 
+106         VERSIONING_SERVICE("VersioningService", true, VersioningService.class, VersioningServicePort.class,
+107                 SessionParameter.WEBSERVICES_VERSIONING_SERVICE,
+108                 SessionParameter.WEBSERVICES_VERSIONING_SERVICE_ENDPOINT),
+109 
+110         DISCOVERY_SERVICE("DiscoveryService", false, DiscoveryService.class, DiscoveryServicePort.class,
+111                 SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, SessionParameter.WEBSERVICES_DISCOVERY_SERVICE_ENDPOINT),
+112 
+113         MULTIFILING_SERVICE("MultiFilingService", false, MultiFilingService.class, MultiFilingServicePort.class,
+114                 SessionParameter.WEBSERVICES_MULTIFILING_SERVICE,
+115                 SessionParameter.WEBSERVICES_MULTIFILING_SERVICE_ENDPOINT),
+116 
+117         RELATIONSHIP_SERVICE("RelationshipService", false, RelationshipService.class, RelationshipServicePort.class,
+118                 SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE,
+119                 SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE_ENDPOINT),
+120 
+121         POLICY_SERVICE("PolicyService", false, PolicyService.class, PolicyServicePort.class,
+122                 SessionParameter.WEBSERVICES_POLICY_SERVICE, SessionParameter.WEBSERVICES_POLICY_SERVICE_ENDPOINT),
+123 
+124         ACL_SERVICE("ACLService", false, ACLService.class, ACLServicePort.class,
+125                 SessionParameter.WEBSERVICES_ACL_SERVICE, SessionParameter.WEBSERVICES_ACL_SERVICE_ENDPOINT);
+126 
+127         private final String name;
+128         private final QName qname;
+129         private final boolean handlesContent;
+130         private final Class<? extends Service> serviceClass;
+131         private final Class<?> portClass;
+132         private final String wsdlKey;
+133         private final String endpointKey;
+134 
+135         CmisWebSerivcesService(String localname, boolean handlesContent, Class<? extends Service> serviceClass,
+136                 Class<?> port11Class, String wsdlKey, String endpointKey) {
+137             this.name = localname;
+138             this.qname = new QName("http://docs.oasis-open.org/ns/cmis/ws/200908/", localname);
+139             this.handlesContent = handlesContent;
+140             this.serviceClass = serviceClass;
+141             this.portClass = port11Class;
+142             this.wsdlKey = wsdlKey;
+143             this.endpointKey = endpointKey;
+144         }
+145 
+146         public String getServiceName() {
+147             return name;
+148         }
+149 
+150         public QName getQName() {
+151             return qname;
+152         }
+153 
+154         public boolean handlesContent() {
+155             return handlesContent;
+156         }
+157 
+158         public Class<? extends Service> getServiceClass() {
+159             return serviceClass;
+160         }
+161 
+162         public Class<?> getPortClass() {
+163             return portClass;
+164         }
+165 
+166         public String getWsdlKey() {
+167             return wsdlKey;
+168         }
+169 
+170         public String getEndpointKey() {
+171             return endpointKey;
+172         }
+173     }
+174 
+175     static class CmisServiceHolder {
+176         private final CmisWebSerivcesService service;
+177         private SoftReference<Service> serviceObject;
+178         private final URL endpointUrl;
+179 
+180         public CmisServiceHolder(final CmisWebSerivcesService service, final URL endpointUrl) throws Exception {
+181             this.service = service;
+182             this.endpointUrl = endpointUrl;
+183             this.serviceObject = new SoftReference<Service>(createServiceObject());
+184         }
+185 
+186         private Service createServiceObject() throws Exception {
+187             final Constructor<? extends Service> serviceConstructor = service.getServiceClass().getConstructor(
+188                     new Class<?>[] { URL.class, QName.class });
+189             return serviceConstructor.newInstance(new Object[] { null, service.getQName() });
+190         }
+191 
+192         public CmisWebSerivcesService getService() {
+193             return service;
+194         }
+195 
+196         public Service getServiceObject() throws Exception {
+197             Service result = serviceObject.get();
+198             if (result == null) {
+199                 result = createServiceObject();
+200                 serviceObject = new SoftReference<Service>(result);
+201             }
+202 
+203             return result;
+204         }
+205 
+206         public URL getEndpointUrl() {
+207             return endpointUrl;
+208         }
+209 
+210         public String getServiceName() {
+211             return service.getServiceName();
+212         }
+213     }
+214 
+215     private BindingSession session;
+216     protected boolean useCompression;
+217     protected boolean useClientCompression;
+218     protected String acceptLanguage;
+219 
+220     private final ReentrantLock portObjectLock = new ReentrantLock();
+221     private final EnumMap<CmisWebSerivcesService, LinkedList<SoftReference<BindingProvider>>> portObjectCache = new EnumMap<CmisWebSerivcesService, LinkedList<SoftReference<BindingProvider>>>(
+222             CmisWebSerivcesService.class);
+223 
+224     public BindingSession getSession() {
+225         return session;
+226     }
+227 
+228     public void setSession(BindingSession session) {
+229         this.session = session;
+230 
+231         final Object compression = session.get(SessionParameter.COMPRESSION);
+232         useCompression = (compression != null) && Boolean.parseBoolean(compression.toString());
+233 
+234         final Object clientCompression = session.get(SessionParameter.CLIENT_COMPRESSION);
+235         useClientCompression = (clientCompression != null) && Boolean.parseBoolean(clientCompression.toString());
+236 
+237         if (session.get(CmisBindingsHelper.ACCEPT_LANGUAGE) instanceof String) {
+238             acceptLanguage = session.get(CmisBindingsHelper.ACCEPT_LANGUAGE).toString();
+239         }
+240     }
+241 
+242     /**
+243      * Return the Repository Service port object.
+244      */
+245     public RepositoryServicePort getRepositoryServicePort(CmisVersion cmisVersion, String soapAction) {
+246         BindingProvider portObject = getPortObject(CmisWebSerivcesService.REPOSITORY_SERVICE);
+247         setSoapAction(portObject, soapAction, cmisVersion);
+248 
+249         return (RepositoryServicePort) portObject;
+250     }
+251 
+252     /**
+253      * Return the Navigation Service port object.
+254      */
+255     public NavigationServicePort getNavigationServicePort(CmisVersion cmisVersion, String soapAction) {
+256         BindingProvider portObject = getPortObject(CmisWebSerivcesService.NAVIGATION_SERVICE);
+257         setSoapAction(portObject, soapAction, cmisVersion);
+258 
+259         return (NavigationServicePort) portObject;
+260     }
+261 
+262     /**
+263      * Return the Object Service port object.
+264      */
+265     public ObjectServicePort getObjectServicePort(CmisVersion cmisVersion, String soapAction) {
+266         BindingProvider portObject = getPortObject(CmisWebSerivcesService.OBJECT_SERVICE);
+267         setSoapAction(portObject, soapAction, cmisVersion);
+268 
+269         return (ObjectServicePort) portObject;
+270     }
+271 
+272     /**
+273      * Return the Versioning Service port object.
+274      */
+275     public VersioningServicePort getVersioningServicePort(CmisVersion cmisVersion, String soapAction) {
+276         BindingProvider portObject = getPortObject(CmisWebSerivcesService.VERSIONING_SERVICE);
+277         setSoapAction(portObject, soapAction, cmisVersion);
+278 
+279         return (VersioningServicePort) portObject;
+280     }
+281 
+282     /**
+283      * Return the Discovery Service port object.
+284      */
+285     public DiscoveryServicePort getDiscoveryServicePort(CmisVersion cmisVersion, String soapAction) {
+286         BindingProvider portObject = getPortObject(CmisWebSerivcesService.DISCOVERY_SERVICE);
+287         setSoapAction(portObject, soapAction, cmisVersion);
+288 
+289         return (DiscoveryServicePort) portObject;
+290     }
+291 
+292     /**
+293      * Return the MultiFiling Service port object.
+294      */
+295     public MultiFilingServicePort getMultiFilingServicePort(CmisVersion cmisVersion, String soapAction) {
+296         BindingProvider portObject = getPortObject(CmisWebSerivcesService.MULTIFILING_SERVICE);
+297         setSoapAction(portObject, soapAction, cmisVersion);
+298 
+299         return (MultiFilingServicePort) portObject;
+300     }
+301 
+302     /**
+303      * Return the Relationship Service port object.
+304      */
+305     public RelationshipServicePort getRelationshipServicePort(CmisVersion cmisVersion, String soapAction) {
+306         BindingProvider portObject = getPortObject(CmisWebSerivcesService.RELATIONSHIP_SERVICE);
+307         setSoapAction(portObject, soapAction, cmisVersion);
+308 
+309         return (RelationshipServicePort) portObject;
+310     }
+311 
+312     /**
+313      * Return the Policy Service port object.
+314      */
+315     public PolicyServicePort getPolicyServicePort(CmisVersion cmisVersion, String soapAction) {
+316         BindingProvider portObject = getPortObject(CmisWebSerivcesService.POLICY_SERVICE);
+317         setSoapAction(portObject, soapAction, cmisVersion);
+318 
+319         return (PolicyServicePort) portObject;
+320     }
+321 
+322     /**
+323      * Return the ACL Service port object.
+324      */
+325     public ACLServicePort getACLServicePort(CmisVersion cmisVersion, String soapAction) {
+326         BindingProvider portObject = getPortObject(CmisWebSerivcesService.ACL_SERVICE);
+327         setSoapAction(portObject, soapAction, cmisVersion);
+328 
+329         return (ACLServicePort) portObject;
+330     }
+331 
+332     public void endCall(Object portObject) {
+333         AuthenticationProvider authProvider = CmisBindingsHelper.getAuthenticationProvider(session);
+334         if (authProvider != null && portObject instanceof BindingProvider) {
+335             BindingProvider bp = (BindingProvider) portObject;
+336             String url = (String) bp.getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
+337             if (bp.getResponseContext() != null) {
+338                 @SuppressWarnings("unchecked")
+339                 Map<String, List<String>> headers = (Map<String, List<String>>) bp.getResponseContext().get(
+340                         MessageContext.HTTP_RESPONSE_HEADERS);
+341                 Integer statusCode = (Integer) bp.getResponseContext().get(MessageContext.HTTP_RESPONSE_CODE);
+342                 authProvider.putResponseHeaders(url, statusCode == null ? -1 : statusCode, headers);
+343             }
+344 
+345             CmisWebSerivcesService service = null;
+346 
+347             if (portObject instanceof RepositoryServicePort) {
+348                 service = CmisWebSerivcesService.REPOSITORY_SERVICE;
+349             } else if (portObject instanceof NavigationServicePort) {
+350                 service = CmisWebSerivcesService.NAVIGATION_SERVICE;
+351             } else if (portObject instanceof ObjectServicePort) {
+352                 service = CmisWebSerivcesService.OBJECT_SERVICE;
+353             } else if (portObject instanceof VersioningServicePort) {
+354                 service = CmisWebSerivcesService.VERSIONING_SERVICE;
+355             } else if (portObject instanceof DiscoveryServicePort) {
+356                 service = CmisWebSerivcesService.DISCOVERY_SERVICE;
+357             } else if (portObject instanceof MultiFilingServicePort) {
+358                 service = CmisWebSerivcesService.MULTIFILING_SERVICE;
+359             } else if (portObject instanceof RelationshipServicePort) {
+360                 service = CmisWebSerivcesService.RELATIONSHIP_SERVICE;
+361             } else if (portObject instanceof PolicyServicePort) {
+362                 service = CmisWebSerivcesService.POLICY_SERVICE;
+363             } else if (portObject instanceof ACLServicePort) {
+364                 service = CmisWebSerivcesService.ACL_SERVICE;
+365             }
+366 
+367             if (service == null) {
+368                 return;
+369             }
+370 
+371             portObjectLock.lock();
+372             try {
+373                 LinkedList<SoftReference<BindingProvider>> queue = portObjectCache.get(service);
+374                 if (queue == null) {
+375                     throw new CmisRuntimeException("This is a bug!");
+376                 }
+377 
+378                 if (queue.size() < PORT_CACHE_SIZE) {
+379                     queue.push(new SoftReference<BindingProvider>(bp));
+380                 } else {
+381                     Iterator<SoftReference<BindingProvider>> iter = queue.iterator();
+382                     while (iter.hasNext()) {
+383                         SoftReference<BindingProvider> ref = iter.next();
+384                         if (ref.get() == null) {
+385                             iter.remove();
+386                             queue.push(new SoftReference<BindingProvider>(bp));
+387                             break;
+388                         }
+389                     }
+390                 }
+391             } finally {
+392                 portObjectLock.unlock();
+393             }
+394         }
+395     }
+396 
+397     // ---- internal ----
+398 
+399     @SuppressWarnings("unchecked")
+400     protected BindingProvider getPortObject(final CmisWebSerivcesService service) {
+401         Map<CmisWebSerivcesService, CmisServiceHolder> serviceMap = (Map<CmisWebSerivcesService, CmisServiceHolder>) session
+402                 .get(SpiSessionParameter.SERVICES);
+403 
+404         // does the service map exist?
+405         if (serviceMap == null) {
+406             session.writeLock();
+407             try {
+408                 // try again
+409                 serviceMap = (Map<CmisWebSerivcesService, CmisServiceHolder>) session.get(SpiSessionParameter.SERVICES);
+410                 if (serviceMap == null) {
+411                     serviceMap = new EnumMap<CmisWebSerivcesService, CmisServiceHolder>(CmisWebSerivcesService.class);
+412                     session.put(SpiSessionParameter.SERVICES, serviceMap, true);
+413                 }
+414 
+415                 if (serviceMap.containsKey(service)) {
+416                     return createPortObject(serviceMap.get(service));
+417                 }
+418 
+419                 // create service object
+420                 CmisServiceHolder serviceholder = initServiceObject(service);
+421                 serviceMap.put(service, serviceholder);
+422 
+423                 // create port object
+424                 return createPortObject(serviceholder);
+425             } finally {
+426                 session.writeUnlock();
+427             }
+428         }
+429 
+430         // is the service in the service map?
+431         if (!serviceMap.containsKey(service)) {
+432             session.writeLock();
+433             try {
+434                 // try again
+435                 if (serviceMap.containsKey(service)) {
+436                     return createPortObject(serviceMap.get(service));
+437                 }
+438 
+439                 // create object
+440                 CmisServiceHolder serviceholder = initServiceObject(service);
+441                 serviceMap.put(service, serviceholder);
+442 
+443                 return createPortObject(serviceholder);
+444             } finally {
+445                 session.writeUnlock();
+446             }
+447         }
+448 
+449         return createPortObject(serviceMap.get(service));
+450     }
+451 
+452     /**
+453      * Creates a service object.
+454      */
+455     protected CmisServiceHolder initServiceObject(final CmisWebSerivcesService service) {
+456         if (LOG.isDebugEnabled()) {
+457             LOG.debug("Initializing Web Service " + service.getServiceName() + "...");
+458         }
+459 
+460         try {
+461             // get URLs
+462             URL endpointUrl = null;
+463 
+464             String wsdlUrlStr = (String) session.get(service.getWsdlKey());
+465             if (wsdlUrlStr != null) {
+466                 endpointUrl = getEndpointUrlFromWsdl(wsdlUrlStr, service);
+467             } else {
+468                 String endpointUrlStr = (String) session.get(service.getEndpointKey());
+469                 if (endpointUrlStr != null) {
+470                     endpointUrl = new URL(endpointUrlStr);
+471                 }
+472             }
+473 
+474             if (endpointUrl == null) {
+475                 throw new CmisRuntimeException("Neither a WSDL URL nor an endpoint URL is specified for the service "
+476                         + service.getServiceName() + "!");
+477             }
+478 
+479             // build the requested service object
+480             return new CmisServiceHolder(service, endpointUrl);
+481         } catch (CmisBaseException ce) {
+482             throw ce;
+483         } catch (Exception e) {
+484             String message = "Cannot initalize Web Services service object [" + service.getServiceName() + "]: "
+485                     + e.getMessage();
+486 
+487             if (e instanceof HTTPException) {
+488                 HTTPException he = (HTTPException) e;
+489                 if (he.getStatusCode() == 401) {
+490                     throw new CmisUnauthorizedException(message, e);
+491                 } else if (he.getStatusCode() == 407) {
+492                     throw new CmisProxyAuthenticationException(message, e);
+493                 }
+494             }
+495 
+496             throw new CmisConnectionException(message, e);
+497         }
+498     }
+499 
+500     /**
+501      * Reads the URL and extracts the endpoint URL of the given service.
+502      */
+503     private URL getEndpointUrlFromWsdl(final String wsdlUrl, final CmisWebSerivcesService service) {
+504         InputStream wsdlStream;
+505         URL url;
+506 
+507         // check the WSDL URL
+508         try {
+509             url = new URL(wsdlUrl);
+510         } catch (MalformedURLException e) {
+511             throw new CmisConnectionException("Invalid WSDL URL: " + wsdlUrl, e);
+512         }
+513 
+514         // check protocol
+515         if (url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https")) {
+516             // HTTP URL -> use HttpInvoker to enable authentication
+517             HttpInvoker hi = CmisBindingsHelper.getHttpInvoker(session);
+518             Response wsdlResponse = hi.invokeGET(new UrlBuilder(wsdlUrl), session);
+519 
+520             if (wsdlResponse.getResponseCode() != 200) {
+521                 throw new CmisConnectionException("Cannot access WSDL: " + wsdlUrl, BigInteger.ZERO,
+522                         wsdlResponse.getErrorContent());
+523             } else {
+524                 wsdlStream = wsdlResponse.getStream();
+525             }
+526         } else {
+527             // non-HTTP URL -> just open the stream
+528             try {
+529                 wsdlStream = url.openStream();
+530             } catch (IOException e) {
+531                 throw new CmisConnectionException("Cannot access WSDL: " + wsdlUrl, e);
+532             }
+533         }
+534 
+535         // parse the WSDL
+536         try {
+537             final Document doc = XMLUtils.parseDomDocument(new BufferedInputStream(wsdlStream, 16 * 1024));
+538 
+539             NodeList serivceList = doc.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/", "service");
+540             for (int i = 0; i < serivceList.getLength(); i++) {
+541                 Element serviceNode = (Element) serivceList.item(i);
+542 
+543                 String name = serviceNode.getAttribute("name");
+544                 if (name == null) {
+545                     continue;
+546                 }
+547 
+548                 if (!service.getQName().getLocalPart().equals(name)) {
+549                     continue;
+550                 }
+551 
+552                 NodeList portList = ((Element) serviceNode).getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/",
+553                         "port");
+554                 if (portList.getLength() < 1) {
+555                     throw new CmisRuntimeException("This service has no ports: " + service.getServiceName());
+556                 }
+557 
+558                 Element port = (Element) portList.item(0);
+559 
+560                 NodeList addressList = port.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/soap/", "address");
+561                 if (addressList.getLength() < 1) {
+562                     throw new CmisRuntimeException("This service has no endpoint address: " + service.getServiceName());
+563                 }
+564 
+565                 Element address = (Element) addressList.item(0);
+566 
+567                 String location = address.getAttribute("location");
+568                 if (location == null) {
+569                     throw new CmisRuntimeException("This service has no endpoint address: " + service.getServiceName());
+570                 }
+571 
+572                 try {
+573                     return new URL(location);
+574                 } catch (MalformedURLException e) {
+575                     throw new CmisRuntimeException("This service provides an invalid endpoint address: "
+576                             + service.getServiceName());
+577                 }
+578             }
+579 
+580             throw new CmisRuntimeException("This service does not provide an endpoint address: "
+581                     + service.getServiceName());
+582         } catch (ParserConfigurationException pe) {
+583             throw new CmisRuntimeException("Cannot parse this WSDL: " + wsdlUrl, pe);
+584         } catch (SAXException se) {
+585             throw new CmisRuntimeException("Cannot parse this WSDL: " + wsdlUrl, se);
+586         } catch (IOException ioe) {
+587             throw new CmisRuntimeException("Cannot read this WSDL: " + wsdlUrl, ioe);
+588         } finally {
+589             try {
+590                 wsdlStream.close();
+591             } catch (IOException ioe) {
+592                 // ignore, there is nothing we can do
+593             }
+594         }
+595     }
+596 
+597     /**
+598      * Sets the default HTTP headers on a {@link BindingProvider} object.
+599      */
+600     protected void setHTTPHeaders(BindingProvider portObject, Map<String, List<String>> httpHeaders) {
+601         if (httpHeaders == null) {
+602             httpHeaders = new HashMap<String, List<String>>();
+603         }
+604 
+605         // CMIS client header
+606         httpHeaders.put("X-CMIS-Client", Collections.singletonList(ClientVersion.OPENCMIS_CLIENT));
+607 
+608         // compression
+609         if (useCompression) {
+610             httpHeaders.put("Accept-Encoding", Collections.singletonList("gzip"));
+611         }
+612 
+613         // client compression
+614         if (useClientCompression) {
+615             httpHeaders.put("Content-Encoding", Collections.singletonList("gzip"));
+616         }
+617 
+618         // locale
+619         if (acceptLanguage != null) {
+620             httpHeaders.put("Accept-Language", Collections.singletonList(acceptLanguage));
+621         }
+622 
+623         portObject.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);
+624     }
+625 
+626     /**
+627      * Sets the endpoint URL if the URL is not <code>null</code>.
+628      */
+629     protected void setEndpointUrl(BindingProvider portObject, URL endpointUrl) {
+630         if (endpointUrl == null) {
+631             return;
+632         }
+633 
+634         portObject.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl.toString());
+635     }
+636 
+637     /**
+638      * Sets the SOAP Action header.
+639      */
+640     protected void setSoapAction(BindingProvider portObject, String soapAction, CmisVersion cmisVersion) {
+641         if (cmisVersion == CmisVersion.CMIS_1_0) {
+642             portObject.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.FALSE);
+643         } else {
+644             portObject.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
+645             portObject.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, soapAction);
+646         }
+647     }
+648 
+649     /**
+650      * Creates a simple port object from a CmisServiceHolder object.
+651      */
+652     protected BindingProvider createPortObjectFromServiceHolder(final CmisServiceHolder serviceHolder,
+653             WebServiceFeature... features) throws Exception {
+654         portObjectLock.lock();
+655         try {
+656             LinkedList<SoftReference<BindingProvider>> queue = portObjectCache.get(serviceHolder.getService());
+657             if (queue == null) {
+658                 queue = new LinkedList<SoftReference<BindingProvider>>();
+659                 portObjectCache.put(serviceHolder.getService(), queue);
+660             }
+661 
+662             while (!queue.isEmpty()) {
+663                 BindingProvider bp = queue.pop().get();
+664                 if (bp != null) {

[... 21 lines stripped ...]