Пример #1
0
  @Override
  public String deploySynapseArtifact(
      OMElement artifactConfig, String fileName, Properties properties) {

    if (log.isDebugEnabled()) {
      log.debug("Endpoint Deployment from file : " + fileName + " : Started");
    }

    CustomLogSetter.getInstance().setLogAppender(customLogContent);

    try {
      Endpoint ep = EndpointFactory.getEndpointFromElement(artifactConfig, false, properties);

      // Set the car name
      ep.setArtifactContainerName(customLogContent);
      if (ep != null) {
        ep.setFileName((new File(fileName)).getName());
        if (log.isDebugEnabled()) {
          log.debug(
              "Endpoint named '" + ep.getName() + "' has been built from the file " + fileName);
        }
        ep.init(getSynapseEnvironment());
        if (log.isDebugEnabled()) {
          log.debug("Initialized the endpoint : " + ep.getName());
        }
        getSynapseConfiguration().addEndpoint(ep.getName(), ep);
        if (log.isDebugEnabled()) {
          log.debug("Endpoint Deployment from file : " + fileName + " : Completed");
        }
        log.info("Endpoint named '" + ep.getName() + "' has been deployed from file : " + fileName);
        return ep.getName();
      } else {
        handleSynapseArtifactDeploymentError(
            "Endpoint Deployment Failed. The artifact "
                + "described in the file "
                + fileName
                + " is not an Endpoint");
      }
    } catch (Exception e) {
      handleSynapseArtifactDeploymentError(
          "Endpoint Deployment from the file : " + fileName + " : Failed.", e);
    }

    return null;
  }
Пример #2
0
  /**
   * This static method will be used to build the Target from the specified element
   *
   * @param elem - OMElement describing the xml configuration of the target
   * @return Target built by parsing the given element
   */
  public static Target createTarget(OMElement elem) {

    if (!TARGET_Q.equals(elem.getQName())) {
      handleException("Element does not match with the target QName");
    }

    Target target = new Target();
    OMAttribute toAttr = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "to"));
    if (toAttr != null && toAttr.getAttributeValue() != null) {
      target.setToAddress(toAttr.getAttributeValue());
    }

    OMAttribute soapAction =
        elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "soapAction"));
    if (soapAction != null && soapAction.getAttributeValue() != null) {
      target.setSoapAction(soapAction.getAttributeValue());
    }

    OMAttribute sequenceAttr =
        elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "sequence"));
    if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
      target.setSequenceRef(sequenceAttr.getAttributeValue());
    }

    OMAttribute endpointAttr =
        elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "endpoint"));
    if (endpointAttr != null && endpointAttr.getAttributeValue() != null) {
      target.setEndpointRef(endpointAttr.getAttributeValue());
    }

    OMElement sequence =
        elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "sequence"));
    if (sequence != null) {
      SequenceMediatorFactory fac = new SequenceMediatorFactory();
      target.setSequence(fac.createAnonymousSequence(sequence));
    }

    OMElement endpoint =
        elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "endpoint"));
    if (endpoint != null) {
      target.setEndpoint(EndpointFactory.getEndpointFromElement(endpoint, true));
    }

    return target;
  }
Пример #3
0
  /**
   * Helper method to construct children endpoints
   *
   * @param listEndpointElement OMElement representing the children endpoints
   * @param parent Parent endpoint
   * @param properties bag of properties to pass in any information to the factory
   * @return List of children endpoints
   */
  protected ArrayList<Endpoint> getEndpoints(
      OMElement listEndpointElement, Endpoint parent, Properties properties) {

    ArrayList<Endpoint> endpoints = new ArrayList<Endpoint>();
    ArrayList<String> keys = new ArrayList<String>();
    Iterator iter = listEndpointElement.getChildrenWithName(XMLConfigConstants.ENDPOINT_ELT);
    while (iter.hasNext()) {
      OMElement endptElem = (OMElement) iter.next();
      Endpoint endpoint = EndpointFactory.getEndpointFromElement(endptElem, true, properties);
      if (endpoint instanceof IndirectEndpoint) {
        String key = ((IndirectEndpoint) endpoint).getKey();
        if (!keys.contains(key)) {
          keys.add(key);
        } else {
          handleException("Same endpoint definition cannot be used with in the siblings");
        }
      }
      endpoint.setParentEndpoint(parent);
      endpoints.add(endpoint);
    }

    return endpoints;
  }
Пример #4
0
  @Override
  public String updateSynapseArtifact(
      OMElement artifactConfig,
      String fileName,
      String existingArtifactName,
      Properties properties) {

    Endpoint ep = EndpointFactory.getEndpointFromElement(artifactConfig, false, properties);

    CustomLogSetter.getInstance().setLogAppender((ep != null) ? ep.getArtifactContainerName() : "");

    if (log.isDebugEnabled()) {
      log.debug("Endpoint update from file : " + fileName + " has started");
    }

    try {
      if (ep == null) {
        handleSynapseArtifactDeploymentError(
            "Endpoint update failed. The artifact "
                + "defined in the file: "
                + fileName
                + " is not a valid endpoint.");
        return null;
      }
      ep.setFileName(new File(fileName).getName());

      if (log.isDebugEnabled()) {
        log.debug("Endpoint: " + ep.getName() + " has been built from the file: " + fileName);
      }

      ep.init(getSynapseEnvironment());
      Endpoint existingEp =
          getSynapseConfiguration().getDefinedEndpoints().get(existingArtifactName);
      if (existingArtifactName.equals(ep.getName())) {
        getSynapseConfiguration().updateEndpoint(existingArtifactName, ep);
      } else {
        // The user has changed the name of the endpoint
        // We should add the updated endpoint as a new endpoint and remove the old one
        getSynapseConfiguration().addEndpoint(ep.getName(), ep);
        getSynapseConfiguration().removeEndpoint(existingArtifactName);
        log.info("Endpoint: " + existingArtifactName + " has been undeployed");
      }

      log.info("Endpoint: " + ep.getName() + " has been updated from the file: " + fileName);

      waitForCompletion();
      existingEp.destroy();
      if (existingArtifactName.equals(ep.getName())) {
        // If the endpoint name was same as the old one, above method call (destroy)
        // will unregister the endpoint MBean - So we should register it again.
        MBeanRegistrar.getInstance().registerMBean(ep.getMetricsMBean(), "Endpoint", ep.getName());
      }
      return ep.getName();

    } catch (DeploymentException e) {
      handleSynapseArtifactDeploymentError(
          "Error while updating the endpoint from the " + "file: " + fileName);
    }

    return null;
  }
Пример #5
0
 /**
  * Core method which is exposed for the external use, and this will find the proper {@link
  * EndpointFactory} and create the endpoint which is of the format {@link Endpoint}.However
  * definition for this endpoint will be built using a custom Endpoint Defn factory.
  *
  * @param elem XML from which the endpoint will be built
  * @param factory custom definition factory which this endpoint will be used to build
  * @param isAnonymous whether this is an anonymous endpoint or not
  * @param properties bag of properties to pass in any information to the factory
  * @return created endpoint
  */
 public static Endpoint getEndpointFromElement(
     OMElement elem, DefinitionFactory factory, boolean isAnonymous, Properties properties) {
   EndpointFactory fac = getEndpointFactory(elem);
   fac.setEndpointDefinitionFactory(factory);
   return fac.createEndpointWithName(elem, isAnonymous, properties);
 }