/**
   * Save endpoint properties
   *
   * @param model
   * @param endpoint
   */
  protected void saveProperties(EndPoint model, AbstractEndpoint endpoint) {
    for (Iterator<EndPointProperty> iterator = model.getProperties().iterator();
        iterator.hasNext(); ) {
      EndPointProperty property = iterator.next();
      MediatorProperty mediatorProperty = new MediatorProperty();
      mediatorProperty.setName(property.getName());

      if (property.getValueType().toString().equals("EXPRESSION")) {
        SynapseXPath XPath = null;
        try {
          XPath = new SynapseXPath(property.getValueExpression().getPropertyValue());
          for (int i = 0; i < property.getValueExpression().getNamespaces().keySet().size(); ++i) {
            String prefix =
                (String) property.getValueExpression().getNamespaces().keySet().toArray()[i];
            String namespaceUri = property.getValueExpression().getNamespaces().get(prefix);
            XPath.addNamespace(prefix, namespaceUri);
            mediatorProperty.setExpression(XPath);
          }
        } catch (JaxenException e) {
          log.error("Error while persisting Endpoint properties", e);
        }
      } else if (property.getValueType().toString().equals("LITERAL")) {
        mediatorProperty.setValue(property.getValue());
      }

      mediatorProperty.setScope(property.getScope().toString().toLowerCase());
      endpoint.addProperty(mediatorProperty);
    }
  }
 protected NamespacedProperty createNamespacedProperty(SynapseXPath xpath) {
   NamespacedProperty nsp = EsbFactory.eINSTANCE.createNamespacedProperty();
   nsp.setPropertyValue(xpath.toString());
   if (xpath.getNamespaces() != null) {
     @SuppressWarnings("unchecked")
     Map<String, String> map = xpath.getNamespaces();
     nsp.setNamespaces(map);
   }
   return nsp;
 }
  public ResolvingEndpoint getEndpointFromXpath(NamespacedProperty nameSpacedProperty)
      throws Exception {

    SynapseXPath synapseXPath = new SynapseXPath(nameSpacedProperty.getPropertyValue());
    for (int i = 0; i < nameSpacedProperty.getNamespaces().keySet().size(); ++i) {
      String prefix = (String) nameSpacedProperty.getNamespaces().keySet().toArray()[i];
      String namespaceUri = nameSpacedProperty.getNamespaces().get(prefix);
      synapseXPath.addNamespace(prefix, namespaceUri);
    }
    ResolvingEndpoint resolvingEndpoint = new ResolvingEndpoint();
    resolvingEndpoint.setKeyExpression(synapseXPath);
    return resolvingEndpoint;
  }
  private void setFaultReason(
      MessageContext synCtx, SOAPFactory factory, SOAPFault fault, int soapVersion) {
    String reasonString = null;

    if (faultReasonValue == null && faultReasonExpr == null) {
      handleException("A valid fault reason value or expression is required", synCtx);
    } else if (faultReasonValue != null) {
      reasonString = faultReasonValue;
    } else {
      reasonString = faultReasonExpr.stringValueOf(synCtx);
    }

    SOAPFaultReason reason = factory.createSOAPFaultReason();
    switch (soapVersion) {
      case SOAP11:
        reason.setText(reasonString);
        break;
      case SOAP12:
        SOAPFaultText text = factory.createSOAPFaultText();
        text.setText(reasonString);
        text.setLang("en");
        reason.addSOAPText(text);
        break;
    }
    fault.setReason(reason);
  }
  private void setFaultCode(
      MessageContext synCtx, SOAPFactory factory, SOAPFault fault, int soapVersion) {

    QName fault_code = null;

    if (faultCodeValue == null && faultCodeExpr == null) {
      handleException("A valid fault code QName value or expression is required", synCtx);
    } else if (faultCodeValue != null) {
      fault_code = faultCodeValue;
    } else {
      String codeStr = faultCodeExpr.stringValueOf(synCtx);
      fault_code = new QName(fault.getNamespace().getNamespaceURI(), codeStr);
    }

    SOAPFaultCode code = factory.createSOAPFaultCode();
    switch (soapVersion) {
      case SOAP11:
        code.setText(fault_code);
        break;
      case SOAP12:
        SOAPFaultValue value = factory.createSOAPFaultValue(code);
        value.setText(fault_code);
        break;
    }
    fault.setCode(code);
  }
