This project has retired. For details please refer to its
Attic page.
JAXWSv2TranslationTransport xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juddi.v3.client.transport;
18
19 import java.util.Map;
20 import java.util.Properties;
21
22 import javax.xml.ws.BindingProvider;
23
24 import org.apache.commons.configuration.ConfigurationException;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.juddi.v3.client.config.Property;
28 import org.apache.juddi.v3.client.config.UDDIClient;
29 import org.apache.juddi.v3.client.config.UDDIClientContainer;
30 import org.apache.juddi.v3.client.cryptor.CryptorFactory;
31 import org.apache.juddi.v3.client.transport.wrapper.Inquiry3to2;
32 import org.apache.juddi.v3.client.transport.wrapper.Publish3to2;
33 import org.apache.juddi.v3.client.transport.wrapper.Security3to2;
34 import org.uddi.v2_service.Inquire;
35 import org.uddi.v2_service.Publish;
36 import org.uddi.v3_service.UDDIInquiryPortType;
37 import org.uddi.v3_service.UDDIPublicationPortType;
38 import org.uddi.v3_service.UDDISecurityPortType;
39
40
41
42
43
44
45
46
47 public class JAXWSv2TranslationTransport extends JAXWSTransport {
48
49 private static Log logger = LogFactory.getLog(JAXWSv2TranslationTransport.class);
50
51 Inquiry3to2 inquiryv2 = null;
52 Security3to2 securityv2 = null;
53 Publish3to2 publishv2 = null;
54
55 public JAXWSv2TranslationTransport() {
56 super();
57 this.nodeName = Transport.DEFAULT_NODE_NAME;
58 }
59
60 public JAXWSv2TranslationTransport(String nodeName) {
61 super();
62 this.nodeName = nodeName;
63 }
64
65 public JAXWSv2TranslationTransport(String clientName, String nodeName) {
66 super();
67 this.clientName = clientName;
68 this.nodeName = nodeName;
69 }
70
71 public String getNodeName() {
72 return nodeName;
73 }
74
75 public void setNodeName(String nodeName) {
76 this.nodeName = nodeName;
77 }
78
79
80
81
82
83
84
85
86
87 private void setCredentials(Map<String, Object> requestContext) throws ConfigurationException {
88 UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
89 Properties properties = client.getClientConfig().getUDDINode(nodeName).getProperties();
90 if (properties != null) {
91 String username = null;
92 String password = null;
93 if (properties.containsKey(Property.BASIC_AUTH_USERNAME)) {
94 username = properties.getProperty(Property.BASIC_AUTH_USERNAME);
95 }
96 if (properties.containsKey(Property.BASIC_AUTH_PASSWORD)) {
97 password = properties.getProperty(Property.BASIC_AUTH_PASSWORD);
98 }
99 String cipher = null;
100 boolean isEncrypted = false;
101 if (properties.containsKey(Property.BASIC_AUTH_PASSWORD_CP)) {
102 cipher = properties.getProperty(Property.BASIC_AUTH_PASSWORD_CP);
103 }
104 if (properties.containsKey(Property.BASIC_AUTH_PASSWORD_IS_ENC)) {
105 isEncrypted = Boolean.parseBoolean(properties.getProperty(Property.BASIC_AUTH_PASSWORD_IS_ENC));
106 }
107 if (username != null && password != null) {
108 requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
109 if (isEncrypted) {
110 try {
111 requestContext.put(BindingProvider.PASSWORD_PROPERTY, CryptorFactory.getCryptor(cipher).decrypt(password));
112 } catch (Exception ex) {
113 logger.error("Unable to decrypt password!", ex);
114 }
115 } else {
116 requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
117 }
118 }
119 }
120 }
121
122 @Override
123 public UDDIInquiryPortType getUDDIInquiryService(String endpointURL) throws TransportException {
124 try {
125 if (inquiryv2 == null) {
126 inquiryv2 = new Inquiry3to2();
127
128 }
129 if (endpointURL == null) {
130 UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
131 endpointURL = client.getClientConfig().getUDDINode(nodeName).getInquiryUrl();
132 }
133 Map<String, Object> requestContext = ((BindingProvider) inquiryv2).getRequestContext();
134 requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
135 setCredentials(requestContext);
136 } catch (Exception e) {
137 throw new TransportException(e.getMessage(), e);
138 }
139 return inquiryv2;
140
141 }
142
143 @Override
144 public UDDISecurityPortType getUDDISecurityService(String endpointURL) throws TransportException {
145 try {
146 if (securityv2 == null) {
147 securityv2 = new Security3to2();
148
149 }
150
151 if (endpointURL == null) {
152
153 UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
154 endpointURL = client.getClientConfig().getUDDINode(nodeName).getPublishUrl();
155 }
156 if (endpointURL.toLowerCase().startsWith("http:")){
157 logger.warn("You should consider using a secure protocol (https) when sending your password!");
158 }
159 Map<String, Object> requestContext = ((BindingProvider) securityv2).getRequestContext();
160 requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
161 setCredentials(requestContext);
162 } catch (Exception e) {
163 throw new TransportException(e.getMessage(), e);
164 }
165 return securityv2;
166
167 }
168
169 @Override
170 public UDDIPublicationPortType getUDDIPublishService(String endpointURL) throws TransportException {
171 try {
172 if (publishv2 == null) {
173 publishv2 = new Publish3to2();
174
175 }
176 if (endpointURL == null) {
177 UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
178 endpointURL = client.getClientConfig().getUDDINode(nodeName).getPublishUrl();
179 }
180
181 Map<String, Object> requestContext = ((BindingProvider) publishv2).getRequestContext();
182 requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
183 setCredentials(requestContext);
184 } catch (Exception e) {
185 throw new TransportException(e.getMessage(), e);
186 }
187 return publishv2;
188 }
189
190
191
192
193
194
195 public Inquire getUDDIv2InquiryService() throws TransportException {
196 return getUDDIv2InquiryService(null);
197 }
198 public Inquire getUDDIv2InquiryService(String endpointURL) throws TransportException {
199 try {
200 if (inquiryv2 == null) {
201 inquiryv2 = new Inquiry3to2();
202
203 }
204 if (endpointURL == null) {
205 UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
206 endpointURL = client.getClientConfig().getUDDINode(nodeName).getInquiryUrl();
207 }
208 Map<String, Object> requestContext = ((BindingProvider) inquiryv2).getRequestContext();
209 requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
210 setCredentials(requestContext);
211 } catch (Exception e) {
212 throw new TransportException(e.getMessage(), e);
213 }
214 return inquiryv2.getUDDIv2WebServiceClient();
215
216 }
217
218
219
220 public Publish getUDDIv2PublishService(String endpointURL) throws TransportException {
221 try {
222 if (publishv2 == null) {
223 publishv2 = new Publish3to2();
224
225 }
226 if (endpointURL == null) {
227 UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
228 endpointURL = client.getClientConfig().getUDDINode(nodeName).getPublishUrl();
229 }
230
231 Map<String, Object> requestContext = ((BindingProvider) publishv2).getRequestContext();
232 requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
233 setCredentials(requestContext);
234 } catch (Exception e) {
235 throw new TransportException(e.getMessage(), e);
236 }
237 return publishv2.getUDDIv2PublishWebServiceClient();
238 }
239
240 public Publish getUDDIv2PublishService() throws TransportException {
241 return getUDDIv2PublishService(null);
242 }
243 }