This project has retired. For details please refer to its Attic page.
Inquiry3to2.java

Inquiry3to2.java

  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. import java.rmi.RemoteException;
  18. import java.util.Map;
  19. import javax.xml.ws.Binding;
  20. import javax.xml.ws.BindingProvider;
  21. import javax.xml.ws.EndpointReference;
  22. import javax.xml.ws.soap.SOAPFaultException;
  23. import org.apache.commons.logging.Log;
  24. import org.apache.commons.logging.LogFactory;
  25. import org.apache.juddi.v3.client.UDDIServiceV2;
  26. import org.apache.juddi.v3.client.mapping.MapUDDIv2Tov3;
  27. import org.apache.juddi.v3.client.mapping.MapUDDIv3Tov2;
  28. import org.uddi.api_v3.BindingDetail;
  29. import org.uddi.api_v3.BusinessDetail;
  30. import org.uddi.api_v3.BusinessList;
  31. import org.uddi.api_v3.FindBinding;
  32. import org.uddi.api_v3.FindBusiness;
  33. import org.uddi.api_v3.FindRelatedBusinesses;
  34. import org.uddi.api_v3.FindService;
  35. import org.uddi.api_v3.FindTModel;
  36. import org.uddi.api_v3.GetBindingDetail;
  37. import org.uddi.api_v3.GetBusinessDetail;
  38. import org.uddi.api_v3.GetOperationalInfo;
  39. import org.uddi.api_v3.GetServiceDetail;
  40. import org.uddi.api_v3.GetTModelDetail;
  41. import org.uddi.api_v3.OperationalInfo;
  42. import org.uddi.api_v3.OperationalInfos;
  43. import org.uddi.api_v3.RelatedBusinessesList;
  44. import org.uddi.api_v3.ServiceDetail;
  45. import org.uddi.api_v3.ServiceList;
  46. import org.uddi.api_v3.TModelDetail;
  47. import org.uddi.api_v3.TModelList;
  48. import org.uddi.v2_service.DispositionReport;
  49. import org.uddi.v2_service.Inquire;
  50. import org.uddi.v3_service.DispositionReportFaultMessage;
  51. import org.uddi.v3_service.UDDIInquiryPortType;

  52. /**
  53.  * This class provides a wrapper to enable UDDIv3 clients to talk to UDDIv2 servers
  54.  * via JAXWS Transport. It handles all translations for Inquiry service methods.
  55.  * @author <a href="alexoree@apache.org">Alex O'Ree</a>
  56.  * @since 3.2
  57.  */
  58. public class Inquiry3to2 implements UDDIInquiryPortType, BindingProvider {

  59.         private static Log logger = LogFactory.getLog(Inquiry3to2.class);
  60.         Inquire inquiryService = null;

  61.         public Inquiry3to2() {

  62.                 UDDIServiceV2 service = new UDDIServiceV2();
  63.                 inquiryService = service.getInquire();

  64.         }
  65.        
  66.         public Inquire getUDDIv2WebServiceClient(){
  67.              return inquiryService;
  68.         }

  69.         @Override
  70.         public BindingDetail findBinding(FindBinding body) throws DispositionReportFaultMessage, RemoteException {
  71.                 try {
  72.                         return MapUDDIv2Tov3.MapBindingDetail(inquiryService.findBinding(MapUDDIv3Tov2.MapFindBinding(body)));
  73.                 } catch (DispositionReport ex) {
  74.                         throw MapUDDIv2Tov3.MapException(ex);
  75.                 } catch (SOAPFaultException ex) {
  76.                         throw MapUDDIv2Tov3.MapException(ex);
  77.                 }
  78.         }

  79.         @Override
  80.         public BusinessList findBusiness(FindBusiness body) throws DispositionReportFaultMessage, RemoteException {
  81.                 try {
  82.                         org.uddi.api_v2.FindBusiness MapFindBusiness = MapUDDIv3Tov2.MapFindBusiness(body);
  83.                         org.uddi.api_v2.BusinessList s = inquiryService.findBusiness(MapFindBusiness);
  84.                         return MapUDDIv2Tov3.MapBusinessList(s);
  85.                 } catch (DispositionReport ex) {
  86.                         throw MapUDDIv2Tov3.MapException(ex);
  87.                 } catch (SOAPFaultException ex) {
  88.                         throw MapUDDIv2Tov3.MapException(ex);
  89.                 }
  90.         }

  91.         @Override
  92.         public RelatedBusinessesList findRelatedBusinesses(FindRelatedBusinesses body) throws DispositionReportFaultMessage, RemoteException {
  93.                 try {
  94.                         return MapUDDIv2Tov3.MapRelatedBusinessesList(inquiryService.findRelatedBusinesses(MapUDDIv3Tov2.MapFindRelatedBusiness(body)));
  95.                 } catch (DispositionReport ex) {
  96.                         throw MapUDDIv2Tov3.MapException(ex);
  97.                 } catch (SOAPFaultException ex) {
  98.                         throw MapUDDIv2Tov3.MapException(ex);
  99.                 }
  100.         }

  101.         @Override
  102.         public ServiceList findService(FindService body) throws DispositionReportFaultMessage, RemoteException {
  103.                 try {
  104.                         return MapUDDIv2Tov3.MapServiceList(inquiryService.findService(MapUDDIv3Tov2.MapFindService(body)));
  105.                 } catch (DispositionReport ex) {
  106.                         throw MapUDDIv2Tov3.MapException(ex);
  107.                 } catch (SOAPFaultException ex) {
  108.                         throw MapUDDIv2Tov3.MapException(ex);
  109.                 }
  110.         }

  111.         @Override
  112.         public TModelList findTModel(FindTModel body) throws DispositionReportFaultMessage, RemoteException {
  113.                 try {
  114.                         return MapUDDIv2Tov3.MapTModelList(inquiryService.findTModel(MapUDDIv3Tov2.MapFindTModel(body)));
  115.                 } catch (DispositionReport ex) {
  116.                         throw MapUDDIv2Tov3.MapException(ex);
  117.                 } catch (SOAPFaultException ex) {
  118.                         throw MapUDDIv2Tov3.MapException(ex);
  119.                 }
  120.         }

  121.         @Override
  122.         public BindingDetail getBindingDetail(GetBindingDetail body) throws DispositionReportFaultMessage, RemoteException {
  123.                 try {
  124.                         return MapUDDIv2Tov3.MapBindingDetail(inquiryService.getBindingDetail(MapUDDIv3Tov2.MapGetBindingDetail(body)));
  125.                 } catch (DispositionReport ex) {
  126.                         throw MapUDDIv2Tov3.MapException(ex);
  127.                 } catch (SOAPFaultException ex) {
  128.                         throw MapUDDIv2Tov3.MapException(ex);
  129.                 }
  130.         }

  131.         @Override
  132.         public BusinessDetail getBusinessDetail(GetBusinessDetail body) throws DispositionReportFaultMessage, RemoteException {
  133.                 try {
  134.                         return MapUDDIv2Tov3.MapBusinessDetail(inquiryService.getBusinessDetail(MapUDDIv3Tov2.MapGetBusinessDetail(body)));
  135.                 } catch (DispositionReport ex) {
  136.                         throw MapUDDIv2Tov3.MapException(ex);
  137.                 } catch (SOAPFaultException ex) {
  138.                         throw MapUDDIv2Tov3.MapException(ex);
  139.                 }
  140.         }

  141.         public static final String VERSION = "2.0";

  142.         @Override
  143.         public OperationalInfos getOperationalInfo(GetOperationalInfo body) throws DispositionReportFaultMessage, RemoteException {
  144.                 OperationalInfos ret = new OperationalInfos();

  145.                 for (int i = 0; i < body.getEntityKey().size(); i++) {
  146.                         OperationalInfo oi = new OperationalInfo();
  147.                         oi.setEntityKey(body.getEntityKey().get(i));
  148.                         try {
  149.                                 org.uddi.api_v2.GetBusinessDetail businessDetail = new org.uddi.api_v2.GetBusinessDetail();
  150.                                 businessDetail.setGeneric(VERSION);
  151.                                 businessDetail.getBusinessKey().add(body.getEntityKey().get(i));
  152.                                 org.uddi.api_v2.BusinessDetail z = inquiryService.getBusinessDetail(businessDetail);
  153.                                 oi.setNodeID(z.getOperator());
  154.                                 oi.setAuthorizedName(z.getBusinessEntity().get(0).getAuthorizedName());
  155.                         } catch (Exception ex) {
  156.                                 logger.warn(ex.getMessage(), ex);
  157.                         }
  158.                         if (oi.getAuthorizedName() != null) {
  159.                                 continue;
  160.                         }
  161.                         try {
  162.                                 org.uddi.api_v2.GetTModelDetail tModelDetail = new org.uddi.api_v2.GetTModelDetail();
  163.                                 tModelDetail.setGeneric(VERSION);
  164.                                 tModelDetail.getTModelKey().add(body.getEntityKey().get(i));
  165.                                 org.uddi.api_v2.TModelDetail z = inquiryService.getTModelDetail(tModelDetail);
  166.                                 oi.setNodeID(z.getOperator());
  167.                                 oi.setAuthorizedName(z.getTModel().get(0).getAuthorizedName());
  168.                         } catch (Exception ex) {
  169.                                 logger.warn(ex.getMessage(), ex);
  170.                         }
  171.                         if (oi.getAuthorizedName() != null) {
  172.                                 continue;
  173.                         }
  174.                         try {
  175.                                 //get the service
  176.                                 org.uddi.api_v2.GetServiceDetail serviceDetail = new org.uddi.api_v2.GetServiceDetail();
  177.                                 serviceDetail.setGeneric(VERSION);
  178.                                 serviceDetail.getServiceKey().add(body.getEntityKey().get(i));
  179.                                 org.uddi.api_v2.ServiceDetail z = inquiryService.getServiceDetail(serviceDetail);
  180.                                 oi.setNodeID(z.getOperator());

  181.                                 org.uddi.api_v2.GetBusinessDetail businessDetail = new org.uddi.api_v2.GetBusinessDetail();
  182.                                 businessDetail.setGeneric(VERSION);
  183.                                 //its owning business
  184.                                 businessDetail.getBusinessKey().add(z.getBusinessService().get(0).getBusinessKey());
  185.                                 org.uddi.api_v2.BusinessDetail z2 = inquiryService.getBusinessDetail(businessDetail);
  186.                                 oi.setNodeID(z.getOperator());
  187.                                 oi.setAuthorizedName(z2.getBusinessEntity().get(0).getAuthorizedName());
  188.                         } catch (Exception ex) {
  189.                                 logger.warn(ex.getMessage(), ex);
  190.                         }
  191.                         ret.getOperationalInfo().add(oi);
  192.                         ret.setTruncated(false);
  193.                 }
  194.                 return ret;
  195.         }

  196.         @Override
  197.         public ServiceDetail getServiceDetail(GetServiceDetail body) throws DispositionReportFaultMessage, RemoteException {
  198.                 try {
  199.                         return MapUDDIv2Tov3.MapServiceDetail(inquiryService.getServiceDetail(MapUDDIv3Tov2.MapGetServiceDetail(body)));
  200.                 } catch (DispositionReport ex) {
  201.                         throw MapUDDIv2Tov3.MapException(ex);
  202.                 } catch (SOAPFaultException ex) {
  203.                         throw MapUDDIv2Tov3.MapException(ex);
  204.                 }
  205.         }

  206.         @Override
  207.         public TModelDetail getTModelDetail(GetTModelDetail body) throws DispositionReportFaultMessage, RemoteException {
  208.                 try {
  209.                         return MapUDDIv2Tov3.MapTModelDetail(inquiryService.getTModelDetail(MapUDDIv3Tov2.MapGetTModelDetail(body)));
  210.                 } catch (DispositionReport ex) {
  211.                         throw MapUDDIv2Tov3.MapException(ex);
  212.                 } catch (SOAPFaultException ex) {
  213.                         throw MapUDDIv2Tov3.MapException(ex);
  214.                 }
  215.         }

  216.         @Override
  217.         public Map<String, Object> getRequestContext() {
  218.                 return ((BindingProvider) inquiryService).getRequestContext();
  219.         }

  220.         @Override
  221.         public Map<String, Object> getResponseContext() {
  222.                 return ((BindingProvider) inquiryService).getResponseContext();
  223.         }

  224.         @Override
  225.         public Binding getBinding() {
  226.                 return ((BindingProvider) inquiryService).getBinding();
  227.         }

  228.         @Override
  229.         public EndpointReference getEndpointReference() {
  230.                 return ((BindingProvider) inquiryService).getEndpointReference();
  231.         }

  232.         @Override
  233.         public <T extends EndpointReference> T getEndpointReference(Class<T> clazz) {
  234.                 return ((BindingProvider) inquiryService).getEndpointReference(clazz);
  235.         }

  236. }