Esempio n. 6
0
 private Object getResultValue(MessageContext synCtx) {
   if (value != null) {
     return value;
   } else if (valueElement != null) {
     return valueElement;
   } else {
     return convertValue(expression.stringValueOf(synCtx), type);
   }
 }
 private void setFaultDetail(MessageContext synCtx, SOAPFactory factory, SOAPFault fault) {
   if (faultDetail != null) {
     SOAPFaultDetail soapFaultDetail = factory.createSOAPFaultDetail();
     soapFaultDetail.setText(faultDetail);
     fault.setDetail(soapFaultDetail);
   } else if (faultDetailExpr != null) {
     SOAPFaultDetail soapFaultDetail = factory.createSOAPFaultDetail();
     Object result = null;
     try {
       result = faultDetailExpr.evaluate(synCtx);
     } catch (JaxenException e) {
       handleException(
           "Evaluation of the XPath expression " + this.toString() + " resulted in an error", e);
     }
     if (result instanceof List) {
       List list = (List) result;
       for (Object obj : list) {
         if (obj instanceof OMNode) {
           soapFaultDetail.addChild((OMNode) obj);
         }
       }
     } else {
       soapFaultDetail.setText(faultDetailExpr.stringValueOf(synCtx));
     }
     fault.setDetail(soapFaultDetail);
   } else if (!faultDetailElements.isEmpty()) {
     SOAPFaultDetail soapFaultDetail = factory.createSOAPFaultDetail();
     for (OMElement faultDetailElement : faultDetailElements) {
       soapFaultDetail.addChild(faultDetailElement.cloneOMElement());
     }
     fault.setDetail(soapFaultDetail);
   } else if (fault.getDetail() != null) {
     // work around for a rampart issue in the following thread
     // http://www.nabble.com/Access-to-validation-error-message-tf4498668.html#a13284520
     fault.getDetail().detach();
   }
 }
 public AggregateMediator() {
   try {
     aggregationExpression =
         new SynapseXPath(
             "/s11:Envelope/s11:Body/child::*[position()=1] | "
                 + "/s12:Envelope/s12:Body/child::*[position()=1]");
     aggregationExpression.addNamespace("s11", SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
     aggregationExpression.addNamespace("s12", SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
   } catch (JaxenException e) {
     if (log.isDebugEnabled()) {
       handleException(
           "Unable to set the default " + "aggregationExpression for the aggregation", e, null);
     }
   }
 }
Esempio n. 9
0
  /** @param synCtx */
  public void evaluate(MessageContext synCtx) {
    String result;
    if (value != null) {
      result = value;
    } else if (expression != null) {
      result = expression.stringValueOf(synCtx);
    } else {
      throw new SynapseException("A value or expression must be specified");
    }

    if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
      synCtx.setProperty(name, result);
    } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)) {
      // Setting property into the  Axis2 Message Context
      Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
      org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
      axis2MessageCtx.setProperty(name, result);
    } else if (XMLConfigConstants.SCOPE_CLIENT.equals(scope)) {
      // Setting property into the  Axis2 Message Context client options
      Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
      org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
      axis2MessageCtx.getOptions().setProperty(name, result);
    } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)) {
      // Setting Transport Headers
      Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
      org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
      Object headers =
          axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);

      if (headers != null && headers instanceof Map) {
        Map headersMap = (Map) headers;
        headersMap.put(name, result);
      }
      if (headers == null) {
        Map headersMap = new HashMap();
        headersMap.put(name, result);
        axis2MessageCtx.setProperty(
            org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap);
      }
    }
  }
  private org.apache.synapse.mediators.builtin.ValidateMediator createValidateMediator(
      EsbNode subject, TransformationInfo information) throws TransformerException, JaxenException {

    /*
     * Check subject.
     */
    Assert.isTrue(subject instanceof ValidateMediator, "Invalid subject.");
    ValidateMediator visualValidateMediator = (ValidateMediator) subject;
    /*
     * Configure Validate mediator.
     */

    org.apache.synapse.mediators.builtin.ValidateMediator validateMediator =
        new org.apache.synapse.mediators.builtin.ValidateMediator();
    setCommonProperties(validateMediator, visualValidateMediator);

    NamespacedProperty sourceXPath = visualValidateMediator.getSourceXpath();
    if (sourceXPath.getPropertyValue() != null && !sourceXPath.getPropertyValue().equals("")) {
      SynapseXPath synapseXPath = new SynapseXPath(sourceXPath.getPropertyValue());
      for (Entry<String, String> entry : sourceXPath.getNamespaces().entrySet()) {
        synapseXPath.addNamespace(entry.getKey(), entry.getValue());
      }
      validateMediator.setSource(synapseXPath);
    }

    List<Value> valueList = new ArrayList<Value>();
    for (ValidateSchema schema : visualValidateMediator.getSchemas()) {

      if (schema.getValidateSchemaKeyType().getLiteral().equals(KeyType.STATIC.getLiteral())) {

        if (schema.getValidateStaticSchemaKey() != null
            && schema.getValidateStaticSchemaKey().getKeyValue() != null) {
          Value val = new Value(schema.getValidateStaticSchemaKey().getKeyValue());
          valueList.add(val);
        }

      } else {

        NamespacedProperty dynamicSchemaKey = schema.getValidateDynamicSchemaKey();
        if (dynamicSchemaKey != null && dynamicSchemaKey.getPropertyValue() != null) {
          SynapseXPath xpath = new SynapseXPath(dynamicSchemaKey.getPropertyValue());
          for (Entry<String, String> entry : dynamicSchemaKey.getNamespaces().entrySet()) {
            xpath.addNamespace(entry.getKey(), entry.getValue());
          }
          Value val = new Value(xpath);
          valueList.add(val);
        }
      }
    }
    validateMediator.setSchemaKeys(valueList);

    // ListMediator onFailMediatorList = new AnonymousListMediator();
    SequenceMediator onFailMediatorList = new SequenceMediator();
    TransformationInfo newOnFailInfo = new TransformationInfo();
    newOnFailInfo.setTraversalDirection(information.getTraversalDirection());
    newOnFailInfo.setSynapseConfiguration(information.getSynapseConfiguration());
    newOnFailInfo.setOriginInSequence(information.getOriginInSequence());
    newOnFailInfo.setOriginOutSequence(information.getOriginOutSequence());
    newOnFailInfo.setCurrentProxy(information.getCurrentProxy());
    newOnFailInfo.setParentSequence(onFailMediatorList);
    doTransform(newOnFailInfo, visualValidateMediator.getOnFailOutputConnector());
    validateMediator.addAll(onFailMediatorList.getList());

    for (ValidateFeature feature : visualValidateMediator.getFeatures()) {
      try {
        validateMediator.addFeature(feature.getFeatureName(), feature.isFeatureEnabled());
      } catch (Exception e) {
        log.error(e);
      }
    }

    if (!visualValidateMediator.getResources().isEmpty()) {

      ResourceMap rMap = new ResourceMap();

      for (ValidateResource resource : visualValidateMediator.getResources()) {

        if (resource.getLocation() != null && resource.getKey() != null) {

          rMap.addResource(resource.getLocation(), resource.getKey().getKeyValue());
        }
      }

      validateMediator.setResourceMap(rMap);
    }

    return validateMediator;
  }
