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.webservices;
20  
21  import java.util.HashMap;
22  import java.util.Locale;
23  import java.util.Map;
24  
25  import org.apache.chemistry.opencmis.client.bindings.CmisBindingFactory;
26  import org.apache.chemistry.opencmis.commons.SessionParameter;
27  import org.apache.chemistry.opencmis.commons.spi.CmisBinding;
28  
29  /**
30   * Web Services Binding Factory.
31   */
32  public class WebServicesTestBindingFactory {
33  
34      private WebServicesTestBindingFactory() {
35      }
36  
37      public static CmisBinding createBinding(String url, String username, String password) {
38          boolean isPrefix = true;
39  
40          url = url.trim();
41          String urlLower = url.toLowerCase(Locale.ENGLISH);
42  
43          if (urlLower.endsWith("?wsdl")) {
44              isPrefix = false;
45          } else if (urlLower.endsWith(".wsdl")) {
46              isPrefix = false;
47          } else if (urlLower.endsWith(".xml")) {
48              isPrefix = false;
49          } else if (urlLower.endsWith(".aspx")) {
50              isPrefix = false;
51          } else if (urlLower.endsWith("/wsdl")) {
52              isPrefix = false;
53          }
54  
55          return createBinding(url, isPrefix, username, password);
56      }
57  
58      public static CmisBinding createBinding(String url, boolean isPrefix, String username, String password) {
59          // gather parameters
60          Map<String, String> parameters = new HashMap<String, String>();
61          parameters.put(SessionParameter.USER, username);
62          parameters.put(SessionParameter.PASSWORD, password);
63  
64          if (!isPrefix) {
65              parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, url);
66              parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, url);
67              parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, url);
68              parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, url);
69              parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, url);
70              parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, url);
71              parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, url);
72              parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, url);
73              parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE, url);
74          } else {
75              parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, url + "RepositoryService?wsdl");
76              parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, url + "NavigationService?wsdl");
77              parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, url + "ObjectService?wsdl");
78              parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, url + "VersioningService?wsdl");
79              parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, url + "DiscoveryService?wsdl");
80              parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, url + "RelationshipService?wsdl");
81              parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, url + "MultiFilingService?wsdl");
82              parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, url + "PolicyService?wsdl");
83              parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE, url + "ACLService?wsdl");
84          }
85  
86          // get factory and create provider
87          CmisBindingFactory factory = CmisBindingFactory.newInstance();
88          CmisBinding binding = factory.createCmisWebServicesBinding(parameters);
89  
90          return binding;
91      }
92  }