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);
  }
 private Object getResultValue(MessageContext synCtx) {
   if (value != null) {
     return value;
   } else if (valueElement != null) {
     return valueElement;
   } else {
     return convertValue(expression.stringValueOf(synCtx), type);
   }
 }
Exemple #4
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 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();
   }
 }
Exemple #6
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);
    }
  }