Esempio n. 11
0
  /**
   * Get the aggregated message from the specified Aggregate instance
   *
   * @param aggregate the Aggregate object that holds collected messages and properties of the
   *     aggregation
   * @return the aggregated message context
   */
  private MessageContext getAggregatedMessage(Aggregate aggregate) {

    MessageContext newCtx = null;
    StatisticsRecord destinationStatRecord = null;

    for (MessageContext synCtx : aggregate.getMessages()) {

      if (newCtx == null) {
        try {
          newCtx = MessageHelper.cloneMessageContextForAggregateMediator(synCtx);
          destinationStatRecord =
              (StatisticsRecord) newCtx.getProperty(SynapseConstants.STATISTICS_STACK);
        } catch (AxisFault axisFault) {
          handleException("Error creating a copy of the message", axisFault, synCtx);
        }

        if (log.isDebugEnabled()) {
          log.debug("Generating Aggregated message from : " + newCtx.getEnvelope());
        }

      } else {
        try {
          if (log.isDebugEnabled()) {
            log.debug(
                "Merging message : "
                    + synCtx.getEnvelope()
                    + " using XPath : "
                    + aggregationExpression);
          }

          EIPUtils.enrichEnvelope(
              newCtx.getEnvelope(), synCtx.getEnvelope(), synCtx, aggregationExpression);
          if (destinationStatRecord != null
              && synCtx.getProperty(SynapseConstants.STATISTICS_STACK) != null) {
            // Merge the statistics logs to one single message
            // context.
            mergeStatisticsRecords(
                (StatisticsRecord) synCtx.getProperty(SynapseConstants.STATISTICS_STACK),
                destinationStatRecord);
          }

          if (log.isDebugEnabled()) {
            log.debug("Merged result : " + newCtx.getEnvelope());
          }

        } catch (JaxenException e) {
          handleException(
              "Error merging aggregation results using XPath : " + aggregationExpression.toString(),
              e,
              synCtx);
        } catch (SynapseException e) {
          handleException(
              "Error evaluating expression: " + aggregationExpression.toString(), e, synCtx);
        }
      }
    }

    // Enclose with a parent element if EnclosingElement is defined
    if (enclosingElementPropertyName != null) {

      if (log.isDebugEnabled()) {
        log.debug(
            "Enclosing the aggregated message with enclosing element: "
                + enclosingElementPropertyName);
      }

      Object enclosingElementProperty = newCtx.getProperty(enclosingElementPropertyName);

      if (enclosingElementProperty != null) {
        if (enclosingElementProperty instanceof OMElement) {
          OMElement enclosingElement = ((OMElement) enclosingElementProperty).cloneOMElement();
          EIPUtils.encloseWithElement(newCtx.getEnvelope(), enclosingElement);

          return newCtx;

        } else {
          handleException(
              "Enclosing Element defined in the property: "
                  + enclosingElementPropertyName
                  + " is not an OMElement ",
              newCtx);
        }
      } else {
        handleException(
            "Enclosing Element property: " + enclosingElementPropertyName + " not found ", newCtx);
      }
    }

    if (MessageFlowTracingDataCollector.isMessageFlowTracingEnabled()) {
      List<String> newMessageFlowTrace = new ArrayList<String>();
      for (MessageContext synCtx : aggregate.getMessages()) {
        List<String> messageFlowTrace =
            (List<String>) synCtx.getProperty(MessageFlowTracerConstants.MESSAGE_FLOW);
        if (null != messageFlowTrace) {
          newMessageFlowTrace.addAll(messageFlowTrace);
        }
      }
      newCtx.setProperty(MessageFlowTracerConstants.MESSAGE_FLOW, newMessageFlowTrace);
    }

    return newCtx;
  }
