1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.client.runtime;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.Reader;
25 import java.net.URL;
26 import java.util.Map;
27
28 import org.apache.chemistry.opencmis.client.SessionParameterMap;
29 import org.apache.chemistry.opencmis.client.api.CmisEndpointDocumentReader;
30 import org.apache.chemistry.opencmis.commons.SessionParameter;
31 import org.apache.chemistry.opencmis.commons.endpoints.CmisAuthentication;
32 import org.apache.chemistry.opencmis.commons.endpoints.CmisEndpoint;
33 import org.apache.chemistry.opencmis.commons.endpoints.CmisEndpointsDocument;
34 import org.apache.chemistry.opencmis.commons.enums.BindingType;
35 import org.apache.chemistry.opencmis.commons.impl.endpoints.CmisEndpointsDocumentHelper;
36 import org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException;
37
38 public class CmisEndpointDocumentReaderImpl implements CmisEndpointDocumentReader {
39
40 @Override
41 public CmisEndpointsDocument read(URL url) throws IOException {
42 try {
43 return CmisEndpointsDocumentHelper.read(url);
44 } catch (JSONParseException e) {
45 throw new IllegalArgumentException("Not a CMIS Endpoint Document!", e);
46 }
47 }
48
49 @Override
50 public CmisEndpointsDocument read(File file) throws IOException {
51 try {
52 return CmisEndpointsDocumentHelper.read(file);
53 } catch (JSONParseException e) {
54 throw new IllegalArgumentException("Not a CMIS Endpoint Document!", e);
55 }
56 }
57
58 @Override
59 public CmisEndpointsDocument read(InputStream in) throws IOException {
60 try {
61 return CmisEndpointsDocumentHelper.read(in);
62 } catch (JSONParseException e) {
63 throw new IllegalArgumentException("Not a CMIS Endpoint Document!", e);
64 }
65 }
66
67 @Override
68 public CmisEndpointsDocument read(Reader in) throws IOException {
69 try {
70 return CmisEndpointsDocumentHelper.read(in);
71 } catch (JSONParseException e) {
72 throw new IllegalArgumentException("Not a CMIS Endpoint Document!", e);
73 }
74 }
75
76 @Override
77 public CmisEndpointsDocument read(String in) {
78 try {
79 return CmisEndpointsDocumentHelper.read(in);
80 } catch (JSONParseException e) {
81 throw new IllegalArgumentException("Not a CMIS Endpoint Document!", e);
82 }
83 }
84
85 @Override
86 public Map<String, String> pepareSessionParameters(CmisAuthentication authentication) {
87 if (authentication == null) {
88 throw new IllegalArgumentException("Authentication object must be provided!");
89 }
90 if (authentication.getEndpoint() == null) {
91 throw new IllegalArgumentException("Authentication object has no endpoint information!");
92 }
93
94 SessionParameterMap result = new SessionParameterMap();
95
96 CmisEndpoint endpoint = authentication.getEndpoint();
97
98
99 String binding = endpoint.getBinding();
100
101 if (CmisEndpoint.BINDING_ATOMPUB.equals(binding)) {
102 result.setAtomPubBindingUrl(endpoint.getUrl());
103 } else if (CmisEndpoint.BINDING_BROWSER.equals(binding)) {
104 result.setBrowserBindingUrl(endpoint.getUrl());
105 } else if (CmisEndpoint.BINDING_WEBSERVICES.equals(binding)) {
106 if (endpoint.getUrl() != null) {
107 result.setWebServicesBindingUrl(endpoint.getUrl());
108 } else {
109 result.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());
110 result.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, endpoint.getRepositoryServiceWdsl());
111 result.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, endpoint.getNavigationServiceWdsl());
112 result.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, endpoint.getObjectServiceWdsl());
113 result.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, endpoint.getVersioningServiceWdsl());
114 result.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, endpoint.getDiscoveryServiceWdsl());
115 result.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, endpoint.getMultifilingServiceWdsl());
116 result.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, endpoint.getRelationshipServiceWdsl());
117 result.put(SessionParameter.WEBSERVICES_ACL_SERVICE, endpoint.getAclServiceWdsl());
118 result.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, endpoint.getPolicyServiceWdsl());
119 }
120 }
121
122
123 if (CmisAuthentication.AUTH_NONE.equals(authentication.getType())) {
124 result.setNoAuthentication();
125 } else if (CmisAuthentication.AUTH_BASIC.equals(authentication.getType())) {
126 result.setBasicAuthentication();
127 } else if (CmisAuthentication.AUTH_USERNAME_TOKEN.equals(authentication.getType())) {
128 result.setUsernameTokenAuthentication(false);
129 } else if (CmisAuthentication.AUTH_OAUTH.equals(authentication.getType())) {
130 result.setOAuthAuthentication();
131 } else if (CmisAuthentication.AUTH_NTLM.equals(authentication.getType())) {
132 result.setNtlmAuthentication();
133 }
134
135
136 result.setCookies(authentication.requiresCookies()
137 || !CmisEndpoint.COOKIES_OPTIONAL.equals(endpoint.getCookies()));
138 result.setCompression(CmisEndpoint.COMPRESSION_SERVER.equals(endpoint.getCompression())
139 || CmisEndpoint.COMPRESSION_BOTH.equals(endpoint.getCompression()));
140 result.setClientCompression(CmisEndpoint.COMPRESSION_CLIENT.equals(endpoint.getCompression())
141 || CmisEndpoint.COMPRESSION_BOTH.equals(endpoint.getCompression()));
142 result.setCsrfHeader(endpoint.getCsrfHeader());
143
144 return result;
145 }
146 }