This project has retired. For details please refer to its Attic page.
UDDIv2InquiryImpl xref
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.api.impl;
17  
18  import java.util.ArrayList;
19  import java.util.HashSet;
20  import java.util.List;
21  import java.util.Set;
22  
23  import javax.jws.WebService;
24  
25  import org.apache.commons.configuration.ConfigurationException;
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  import org.apache.juddi.config.AppConfig;
29  import org.apache.juddi.config.Property;
30  import org.apache.juddi.v3.client.mapping.MapUDDIv2Tov3;
31  import org.apache.juddi.v3.client.mapping.MapUDDIv3Tov2;
32  import org.apache.juddi.validation.ValidateUDDIv2Inquiry;
33  import org.uddi.api_v2.BindingDetail;
34  import org.uddi.api_v2.BusinessDetail;
35  import org.uddi.api_v2.BusinessDetailExt;
36  import org.uddi.api_v2.BusinessList;
37  import org.uddi.api_v2.FindBinding;
38  import org.uddi.api_v2.FindBusiness;
39  import org.uddi.api_v2.FindRelatedBusinesses;
40  import org.uddi.api_v2.FindService;
41  import org.uddi.api_v2.FindTModel;
42  import org.uddi.api_v2.GetBindingDetail;
43  import org.uddi.api_v2.GetBusinessDetail;
44  import org.uddi.api_v2.GetBusinessDetailExt;
45  import org.uddi.api_v2.GetServiceDetail;
46  import org.uddi.api_v2.GetTModelDetail;
47  import org.uddi.api_v2.RelatedBusinessesList;
48  import org.uddi.api_v2.ServiceDetail;
49  import org.uddi.api_v2.ServiceList;
50  import org.uddi.api_v2.TModelDetail;
51  import org.uddi.api_v2.TModelList;
52  import org.uddi.v2_service.DispositionReport;
53  import org.uddi.v2_service.Inquire;
54  import org.uddi.v3_service.DispositionReportFaultMessage;
55  
56  /**
57   * UDDI v2 Implementation for the Inquiry service. This implementation is
58   * basically a wrapper and API translator that translates and forwards the
59   * request to our UDDIv3 Inquiry implementation.<br><br>
60   * This class is a BETA feature and is largely untested. Please report any
61   * issues
62   *
63   * @author <a href="mailto:alexoree.apache.org">Alex O'Ree</a>
64   * @since 3.2
65   */
66  @WebService(serviceName = "Inquire", targetNamespace = "urn:uddi-org:inquiry_v2",
67          endpointInterface = "org.uddi.v2_service.Inquire")
68  public class UDDIv2InquiryImpl implements Inquire {
69  
70          private static Log logger = LogFactory.getLog(UDDIv2InquiryImpl.class);
71          static UDDIInquiryImpl inquiryService = new UDDIInquiryImpl();
72  
73          public UDDIv2InquiryImpl() {
74                  logger.warn("This implementation of UDDIv2 Inquire service " + UDDIv2InquiryImpl.class.getCanonicalName() + " is considered BETA. Please"
75                          + " report any issues to https://issues.apache.org/jira/browse/JUDDI");
76          }
77  
78          static String nodeId=null;
79          public static String getNodeID(){
80                   try {
81                           nodeId=AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID);
82                   } catch (ConfigurationException ex) {
83                           logger.warn(ex.getMessage());
84                           nodeId="JUDDI_v3";
85                   }
86                   return nodeId;
87          }
88          
89          @Override
90          public BindingDetail findBinding(FindBinding body) throws DispositionReport {
91                  ValidateUDDIv2Inquiry.validateFindBinding(body);
92                  try {
93                          return MapUDDIv3Tov2.MapBindingDetail(inquiryService.findBinding(MapUDDIv2Tov3.MapFindBinding(body)), getNodeID());
94                  } catch (DispositionReportFaultMessage ex) {
95                          throw MapUDDIv3Tov2.MapException(ex, getNodeID());
96                  }
97          }
98  
99          @Override
100         public BusinessList findBusiness(FindBusiness body) throws DispositionReport {
101                 ValidateUDDIv2Inquiry.validateFindBusiness(body);
102                 try {
103                         return MapUDDIv3Tov2.MapBusinessListEntity(inquiryService.findBusiness(MapUDDIv2Tov3.MapFindBusiness(body)), getNodeID());
104                 } catch (DispositionReportFaultMessage ex) {
105                         throw MapUDDIv3Tov2.MapException(ex, getNodeID());
106                 }
107 
108         }
109 
110         @Override
111         public RelatedBusinessesList findRelatedBusinesses(FindRelatedBusinesses body) throws DispositionReport {
112                 ValidateUDDIv2Inquiry.validateFindRelatedBusinesses(body);
113                 try {
114                         return MapUDDIv3Tov2.MapRelatedBusinessList(inquiryService.findRelatedBusinesses(MapUDDIv2Tov3.MapFindRelatedBusiness(body)), getNodeID());
115                 } catch (DispositionReportFaultMessage ex) {
116                         throw MapUDDIv3Tov2.MapException(ex, getNodeID());
117                 }
118         }
119 
120         @Override
121         public ServiceList findService(FindService body) throws DispositionReport {
122                 ValidateUDDIv2Inquiry.validateFindService(body);
123                 try {
124                         return MapUDDIv3Tov2.MapServiceList(inquiryService.findService(MapUDDIv2Tov3.MapFindService(body)), getNodeID());
125                 } catch (DispositionReportFaultMessage ex) {
126                         throw MapUDDIv3Tov2.MapException(ex, getNodeID());
127                 }
128         }
129 
130         @Override
131         public TModelList findTModel(FindTModel body) throws DispositionReport {
132                 ValidateUDDIv2Inquiry.validateFindTModel(body);
133                 try {
134                         return MapUDDIv3Tov2.MapTModelListElement(inquiryService.findTModel(MapUDDIv2Tov3.MapFindTModel(body)), getNodeID());
135                 } catch (DispositionReportFaultMessage ex) {
136                         throw MapUDDIv3Tov2.MapException(ex, getNodeID());
137                 }
138         }
139 
140         @Override
141         public BindingDetail getBindingDetail(GetBindingDetail body) throws DispositionReport {
142                 ValidateUDDIv2Inquiry.validateGetBindingDetail(body);
143                 try {
144                         return MapUDDIv3Tov2.MapBindingDetail(inquiryService.getBindingDetail(MapUDDIv2Tov3.MapGetBindingDetail(body)), getNodeID());
145                 } catch (DispositionReportFaultMessage ex) {
146                         throw MapUDDIv3Tov2.MapException(ex, getNodeID());
147                 }
148         }
149 
150         @Override
151         public BusinessDetail getBusinessDetail(GetBusinessDetail body) throws DispositionReport {
152                 ValidateUDDIv2Inquiry.validateGetBusinessDetail(body);
153                 try {
154                         BusinessDetail MapBusinessDetail = MapUDDIv3Tov2.MapBusinessDetail(inquiryService.getBusinessDetail(MapUDDIv2Tov3.MapGetBusinessDetail(body)), getNodeID());
155                        // StringWriter sw = new StringWriter();
156                        // JAXB.marshal(MapBusinessDetail, sw);
157                       //  logger.info(sw.toString());
158                         return MapBusinessDetail;
159                 } catch (DispositionReportFaultMessage ex) {
160                         throw MapUDDIv3Tov2.MapException(ex, getNodeID());
161                 }
162         }
163 
164         @Override
165         public BusinessDetailExt getBusinessDetailExt(GetBusinessDetailExt body) throws DispositionReport {
166                 ValidateUDDIv2Inquiry.validateBusinessDetailExt(body);
167                 try {
168                         return MapUDDIv3Tov2.MapBusinessDetailExt(inquiryService.getBusinessDetail(MapUDDIv2Tov3.MapGetBusinessDetailExt(body)), getNodeID());
169                 } catch (DispositionReportFaultMessage ex) {
170                         throw MapUDDIv3Tov2.MapException(ex, getNodeID());
171                 }
172         }
173 
174         @Override
175         public ServiceDetail getServiceDetail(GetServiceDetail body) throws DispositionReport {
176                 ValidateUDDIv2Inquiry.validateGetServiceDetail(body);
177                 try {
178                         return MapUDDIv3Tov2.MapServiceDetail(inquiryService.getServiceDetail(MapUDDIv2Tov3.MapGetServiceDetail(body)), getNodeID());
179                 } catch (DispositionReportFaultMessage ex) {
180                         throw MapUDDIv3Tov2.MapException(ex, getNodeID());
181                 }
182         }
183 
184         @Override
185         public TModelDetail getTModelDetail(GetTModelDetail body) throws DispositionReport {
186                 ValidateUDDIv2Inquiry.validateGetTModelDetail(body);
187                 try {
188                 	//remove duplicates using a set
189                 	Set<String> keyList = new HashSet(body.getTModelKey());
190                 	body.getTModelKey().clear();
191                 	body.getTModelKey().addAll(keyList);
192                         return MapUDDIv3Tov2.MapTModelDetail(inquiryService.getTModelDetail(MapUDDIv2Tov3.MapGetTModelDetail(body)), getNodeID());
193                 } catch (DispositionReportFaultMessage ex) {
194                         throw MapUDDIv3Tov2.MapException(ex, getNodeID());
195                 }
196         }
197 
198 }