Esempio n. 12
0
  /**
   * Invoked by the Aggregate objects that are timed out, to signal timeout/completion of itself
   *
   * @param aggregate the timed out Aggregate that holds collected messages and properties
   */
  public boolean completeAggregate(Aggregate aggregate) {

    boolean markedCompletedNow = false;
    boolean wasComplete = aggregate.isCompleted();
    if (wasComplete) {
      return false;
    }

    if (log.isDebugEnabled()) {
      log.debug("Aggregation completed or timed out");
    }

    // cancel the timer
    synchronized (this) {
      if (!aggregate.isCompleted()) {
        aggregate.cancel();
        aggregate.setCompleted(true);
        markedCompletedNow = true;
      }
    }

    if (!markedCompletedNow) {
      return false;
    }

    MessageContext newSynCtx = getAggregatedMessage(aggregate);

    if (newSynCtx == null) {
      log.warn("An aggregation of messages timed out with no aggregated messages", null);
      return false;
    } else {
      // Get the aggregated message to the next mediator placed after the aggregate mediator
      // in the sequence
      if (newSynCtx.isContinuationEnabled()) {
        try {
          aggregate
              .getLastMessage()
              .setEnvelope(MessageHelper.cloneSOAPEnvelope(newSynCtx.getEnvelope()));
        } catch (AxisFault axisFault) {
          log.warn(
              "Error occurred while assigning aggregated message"
                  + " back to the last received message context");
        }
      }
    }

    aggregate.clear();
    activeAggregates.remove(aggregate.getCorrelation());

    if ((correlateExpression != null
            && !correlateExpression.toString().equals(aggregate.getCorrelation()))
        || correlateExpression == null) {

      if (onCompleteSequence != null) {

        ContinuationStackManager.addReliantContinuationState(newSynCtx, 0, getMediatorPosition());
        boolean result = onCompleteSequence.mediate(newSynCtx);
        if (result) {
          ContinuationStackManager.removeReliantContinuationState(newSynCtx);
        }
        return result;

      } else if (onCompleteSequenceRef != null
          && newSynCtx.getSequence(onCompleteSequenceRef) != null) {

        ContinuationStackManager.updateSeqContinuationState(newSynCtx, getMediatorPosition());
        return newSynCtx.getSequence(onCompleteSequenceRef).mediate(newSynCtx);

      } else {
        handleException(
            "Unable to find the sequence for the mediation " + "of the aggregated message",
            newSynCtx);
      }
    }
    return false;
  }
