View Javadoc

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 javax.xml.ws.spi.Provider;
22  
23  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
24  import org.apache.chemistry.opencmis.client.bindings.spi.CmisSpi;
25  import org.apache.chemistry.opencmis.commons.SessionParameter;
26  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
27  import org.apache.chemistry.opencmis.commons.impl.ClassLoaderUtil;
28  import org.apache.chemistry.opencmis.commons.spi.AclService;
29  import org.apache.chemistry.opencmis.commons.spi.DiscoveryService;
30  import org.apache.chemistry.opencmis.commons.spi.MultiFilingService;
31  import org.apache.chemistry.opencmis.commons.spi.NavigationService;
32  import org.apache.chemistry.opencmis.commons.spi.ObjectService;
33  import org.apache.chemistry.opencmis.commons.spi.PolicyService;
34  import org.apache.chemistry.opencmis.commons.spi.RelationshipService;
35  import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
36  import org.apache.chemistry.opencmis.commons.spi.VersioningService;
37  import org.slf4j.Logger;
38  import org.slf4j.LoggerFactory;
39  
40  /**
41   * CMIS Web Services SPI implementation.
42   */
43  public class CmisWebServicesSpi implements CmisSpi {
44  
45      public static final String JAXWS_IMPL_RI = "sunri";
46      public static final String JAXWS_IMPL_JRE = "sunjre";
47      public static final String JAXWS_IMPL_CXF = "cxf";
48      public static final String JAXWS_IMPL_WEBSPHERE = "websphere";
49      public static final String JAXWS_IMPL_AXIS2 = "axis2";
50  
51      private static final Logger LOG = LoggerFactory.getLogger(CmisWebServicesSpi.class);
52  
53      private final RepositoryService repositoryService;
54      private final NavigationService navigationService;
55      private final ObjectService objectService;
56      private final VersioningService versioningService;
57      private final DiscoveryService discoveryService;
58      private final MultiFilingService multiFilingService;
59      private final RelationshipService relationshipService;
60      private final PolicyService policyService;
61      private final AclService aclService;
62  
63      /**
64       * Constructor.
65       */
66      public CmisWebServicesSpi(BindingSession session) {
67          if (LOG.isDebugEnabled()) {
68              LOG.debug("Session {}: Initializing Web Services SPI...", session.getSessionId());
69          }
70  
71          AbstractPortProvider portProvider = null;
72  
73          String portProviderClass = (String) session.get(SessionParameter.WEBSERVICES_PORT_PROVIDER_CLASS);
74          if (portProviderClass == null) {
75              String jaxwsImpl = (String) session.get(SessionParameter.WEBSERVICES_JAXWS_IMPL);
76  
77              if (jaxwsImpl == null) {
78                  jaxwsImpl = System.getProperty("org.apache.chemistry.opencmis.binding.webservices.jaxws.impl");
79              }
80  
81              if (jaxwsImpl == null) {
82                  Provider provider = Provider.provider();
83                  if (provider == null) {
84                      throw new CmisRuntimeException("No JAX-WS implementation found!");
85                  }
86  
87                  String providerPackage = provider.getClass().getPackage().getName();
88  
89                  if (providerPackage.startsWith("com.sun.xml.internal.ws.spi")) {
90                      throw new CmisRuntimeException(
91                              "JRE JAX-WS implementation not supported anymore. Please use Apache CXF.");
92                  } else if (providerPackage.startsWith("com.sun.xml.ws.spi")) {
93                      throw new CmisRuntimeException("JAX-WS RI not supported anymore. Please use Apache CXF.");
94                  } else if (providerPackage.startsWith("org.apache.cxf.jaxws")) {
95                      portProvider = new CXFPortProvider();
96                  } else if (providerPackage.startsWith("org.apache.axis2.jaxws.spi")) {
97                      throw new CmisRuntimeException("Axis2 not supported anymore. Please use Apache CXF.");
98                  } else {
99                      throw new CmisRuntimeException("Could not detect JAX-WS implementation! Use session parameter "
100                             + SessionParameter.WEBSERVICES_JAXWS_IMPL + " to specify one.");
101                 }
102             } else if (JAXWS_IMPL_JRE.equals(jaxwsImpl)) {
103                 throw new CmisRuntimeException(
104                         "JRE JAX-WS implementation not supported anymore. Please use Apache CXF.");
105             } else if (JAXWS_IMPL_RI.equals(jaxwsImpl)) {
106                 throw new CmisRuntimeException("JAX-WS RI not supported anymore. Please use Apache CXF.");
107             } else if (JAXWS_IMPL_CXF.equals(jaxwsImpl)) {
108                 portProvider = new CXFPortProvider();
109             } else if (JAXWS_IMPL_WEBSPHERE.equals(jaxwsImpl)) {
110                 portProvider = new WebSpherePortProvider();
111             } else if (JAXWS_IMPL_AXIS2.equals(jaxwsImpl)) {
112                 throw new CmisRuntimeException("Axis2 not supported anymore. Please use Apache CXF.");
113             } else {
114                 throw new CmisRuntimeException("Unknown JAX-WS implementation specified!");
115             }
116         } else {
117             Object portProviderObj = null;
118 
119             try {
120                 portProviderObj = ClassLoaderUtil.loadClass(portProviderClass).newInstance();
121             } catch (Exception e) {
122                 throw new IllegalArgumentException("Could not load port provider: " + e, e);
123             }
124 
125             if (!(portProviderObj instanceof AbstractPortProvider)) {
126                 throw new IllegalArgumentException("Port provider does not implement AbstractPortProvider!");
127             }
128             portProvider = (AbstractPortProvider) portProviderObj;
129         }
130 
131         if (LOG.isDebugEnabled()) {
132             LOG.debug("Session {}: Port provider class: {}", session.getSessionId(), portProvider.getClass().getName());
133         }
134 
135         portProvider.setSession(session);
136 
137         repositoryService = new RepositoryServiceImpl(session, portProvider);
138         navigationService = new NavigationServiceImpl(session, portProvider);
139         objectService = new ObjectServiceImpl(session, portProvider);
140         versioningService = new VersioningServiceImpl(session, portProvider);
141         discoveryService = new DiscoveryServiceImpl(session, portProvider);
142         multiFilingService = new MultiFilingServiceImpl(session, portProvider);
143         relationshipService = new RelationshipServiceImpl(session, portProvider);
144         policyService = new PolicyServiceImpl(session, portProvider);
145         aclService = new AclServiceImpl(session, portProvider);
146     }
147 
148     @Override
149     public RepositoryService getRepositoryService() {
150         return repositoryService;
151     }
152 
153     @Override
154     public NavigationService getNavigationService() {
155         return navigationService;
156     }
157 
158     @Override
159     public ObjectService getObjectService() {
160         return objectService;
161     }
162 
163     @Override
164     public DiscoveryService getDiscoveryService() {
165         return discoveryService;
166     }
167 
168     @Override
169     public VersioningService getVersioningService() {
170         return versioningService;
171     }
172 
173     @Override
174     public MultiFilingService getMultiFilingService() {
175         return multiFilingService;
176     }
177 
178     @Override
179     public RelationshipService getRelationshipService() {
180         return relationshipService;
181     }
182 
183     @Override
184     public PolicyService getPolicyService() {
185         return policyService;
186     }
187 
188     @Override
189     public AclService getAclService() {
190         return aclService;
191     }
192 
193     @Override
194     public void clearAllCaches() {
195     }
196 
197     @Override
198     public void clearRepositoryCache(String repositoryId) {
199     }
200 
201     @Override
202     public void close() {
203         // no-op for Web Services
204     }
205 }