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