Example #1
0
  public BusinessService readServiceAnnotations(String classWithAnnotations, Properties properties)
      throws ClassNotFoundException {

    BusinessService service = new BusinessService();
    Class<?> clazz = ClassUtil.forName(classWithAnnotations, this.getClass());
    UDDIService uddiService = (UDDIService) clazz.getAnnotation(UDDIService.class);
    WebService webServiceAnnotation = (WebService) clazz.getAnnotation(WebService.class);

    if (uddiService != null) {
      // service
      String lang = "en"; // default to english
      if (uddiService.lang() != null) {
        lang = uddiService.lang();
      }
      Name name = new Name();
      name.setLang(lang);
      service.setBusinessKey(TokenResolver.replaceTokens(uddiService.businessKey(), properties));
      service.setServiceKey(TokenResolver.replaceTokens(uddiService.serviceKey(), properties));
      if (!"".equals(uddiService.serviceName())) {
        name.setValue(TokenResolver.replaceTokens(uddiService.serviceName(), properties));
      } else if (webServiceAnnotation != null && !"".equals(webServiceAnnotation.serviceName())) {
        name.setValue(webServiceAnnotation.serviceName());
      } else {
        name.setValue(clazz.getSimpleName());
      }
      service.getName().add(name);
      Description description = new Description();
      description.setLang(lang);
      description.setValue(TokenResolver.replaceTokens(uddiService.description(), properties));
      service.getDescription().add(description);

      // categoryBag on the service
      if (!"".equals(uddiService.categoryBag())) {
        CategoryBag categoryBag = parseCategoryBag(uddiService.categoryBag());
        service.setCategoryBag(categoryBag);
      }

      // bindingTemplate on service
      BindingTemplate bindingTemplate =
          parseServiceBinding(clazz, lang, webServiceAnnotation, properties);
      if (bindingTemplate != null) {
        bindingTemplate.setServiceKey(service.getServiceKey());
        if (service.getBindingTemplates() == null) {
          service.setBindingTemplates(new BindingTemplates());
        }
        service.getBindingTemplates().getBindingTemplate().add(bindingTemplate);
      }

    } else {
      log.error("Missing UDDIService annotation in class " + classWithAnnotations);
    }

    return service;
  }
  @Test()
  public void JUDDI_712_SaveService2WithSignature() throws CertificateException {
    Assume.assumeTrue(TckPublisher.isEnabled());
    SaveBusiness sb = new SaveBusiness();
    sb.setAuthInfo(authInfoJoe);
    BusinessEntity be = new BusinessEntity();
    Name n = new Name();
    n.setValue("JUDDI_712_SaveService2WithSignature");
    be.getName().add(n);
    be.setBusinessKey(TckBusiness.JOE_BUSINESS_KEY);
    sb.getBusinessEntity().add(be);
    BusinessDetail saveBusiness = null;
    try {

      saveBusiness = publicationJoe.saveBusiness(sb);
    } catch (Exception ex) {
      logger.info("UnExpected failure: ", ex);
      Assert.fail();
    }

    SaveService ss = new SaveService();
    ss.setAuthInfo(authInfoJoe);
    BusinessService bs = new BusinessService();
    bs.setBusinessKey(TckBusiness.JOE_BUSINESS_KEY);
    bs.setServiceKey(TckBusinessService.JOE_SERVICE_KEY);
    bs.setBindingTemplates(new BindingTemplates());
    BindingTemplate bt = new BindingTemplate();
    bt.setBindingKey(null);
    bt.setServiceKey(TckBusinessService.JOE_SERVICE_KEY);
    bt.setAccessPoint(new AccessPoint("http://localhost", "wsdl"));
    bs.getBindingTemplates().getBindingTemplate().add(bt);
    bs.getName().add(new Name("Joe's bs", null));
    DigSigUtil ds = GetDigSig();
    bs = ds.signUddiEntity(bs);

    be.setBusinessServices(new BusinessServices());
    be.getBusinessServices().getBusinessService().add(bs);

    sb.getBusinessEntity().add(be);
    try {
      publicationJoe.saveService(ss);
      Assert.fail("unexpected success");
    } catch (Exception ex) {
      logger.info("Expected failure: " + ex.getMessage());
    } finally {
      DeleteBusinesses(
          saveBusiness.getBusinessEntity().get(0).getBusinessKey(), authInfoJoe, publicationJoe);
    }
  }