Esempio n. 13
0
  /**
   * Aggregate messages flowing through this mediator according to the correlation criteria and the
   * aggregation algorithm specified to it
   *
   * @param synCtx - MessageContext to be mediated and aggregated
   * @return boolean true if the complete condition for the particular aggregate is validated
   */
  public boolean mediate(MessageContext synCtx) {

    if (synCtx.getEnvironment().isDebugEnabled()) {
      if (super.divertMediationRoute(synCtx)) {
        return true;
      }
    }

    SynapseLog synLog = getLog(synCtx);

    if (synLog.isTraceOrDebugEnabled()) {
      synLog.traceOrDebug("Start : Aggregate mediator");

      if (synLog.isTraceTraceEnabled()) {
        synLog.traceTrace("Message : " + synCtx.getEnvelope());
      }
    }

    try {
      Aggregate aggregate = null;
      String correlationIdName =
          (id != null
              ? EIPConstants.AGGREGATE_CORRELATION + "." + id
              : EIPConstants.AGGREGATE_CORRELATION);
      // if a correlateExpression is provided and there is a coresponding
      // element in the current message prepare to correlate the messages on that
      Object result = null;
      if (correlateExpression != null) {
        result = correlateExpression.evaluate(synCtx);
        if (result instanceof List) {
          if (((List) result).isEmpty()) {
            handleException(
                "Failed to evaluate correlate expression: " + correlateExpression.toString(),
                synCtx);
          }
        }
      }
      if (result != null) {

        while (aggregate == null) {

          synchronized (lock) {
            if (activeAggregates.containsKey(correlateExpression.toString())) {

              aggregate = activeAggregates.get(correlateExpression.toString());
              if (aggregate != null) {
                if (!aggregate.getLock()) {
                  aggregate = null;
                }
              }

            } else {

              if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug(
                    "Creating new Aggregator - "
                        + (completionTimeoutMillis > 0
                            ? "expires in : " + (completionTimeoutMillis / 1000) + "secs"
                            : "without expiry time"));
              }

              Double minMsg = Double.parseDouble(minMessagesToComplete.evaluateValue(synCtx));
              Double maxMsg = Double.parseDouble(maxMessagesToComplete.evaluateValue(synCtx));

              aggregate =
                  new Aggregate(
                      synCtx.getEnvironment(),
                      correlateExpression.toString(),
                      completionTimeoutMillis,
                      minMsg.intValue(),
                      maxMsg.intValue(),
                      this);

              if (completionTimeoutMillis > 0) {
                synCtx
                    .getConfiguration()
                    .getSynapseTimer()
                    .schedule(aggregate, completionTimeoutMillis);
              }
              aggregate.getLock();
              activeAggregates.put(correlateExpression.toString(), aggregate);
            }
          }
        }

      } else if (synCtx.getProperty(correlationIdName) != null) {
        // if the correlattion cannot be found using the correlateExpression then
        // try the default which is through the AGGREGATE_CORRELATION message property
        // which is the unique original message id of a split or iterate operation and
        // which thus can be used to uniquely group messages into aggregates

        Object o = synCtx.getProperty(correlationIdName);
        String correlation;

        if (o != null && o instanceof String) {
          correlation = (String) o;
          while (aggregate == null) {
            synchronized (lock) {
              if (activeAggregates.containsKey(correlation)) {
                aggregate = activeAggregates.get(correlation);
                if (aggregate != null) {
                  if (!aggregate.getLock()) {
                    aggregate = null;
                  }
                } else {
                  break;
                }
              } else {
                if (synLog.isTraceOrDebugEnabled()) {
                  synLog.traceOrDebug(
                      "Creating new Aggregator - "
                          + (completionTimeoutMillis > 0
                              ? "expires in : " + (completionTimeoutMillis / 1000) + "secs"
                              : "without expiry time"));
                }

                Double minMsg = -1.0;
                if (minMessagesToComplete != null) {
                  minMsg = Double.parseDouble(minMessagesToComplete.evaluateValue(synCtx));
                }
                Double maxMsg = -1.0;
                if (maxMessagesToComplete != null) {
                  maxMsg = Double.parseDouble(maxMessagesToComplete.evaluateValue(synCtx));
                }

                aggregate =
                    new Aggregate(
                        synCtx.getEnvironment(),
                        correlation,
                        completionTimeoutMillis,
                        minMsg.intValue(),
                        maxMsg.intValue(),
                        this);

                if (completionTimeoutMillis > 0) {
                  synchronized (aggregate) {
                    if (!aggregate.isCompleted()) {
                      synCtx
                          .getConfiguration()
                          .getSynapseTimer()
                          .schedule(aggregate, completionTimeoutMillis);
                    }
                  }
                }
                aggregate.getLock();
                activeAggregates.put(correlation, aggregate);
              }
            }
          }

        } else {
          synLog.traceOrDebug("Unable to find aggrgation correlation property");
          return true;
        }
      } else {
        synLog.traceOrDebug("Unable to find aggrgation correlation XPath or property");
        return true;
      }

      // if there is an aggregate continue on aggregation
      if (aggregate != null) {
        // this is a temporary fix
        synCtx.getEnvelope().build();
        boolean collected = aggregate.addMessage(synCtx);
        if (synLog.isTraceOrDebugEnabled()) {
          if (collected) {
            synLog.traceOrDebug("Collected a message during aggregation");
            if (synLog.isTraceTraceEnabled()) {
              synLog.traceTrace("Collected message : " + synCtx);
            }
          }
        }

        // check the completeness of the aggregate and if completed aggregate the messages
        // if not completed return false and block the message sequence till it completes

        if (aggregate.isComplete(synLog)) {
          synLog.traceOrDebug("Aggregation completed - invoking onComplete");
          boolean onCompleteSeqResult = completeAggregate(aggregate);
          synLog.traceOrDebug("End : Aggregate mediator");
          isAggregateComplete = onCompleteSeqResult;
          return onCompleteSeqResult;
        } else {
          aggregate.releaseLock();
        }

      } else {
        // if the aggregation correlation cannot be found then continue the message on the
        // normal path by returning true

        synLog.traceOrDebug("Unable to find an aggregate for this message - skip");
        return true;
      }

    } catch (JaxenException e) {
      handleException("Unable to execute the XPATH over the message", e, synCtx);
    }

    synLog.traceOrDebug("End : Aggregate mediator");

    // When Aggregation is not completed return false to hold the flow
    return false;
  }
