Ejemplo n.º 1
0
 public static OMElement wrapBoxCarringResponse(OMElement result) {
   OMFactory fac = OMAbstractFactory.getOMFactory();
   OMElement wrapperElement =
       fac.createOMElement(
           new QName(
               DBConstants.WSO2_DS_NAMESPACE, DBConstants.DATA_SERVICE_RESPONSE_WRAPPER_ELEMENT));
   if (result != null) {
     wrapperElement.addChild(result);
   }
   OMDocument doc = fac.createOMDocument();
   doc.addChild(wrapperElement);
   return doc.getOMDocumentElement();
 }
Ejemplo n.º 2
0
  public static SynapseMessageContext createLightweightSynapseMessageContext(String payload)
      throws Exception {
    MessageContext mc = new OldMessageContext();
    SynapseConfiguration config = new SynapseConfiguration();
    SynapseEnvironment env = new Axis2SynapseEnvironment(config);
    SynapseMessageContext synMc = Axis2SynapseMessageContextImpl.newInstance(mc, config, env);
    SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
    OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
    omDoc.addChild(envelope);

    envelope.getBody().addChild(createOMElement(payload));

    synMc.setEnvelope(envelope);
    return synMc;
  }
 protected String serialize() {
   String result = null;
   OMDocument document = factory.createOMDocument();
   OMElement documentElement = getDocumentElement();
   document.addChild(documentElement);
   ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
   try {
     prettify(documentElement, outputStream);
   } catch (XMLStreamException e) {
     // log.error(e);
     return null;
   } catch (Exception e) {
     // log.error(e);
     return null;
   }
   result = outputStream.toString();
   return result;
 }
Ejemplo n.º 4
0
 protected void releaseDocument(Object document) {
   ((OMDocument) document).close(false);
 }
Ejemplo n.º 5
0
 public String getCharsetEncoding() {
   return document.getCharsetEncoding();
 }
  /**
   * Actual transformation of the current message into a fault message
   *
   * @param synCtx the current message context
   * @param soapVersion SOAP version of the resulting fault desired
   * @param synLog the Synapse log to use
   */
  private void makeSOAPFault(MessageContext synCtx, int soapVersion, SynapseLog synLog) {

    if (synLog.isTraceOrDebugEnabled()) {
      synLog.traceOrDebug("Creating a SOAP " + (soapVersion == SOAP11 ? "1.1" : "1.2") + " fault");
    }

    // get the correct SOAP factory to be used
    SOAPFactory factory =
        (soapVersion == SOAP11
            ? OMAbstractFactory.getSOAP11Factory()
            : OMAbstractFactory.getSOAP12Factory());

    // create the SOAP fault document and envelope
    OMDocument soapFaultDocument = factory.createOMDocument();
    SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();
    soapFaultDocument.addChild(faultEnvelope);

    // create the fault element  if it is need
    SOAPFault fault = faultEnvelope.getBody().getFault();
    if (fault == null) {
      fault = factory.createSOAPFault();
    }

    // populate it
    setFaultCode(synCtx, factory, fault, soapVersion);
    setFaultReason(synCtx, factory, fault, soapVersion);
    setFaultNode(factory, fault);
    setFaultRole(factory, fault);
    setFaultDetail(synCtx, factory, fault);

    // set the all headers of original SOAP Envelope to the Fault Envelope
    if (synCtx.getEnvelope() != null) {
      SOAPHeader soapHeader = synCtx.getEnvelope().getHeader();
      if (soapHeader != null) {
        for (Iterator iter = soapHeader.examineAllHeaderBlocks(); iter.hasNext(); ) {
          Object o = iter.next();
          if (o instanceof SOAPHeaderBlock) {
            SOAPHeaderBlock header = (SOAPHeaderBlock) o;
            faultEnvelope.getHeader().addChild(header);
          } else if (o instanceof OMElement) {
            faultEnvelope.getHeader().addChild((OMElement) o);
          }
        }
      }
    }

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

    // overwrite current message envelope with new fault envelope
    try {
      synCtx.setEnvelope(faultEnvelope);
    } catch (AxisFault af) {
      handleException(
          "Error replacing current SOAP envelope " + "with the fault envelope", af, synCtx);
    }

    if (synCtx.getFaultTo() != null) {
      synCtx.setTo(synCtx.getFaultTo());
    } else if (synCtx.getReplyTo() != null) {
      synCtx.setTo(synCtx.getReplyTo());
    } else {
      synCtx.setTo(null);
    }

    // set original messageID as relatesTo
    if (synCtx.getMessageID() != null) {
      RelatesTo relatesTo = new RelatesTo(synCtx.getMessageID());
      synCtx.setRelatesTo(new RelatesTo[] {relatesTo});
    }

    synLog.traceOrDebug("End : Fault mediator");
  }