Example #3
0
  protected BindingTemplate parseServiceBinding(
      Class<?> classWithAnnotations,
      String lang,
      WebService webServiceAnnotation,
      Properties properties) {

    BindingTemplate bindingTemplate = null;
    UDDIServiceBinding uddiServiceBinding =
        (UDDIServiceBinding) classWithAnnotations.getAnnotation(UDDIServiceBinding.class);
    // binding
    if (uddiServiceBinding != null) {
      bindingTemplate = new BindingTemplate();

      bindingTemplate.setBindingKey(
          TokenResolver.replaceTokens(uddiServiceBinding.bindingKey(), properties));

      String bindingLang = String.valueOf(lang);
      if (uddiServiceBinding.lang() != null) {
        bindingLang = TokenResolver.replaceTokens(uddiServiceBinding.lang(), properties);
      }
      Description bindingDescription = new Description();
      bindingDescription.setLang(bindingLang);
      bindingDescription.setValue(
          TokenResolver.replaceTokens(uddiServiceBinding.description(), properties));
      bindingTemplate.getDescription().add(bindingDescription);

      AccessPoint accessPoint = new AccessPoint();
      accessPoint.setUseType(AccessPointType.WSDL_DEPLOYMENT.toString());
      if (!"".equals(uddiServiceBinding.accessPointType())) {
        accessPoint.setUseType(uddiServiceBinding.accessPointType());
      }
      if (!"".equals(uddiServiceBinding.accessPoint())) {
        String endPoint = uddiServiceBinding.accessPoint();
        endPoint = TokenResolver.replaceTokens(endPoint, properties);
        log.debug("AccessPoint EndPoint=" + endPoint);
        accessPoint.setValue(endPoint);
      } else if (webServiceAnnotation != null && webServiceAnnotation.wsdlLocation() != null) {
        accessPoint.setValue(webServiceAnnotation.wsdlLocation());
      }
      bindingTemplate.setAccessPoint(accessPoint);

      // tModelKeys on the binding
      if (!"".equals(uddiServiceBinding.tModelKeys())) {
        String[] tModelKeys = uddiServiceBinding.tModelKeys().split(",");
        for (String tModelKey : tModelKeys) {
          TModelInstanceInfo instanceInfo = new TModelInstanceInfo();
          instanceInfo.setTModelKey(tModelKey);
          if (bindingTemplate.getTModelInstanceDetails() == null) {
            bindingTemplate.setTModelInstanceDetails(new TModelInstanceDetails());
          }
          bindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().add(instanceInfo);
        }
      }
      // categoryBag on the binding
      if (!"".equals(uddiServiceBinding.categoryBag())) {
        CategoryBag categoryBag = parseCategoryBag(uddiServiceBinding.categoryBag());
        bindingTemplate.setCategoryBag(categoryBag);
      }
    } else {
      log.error("Missing UDDIServiceBinding annotation in class " + classWithAnnotations);
    }
    return bindingTemplate;
  }
  /**
   * This method retrieves the service information from the UDDI server for each of the business
   * entities.
   *
   * @param oEntities The business entities for which services should be retrieved. The information
   *     is placed in the appropriate location in this object.
   * @throws UDDIAccessorException
   */
  private void retrieveDetailedServiceInfoFromUDDI(CMBusinessEntities oEntities)
      throws UDDIAccessorException {
    if ((oEntities == null)
        || (oEntities.getBusinessEntity() == null)
        || (oEntities.getBusinessEntity().size() <= 0)) {
      return; // we are done  there is nothing to retrieve.
    }

    ServiceDetail oResult = null;

    try {
      GetServiceDetail oSearchParams = new GetServiceDetail();

      // Load up the list of service keys to retrieve the details of...
      // --------------------------------------------------------
      for (CMBusinessEntity oEntity : oEntities.getBusinessEntity()) {
        if ((oEntity.getBusinessServices() != null)
            && (oEntity.getBusinessServices().getBusinessService() != null)
            && (oEntity.getBusinessServices().getBusinessService().size() > 0)) {
          for (CMBusinessService oService : oEntity.getBusinessServices().getBusinessService()) {
            if ((oService.getServiceKey() != null) && (oService.getServiceKey().length() > 0)) {
              oSearchParams.getServiceKey().add(oService.getServiceKey());
            }
          } // for (CMBusinessService oService : oEntity.getBusinessServices().getBusinessService())
        } // if ((oEntity.getBusinessServices() != null) && ...
      } // for (CMBusinessEntity oEntity : oEntities.getBusinessEntity())

      UDDIInquiryPortType oPort = getUDDIInquiryWebService();
      oResult = oPort.getServiceDetail(oSearchParams);
    } catch (Exception e) {
      String sErrorMessage =
          "Failed to call UDDI web service get_serviceDetail method.  Error: " + e.getMessage();
      log.error(sErrorMessage, e);
      throw new UDDIAccessorException(sErrorMessage, e);
    }

    // Now let's process the results...
    // ---------------------------------
    if ((oResult != null)
        && (oResult.getBusinessService() != null)
        && (oResult.getBusinessService().size() > 0)) {
      // Now put the returned information back into our structure.
      // -----------------------------------------------------------
      for (BusinessService oUDDIService : oResult.getBusinessService()) {
        if ((oUDDIService.getServiceKey() != null)
            && (oUDDIService.getServiceKey().length() > 0)
            && (oUDDIService.getBusinessKey() != null)
            && (oUDDIService.getBusinessKey().length() > 0)) {
          CMBusinessService oService =
              findSpecificService(
                  oEntities.getBusinessEntity(),
                  oUDDIService.getBusinessKey(),
                  oUDDIService.getServiceKey());

          if (oService != null) {
            // Binding Service Name
            // ----------------------
            if ((oUDDIService.getName() != null) && (oUDDIService.getName().size() > 0)) {
              CMBindingNames oNames = new CMBindingNames();
              oService.setNames(oNames);

              for (Name oUDDIName : oUDDIService.getName()) {
                if ((oUDDIName.getValue() != null) && (oUDDIName.getValue().length() > 0)) {
                  oService.getNames().getName().add(oUDDIName.getValue());
                }
              }
            } // if ((oUDDIService.getName() != null) &&

            // Binding Descriptions
            // ---------------------
            if ((oUDDIService.getDescription() != null)
                && (oUDDIService.getDescription().size() > 0)) {
              CMBindingDescriptions oDescripts = new CMBindingDescriptions();
              oService.setDescriptions(oDescripts);

              for (Description oUDDIDescript : oUDDIService.getDescription()) {
                if ((oUDDIDescript.getValue() != null) && (oUDDIDescript.getValue().length() > 0)) {
                  oService.getDescriptions().getDescription().add(oUDDIDescript.getValue());
                }
              }
            } // if ((oUDDIService.getDescription() != null) && ...

            // Binding Template Information
            // -----------------------------
            if ((oUDDIService.getBindingTemplates() != null)
                && (oUDDIService.getBindingTemplates().getBindingTemplate() != null)
                && (oUDDIService.getBindingTemplates().getBindingTemplate().size() > 0)) {
              CMBindingTemplates oTemplates = new CMBindingTemplates();
              for (BindingTemplate oUDDITemplate :
                  oUDDIService.getBindingTemplates().getBindingTemplate()) {
                CMBindingTemplate oTemplate = new CMBindingTemplate();
                boolean bHaveData = false;

                // Endpoint URL
                // --------------
                if ((oUDDITemplate.getAccessPoint() != null)
                    && (oUDDITemplate.getAccessPoint().getValue() != null)
                    && (oUDDITemplate.getAccessPoint().getValue().length() > 0)) {
                  oTemplate.setEndpointURL(oUDDITemplate.getAccessPoint().getValue());
                  bHaveData = true;
                }

                // Service Version
                // ---------------
                if ((oUDDITemplate.getCategoryBag() != null)
                    && (oUDDITemplate.getCategoryBag().getKeyedReference() != null)
                    && (oUDDITemplate.getCategoryBag().getKeyedReference().size() > 0)) {

                  List<String> oServiceVersions =
                      findAndGetValueFromKeyedReference(
                          oUDDITemplate.getCategoryBag().getKeyedReference(), SERVICE_VERSION_KEY);
                  if (oServiceVersions != null && oServiceVersions.size() == 1) {
                    for (String sValue : oServiceVersions) {
                      if ((sValue != null) && (sValue.length() > 0)) {
                        oTemplate.setServiceVersion(sValue);
                        bHaveData = true;
                      }
                    }
                  } else {
                    log.debug(
                        "A single Service Version is NOT detected for UDDI Service "
                            + oUDDIService.getBusinessKey()
                            + " - "
                            + oUDDIService.getServiceKey());
                  }
                }
                if (bHaveData) {
                  oTemplates.getBindingTemplate().add(oTemplate);
                }
              }

              if ((oTemplates.getBindingTemplate() != null)
                  && (oTemplates.getBindingTemplate().size() > 0)) {
                oService.setBindingTemplates(oTemplates);
              }
            }

            // Uniform Service Name
            //
            // Multiple Uniform Service Names will result in the
            // creation of oService copies so this should be the last
            // population to be performed.
            // ----------------------------------------
            populateUniformServiceNameAndReplicateService(oUDDIService, oEntities, oService);
          } // if (oService != null)
        } // if ((oUDDIService.getServiceKey() != null) &&  ...
      } // for (BusinessService oUDDIService : oResult.getBusinessService())
    } // if ((oResult != null) &&
  }