Esempio n. 14
0
 public String getEvaluatedExpression(MessageContext synCtx) {
   return expression.stringValueOf(synCtx);
 }
  private void makePOXFault(MessageContext synCtx, SynapseLog synLog) {

    OMFactory fac = synCtx.getEnvelope().getOMFactory();
    OMElement faultPayload = fac.createOMElement(new QName("Exception"));

    if (faultDetail != null) {

      if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Setting the fault detail : " + faultDetail + " as the POX Fault");
      }

      faultPayload.setText(faultDetail);

    } else if (faultDetailExpr != null) {

      String faultDetail = faultDetailExpr.stringValueOf(synCtx);

      if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Setting the fault detail : " + faultDetail + " as the POX Fault");
      }

      faultPayload.setText(faultDetail);

    } else if (faultReasonValue != null) {

      if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Setting the fault reason : " + faultReasonValue + " as the POX Fault");
      }

      faultPayload.setText(faultReasonValue);

    } else if (faultReasonExpr != null) {

      String faultReason = faultReasonExpr.stringValueOf(synCtx);
      faultPayload.setText(faultReason);

      if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Setting the fault reason : " + faultReason + " as the POX Fault");
      }
    }

    SOAPBody body = synCtx.getEnvelope().getBody();
    if (body != null) {

      if (body.getFirstElement() != null) {
        body.getFirstElement().detach();
      }

      synCtx.setFaultResponse(true);
      ((Axis2MessageContext) synCtx).getAxis2MessageContext().setProcessingFault(true);

      if (synLog.isTraceOrDebugEnabled()) {
        String msg =
            "Original SOAP Message : "
                + synCtx.getEnvelope().toString()
                + "POXFault Message created : "
                + faultPayload.toString();
        synLog.traceTrace(msg);
        if (log.isTraceEnabled()) {
          log.trace(msg);
        }
      }

      body.addChild(faultPayload);
    }
  }