View Javadoc
1   /*
2    * Copyright 2014 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.v3.client.transport.wrapper;
17  
18  import java.rmi.RemoteException;
19  import java.util.Map;
20  import javax.xml.ws.Binding;
21  import javax.xml.ws.BindingProvider;
22  import javax.xml.ws.EndpointReference;
23  import javax.xml.ws.soap.SOAPFaultException;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.juddi.v3.client.UDDIServiceV2;
27  import org.apache.juddi.v3.client.mapping.MapUDDIv2Tov3;
28  import org.apache.juddi.v3.client.mapping.MapUDDIv3Tov2;
29  import org.uddi.api_v3.BindingDetail;
30  import org.uddi.api_v3.BusinessDetail;
31  import org.uddi.api_v3.BusinessList;
32  import org.uddi.api_v3.FindBinding;
33  import org.uddi.api_v3.FindBusiness;
34  import org.uddi.api_v3.FindRelatedBusinesses;
35  import org.uddi.api_v3.FindService;
36  import org.uddi.api_v3.FindTModel;
37  import org.uddi.api_v3.GetBindingDetail;
38  import org.uddi.api_v3.GetBusinessDetail;
39  import org.uddi.api_v3.GetOperationalInfo;
40  import org.uddi.api_v3.GetServiceDetail;
41  import org.uddi.api_v3.GetTModelDetail;
42  import org.uddi.api_v3.OperationalInfo;
43  import org.uddi.api_v3.OperationalInfos;
44  import org.uddi.api_v3.RelatedBusinessesList;
45  import org.uddi.api_v3.ServiceDetail;
46  import org.uddi.api_v3.ServiceList;
47  import org.uddi.api_v3.TModelDetail;
48  import org.uddi.api_v3.TModelList;
49  import org.uddi.v2_service.DispositionReport;
50  import org.uddi.v2_service.Inquire;
51  import org.uddi.v3_service.DispositionReportFaultMessage;
52  import org.uddi.v3_service.UDDIInquiryPortType;
53  
54  /**
55   * This class provides a wrapper to enable UDDIv3 clients to talk to UDDIv2 servers
56   * via JAXWS Transport. It handles all translations for Inquiry service methods.
57   * @author <a href="alexoree@apache.org">Alex O'Ree</a>
58   * @since 3.2
59   */
60  public class Inquiry3to2 implements UDDIInquiryPortType, BindingProvider {
61  
62          private static Log logger = LogFactory.getLog(Inquiry3to2.class);
63          Inquire inquiryService = null;
64  
65          public Inquiry3to2() {
66  
67                  UDDIServiceV2 service = new UDDIServiceV2();
68                  inquiryService = service.getInquire();
69  
70          }
71          
72          public Inquire getUDDIv2WebServiceClient(){
73               return inquiryService;
74          }
75  
76          @Override
77          public BindingDetail findBinding(FindBinding body) throws DispositionReportFaultMessage, RemoteException {
78                  try {
79                          return MapUDDIv2Tov3.MapBindingDetail(inquiryService.findBinding(MapUDDIv3Tov2.MapFindBinding(body)));
80                  } catch (DispositionReport ex) {
81                          throw MapUDDIv2Tov3.MapException(ex);
82                  } catch (SOAPFaultException ex) {
83                          throw MapUDDIv2Tov3.MapException(ex);
84                  }
85          }
86  
87          @Override
88          public BusinessList findBusiness(FindBusiness body) throws DispositionReportFaultMessage, RemoteException {
89                  try {
90                          org.uddi.api_v2.FindBusiness MapFindBusiness = MapUDDIv3Tov2.MapFindBusiness(body);
91                          org.uddi.api_v2.BusinessList s = inquiryService.findBusiness(MapFindBusiness);
92                          return MapUDDIv2Tov3.MapBusinessList(s);
93                  } catch (DispositionReport ex) {
94                          throw MapUDDIv2Tov3.MapException(ex);
95                  } catch (SOAPFaultException ex) {
96                          throw MapUDDIv2Tov3.MapException(ex);
97                  }
98          }
99  
100         @Override
101         public RelatedBusinessesList findRelatedBusinesses(FindRelatedBusinesses body) throws DispositionReportFaultMessage, RemoteException {
102                 try {
103                         return MapUDDIv2Tov3.MapRelatedBusinessesList(inquiryService.findRelatedBusinesses(MapUDDIv3Tov2.MapFindRelatedBusiness(body)));
104                 } catch (DispositionReport ex) {
105                         throw MapUDDIv2Tov3.MapException(ex);
106                 } catch (SOAPFaultException ex) {
107                         throw MapUDDIv2Tov3.MapException(ex);
108                 }
109         }
110 
111         @Override
112         public ServiceList findService(FindService body) throws DispositionReportFaultMessage, RemoteException {
113                 try {
114                         return MapUDDIv2Tov3.MapServiceList(inquiryService.findService(MapUDDIv3Tov2.MapFindService(body)));
115                 } catch (DispositionReport ex) {
116                         throw MapUDDIv2Tov3.MapException(ex);
117                 } catch (SOAPFaultException ex) {
118                         throw MapUDDIv2Tov3.MapException(ex);
119                 }
120         }
121 
122         @Override
123         public TModelList findTModel(FindTModel body) throws DispositionReportFaultMessage, RemoteException {
124                 try {
125                         return MapUDDIv2Tov3.MapTModelList(inquiryService.findTModel(MapUDDIv3Tov2.MapFindTModel(body)));
126                 } catch (DispositionReport ex) {
127                         throw MapUDDIv2Tov3.MapException(ex);
128                 } catch (SOAPFaultException ex) {
129                         throw MapUDDIv2Tov3.MapException(ex);
130                 }
131         }
132 
133         @Override
134         public BindingDetail getBindingDetail(GetBindingDetail body) throws DispositionReportFaultMessage, RemoteException {
135                 try {
136                         return MapUDDIv2Tov3.MapBindingDetail(inquiryService.getBindingDetail(MapUDDIv3Tov2.MapGetBindingDetail(body)));
137                 } catch (DispositionReport ex) {
138                         throw MapUDDIv2Tov3.MapException(ex);
139                 } catch (SOAPFaultException ex) {
140                         throw MapUDDIv2Tov3.MapException(ex);
141                 }
142         }
143 
144         @Override
145         public BusinessDetail getBusinessDetail(GetBusinessDetail body) throws DispositionReportFaultMessage, RemoteException {
146                 try {
147                         return MapUDDIv2Tov3.MapBusinessDetail(inquiryService.getBusinessDetail(MapUDDIv3Tov2.MapGetBusinessDetail(body)));
148                 } catch (DispositionReport ex) {
149                         throw MapUDDIv2Tov3.MapException(ex);
150                 } catch (SOAPFaultException ex) {
151                         throw MapUDDIv2Tov3.MapException(ex);
152                 }
153         }
154 
155         public static final String VERSION = "2.0";
156 
157         @Override
158         public OperationalInfos getOperationalInfo(GetOperationalInfo body) throws DispositionReportFaultMessage, RemoteException {
159                 OperationalInfos ret = new OperationalInfos();
160 
161                 for (int i = 0; i < body.getEntityKey().size(); i++) {
162                         OperationalInfo oi = new OperationalInfo();
163                         oi.setEntityKey(body.getEntityKey().get(i));
164                         try {
165                                 org.uddi.api_v2.GetBusinessDetail businessDetail = new org.uddi.api_v2.GetBusinessDetail();
166                                 businessDetail.setGeneric(VERSION);
167                                 businessDetail.getBusinessKey().add(body.getEntityKey().get(i));
168                                 org.uddi.api_v2.BusinessDetail z = inquiryService.getBusinessDetail(businessDetail);
169                                 oi.setNodeID(z.getOperator());
170                                 oi.setAuthorizedName(z.getBusinessEntity().get(0).getAuthorizedName());
171                         } catch (Exception ex) {
172                                 logger.warn(ex.getMessage(), ex);
173                         }
174                         if (oi.getAuthorizedName() != null) {
175                                 continue;
176                         }
177                         try {
178                                 org.uddi.api_v2.GetTModelDetail tModelDetail = new org.uddi.api_v2.GetTModelDetail();
179                                 tModelDetail.setGeneric(VERSION);
180                                 tModelDetail.getTModelKey().add(body.getEntityKey().get(i));
181                                 org.uddi.api_v2.TModelDetail z = inquiryService.getTModelDetail(tModelDetail);
182                                 oi.setNodeID(z.getOperator());
183                                 oi.setAuthorizedName(z.getTModel().get(0).getAuthorizedName());
184                         } catch (Exception ex) {
185                                 logger.warn(ex.getMessage(), ex);
186                         }
187                         if (oi.getAuthorizedName() != null) {
188                                 continue;
189                         }
190                         try {
191                                 //get the service
192                                 org.uddi.api_v2.GetServiceDetail serviceDetail = new org.uddi.api_v2.GetServiceDetail();
193                                 serviceDetail.setGeneric(VERSION);
194                                 serviceDetail.getServiceKey().add(body.getEntityKey().get(i));
195                                 org.uddi.api_v2.ServiceDetail z = inquiryService.getServiceDetail(serviceDetail);
196                                 oi.setNodeID(z.getOperator());
197 
198                                 org.uddi.api_v2.GetBusinessDetail businessDetail = new org.uddi.api_v2.GetBusinessDetail();
199                                 businessDetail.setGeneric(VERSION);
200                                 //its owning business
201                                 businessDetail.getBusinessKey().add(z.getBusinessService().get(0).getBusinessKey());
202                                 org.uddi.api_v2.BusinessDetail z2 = inquiryService.getBusinessDetail(businessDetail);
203                                 oi.setNodeID(z.getOperator());
204                                 oi.setAuthorizedName(z2.getBusinessEntity().get(0).getAuthorizedName());
205                         } catch (Exception ex) {
206                                 logger.warn(ex.getMessage(), ex);
207                         }
208                         ret.getOperationalInfo().add(oi);
209                         ret.setTruncated(false);
210                 }
211                 return ret;
212         }
213 
214         @Override
215         public ServiceDetail getServiceDetail(GetServiceDetail body) throws DispositionReportFaultMessage, RemoteException {
216                 try {
217                         return MapUDDIv2Tov3.MapServiceDetail(inquiryService.getServiceDetail(MapUDDIv3Tov2.MapGetServiceDetail(body)));
218                 } catch (DispositionReport ex) {
219                         throw MapUDDIv2Tov3.MapException(ex);
220                 } catch (SOAPFaultException ex) {
221                         throw MapUDDIv2Tov3.MapException(ex);
222                 }
223         }
224 
225         @Override
226         public TModelDetail getTModelDetail(GetTModelDetail body) throws DispositionReportFaultMessage, RemoteException {
227                 try {
228                         return MapUDDIv2Tov3.MapTModelDetail(inquiryService.getTModelDetail(MapUDDIv3Tov2.MapGetTModelDetail(body)));
229                 } catch (DispositionReport ex) {
230                         throw MapUDDIv2Tov3.MapException(ex);
231                 } catch (SOAPFaultException ex) {
232                         throw MapUDDIv2Tov3.MapException(ex);
233                 }
234         }
235 
236         @Override
237         public Map<String, Object> getRequestContext() {
238                 return ((BindingProvider) inquiryService).getRequestContext();
239         }
240 
241         @Override
242         public Map<String, Object> getResponseContext() {
243                 return ((BindingProvider) inquiryService).getResponseContext();
244         }
245 
246         @Override
247         public Binding getBinding() {
248                 return ((BindingProvider) inquiryService).getBinding();
249         }
250 
251         @Override
252         public EndpointReference getEndpointReference() {
253                 return ((BindingProvider) inquiryService).getEndpointReference();
254         }
255 
256         @Override
257         public <T extends EndpointReference> T getEndpointReference(Class<T> clazz) {
258                 return ((BindingProvider) inquiryService).getEndpointReference(clazz);
259         }
260 
261 }