org.apache.axiom.om.OMElement.serializeAndConsume()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.8k)|赞(0)|评价(0)|浏览(73)

本文整理了Java中org.apache.axiom.om.OMElement.serializeAndConsume()方法的一些代码示例,展示了OMElement.serializeAndConsume()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OMElement.serializeAndConsume()方法的具体详情如下:
包路径:org.apache.axiom.om.OMElement
类名称:OMElement
方法名:serializeAndConsume

OMElement.serializeAndConsume介绍

[英]Serialize the node without caching.

This method will always serialize the infoset as plain XML. In particular, any OMTextcontaining optimized binary will be inlined using base64 encoding.
[中]序列化节点而不缓存。
此方法始终将信息集序列化为纯XML。特别是,任何包含优化二进制文件的OMTEXT都将使用base64编码进行内联。

代码示例

代码示例来源:origin: org.apache.axis2/axis2-transport-http

private void handleOMOutput(OutputStream out, boolean doingMTOM)
    throws XMLStreamException {
  format.setDoOptimize(doingMTOM);
  element.serializeAndConsume(out, format);
}

代码示例来源:origin: org.apache.airavata/airavata-messenger-commons

public static String omToString(OMElement element) {
  StringWriter writer = new StringWriter();
  String ret = null;
  try {
    XMLStreamWriter streamWriter = getXMLOutputFactory().createXMLStreamWriter(writer);
    element.serializeAndConsume(streamWriter);
    streamWriter.flush();
    ret = writer.toString();
  } catch (Exception e) {
    throw new RuntimeException("unable to serialize the OMElement", e);
  }
  return ret;
}

代码示例来源:origin: org.apache.airavata/messenger-commons

public static String omToString(OMElement element) {
  StringWriter writer = new StringWriter();
  String ret = null;
  try {
    XMLStreamWriter streamWriter = getXMLOutputFactory().createXMLStreamWriter(writer);
    element.serializeAndConsume(streamWriter);
    streamWriter.flush();
    ret = writer.toString();
  } catch (Exception e) {
    throw new RuntimeException("unable to serialize the OMElement", e);
  }
  return ret;
}

代码示例来源:origin: org.apache.axis2/axis2-fastinfoset

/**
 * Retrieves the raw bytes from the SOAP envelop.
 * 
 * @see org.apache.axis2.transport.MessageFormatter#getBytes(org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat)
 */
public byte[] getBytes(MessageContext messageContext, OMOutputFormat format)
    throws AxisFault {
  OMElement element = messageContext.getEnvelope();
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  
  try {
    //Creates StAX document serializer which actually implements the XMLStreamWriter
    XMLStreamWriter streamWriter = new StAXDocumentSerializer(outStream);
    element.serializeAndConsume(streamWriter);
    //TODO Looks like the SOAP envelop doesn't have an end document tag. Find out why?
    streamWriter.writeEndDocument();
    
    return outStream.toByteArray();
    
  } catch (XMLStreamException xmlse) {
    logger.error(xmlse.getMessage());
    throw new AxisFault(xmlse.getMessage(), xmlse);
  }
}

代码示例来源:origin: org.apache.axis2/axis2-fastinfoset

/**
 * Retrieves the raw bytes from the SOAP envelop.
 * 
 * @see org.apache.axis2.transport.MessageFormatter#getBytes(org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat)
 */
public byte[] getBytes(MessageContext messageContext, OMOutputFormat format)
    throws AxisFault {
  //For POX drop the SOAP envelope and use the message body
  OMElement element = messageContext.getEnvelope().getBody().getFirstElement();
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  
  try {
    //Creates StAX document serializer which actually implements the XMLStreamWriter
    XMLStreamWriter streamWriter = new StAXDocumentSerializer(outStream);
    //Since we drop the SOAP envelop we have to manually write the start document and the end document events
    streamWriter.writeStartDocument();
    element.serializeAndConsume(streamWriter);
    streamWriter.writeEndDocument();
    
    return outStream.toByteArray();
    
  } catch (XMLStreamException xmlse) {
    logger.error(xmlse.getMessage());
    throw new AxisFault(xmlse.getMessage(), xmlse);
  }
}

代码示例来源:origin: org.apache.axis2/axis2-fastinfoset

/**
   * Write the SOAP envelop to the given OutputStream.
   * 
   * @see org.apache.axis2.transport.MessageFormatter#writeTo(org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat, java.io.OutputStream, boolean)
   */
  public void writeTo(MessageContext messageContext, OMOutputFormat format,
      OutputStream outputStream, boolean preserve) throws AxisFault {
    OMElement element = messageContext.getEnvelope();
    
    try {
      //Create the StAX document serializer
      XMLStreamWriter streamWriter = new StAXDocumentSerializer(outputStream);
      if (preserve) {
        element.serialize(streamWriter);
      } else {
        element.serializeAndConsume(streamWriter);
      }
//            TODO Looks like the SOAP envelop doesn't have a end document tag. Find out why?
      streamWriter.writeEndDocument();
    } catch (XMLStreamException xmlse) {
      logger.error(xmlse.getMessage());
      throw new AxisFault(xmlse.getMessage(), xmlse);
    }
  }

代码示例来源:origin: org.apache.axis2.transport/axis2-transport-testkit

public String encode(ClientOptions options, XMLMessage message) throws Exception {
    if (message.getType() == XMLMessage.Type.SWA) {
      throw new UnsupportedOperationException();
    }
    OMOutputFormat format = new OMOutputFormat();
    format.setIgnoreXMLDeclaration(true);
    StringWriter sw = new StringWriter();
    message.getMessageElement().serializeAndConsume(sw, format);
    return sw.toString();
  }
};

代码示例来源:origin: apache/axis2-java

public String encode(ClientOptions options, XMLMessage message) throws Exception {
    if (message.getType() == XMLMessage.Type.SWA) {
      throw new UnsupportedOperationException();
    }
    OMOutputFormat format = new OMOutputFormat();
    format.setIgnoreXMLDeclaration(true);
    StringWriter sw = new StringWriter();
    message.getMessageElement().serializeAndConsume(sw, format);
    return sw.toString();
  }
};

代码示例来源:origin: org.apache.axis2/axis2-transport-testkit

public String encode(ClientOptions options, XMLMessage message) throws Exception {
    if (message.getType() == XMLMessage.Type.SWA) {
      throw new UnsupportedOperationException();
    }
    OMOutputFormat format = new OMOutputFormat();
    format.setIgnoreXMLDeclaration(true);
    StringWriter sw = new StringWriter();
    message.getMessageElement().serializeAndConsume(sw, format);
    return sw.toString();
  }
};

代码示例来源:origin: org.apache.axis2/axis2-fastinfoset

/**
 * Write the SOAP envelop to the given OutputStream.
 * 
 * @see org.apache.axis2.transport.MessageFormatter#writeTo(org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat, java.io.OutputStream, boolean)
 */
public void writeTo(MessageContext messageContext, OMOutputFormat format,
    OutputStream outputStream, boolean preserve) throws AxisFault {
  //For POX drop the SOAP envelope and use the message body
  OMElement element = messageContext.getEnvelope().getBody().getFirstElement();
  
  try {
    //Create the StAX document serializer
    XMLStreamWriter streamWriter = new StAXDocumentSerializer(outputStream);
    //Since we drop the SOAP envelop we have to manually write the start document and the end document events			
    streamWriter.writeStartDocument();
    if (preserve) {
      element.serialize(streamWriter);
    } else {
      element.serializeAndConsume(streamWriter);
    }
    streamWriter.writeEndDocument();
  } catch (XMLStreamException xmlse) {
    logger.error(xmlse.getMessage());
    throw new AxisFault(xmlse.getMessage(), xmlse);
  }
}

代码示例来源:origin: org.apache.axis2/axis2-kernel

writeSwAMessage(msgCtxt, bytesOut, format, false);
} else {
  element.serializeAndConsume(bytesOut, format);
element.serializeAndConsume(bytesOut, format);
return bytesOut.toByteArray();

代码示例来源:origin: org.apache.axis2/axis2-transport-http

public byte[] writeBytes() throws AxisFault {
  try {
    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    if (!format.isOptimized()) {
      OMOutputFormat format2 = new OMOutputFormat();
      format2.setCharSetEncoding(charSetEnc);
      element.serializeAndConsume(bytesOut, format2);
      return bytesOut.toByteArray();
    } else {
      format.setCharSetEncoding(charSetEnc);
      format.setDoOptimize(true);
      element.serializeAndConsume(bytesOut, format);
      return bytesOut.toByteArray();
    }
  } catch (XMLStreamException e) {
    throw AxisFault.makeFault(e);
  } catch (FactoryConfigurationError e) {
    throw AxisFault.makeFault(e);
  }
}

代码示例来源:origin: org.apache.axis2/axis2-json

dataOut.serializeAndConsume(jsonWriter);
jsonWriter.writeEndDocument();
jsonString = out.toString();

代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl

/**
 * Deploy the sequence to the gateway.
 *
 * @param sequence     - The sequence element , which to be deployed in synapse
 * @param tenantDomain - The Tenant Domain
 * @throws AppManagementException on errors.
 */
public void addSequence(OMElement sequence, String tenantDomain) throws AppManagementException {
  try {
    StringWriter writer = new StringWriter();
    sequence.serializeAndConsume(writer);
    String addedSequence = writer.toString();
    if (!StringUtils.isEmpty(tenantDomain) && !tenantDomain.equals(MultitenantConstants
                                       .SUPER_TENANT_DOMAIN_NAME)) {
      appGatewayAdminStub.addSequenceForTenant(addedSequence, tenantDomain);
    } else {
      appGatewayAdminStub.addSequence(addedSequence);
    }
  } catch (RemoteException e) {
    String errorMsg = "Error while adding new sequence. Tenant : " + tenantDomain;
    throw new AppManagementException(errorMsg, e);
  } catch (AppGatewayAdminAppManagementExceptionException e) {
    String errorMsg = "Error while adding new sequence. Tenant : " + tenantDomain;
    throw new AppManagementException(errorMsg, e);
  } catch (XMLStreamException e) {
    String errorMsg = "Error while adding new sequence. Tenant : " + tenantDomain;
    throw new AppManagementException(errorMsg, e);
  }
}

代码示例来源:origin: org.apache.axis2.transport/axis2-transport-testkit

public byte[] encode(ClientOptions options, XMLMessage message) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OMOutputFormat outputFormat = new OMOutputFormat();
    outputFormat.setCharSetEncoding(options.getCharset());
    outputFormat.setIgnoreXMLDeclaration(true);
    if (message.getType() == XMLMessage.Type.SWA) {
      outputFormat.setMimeBoundary(options.getMimeBoundary());
      outputFormat.setRootContentId(options.getRootContentId());
      StringWriter writer = new StringWriter();
      message.getMessageElement().serializeAndConsume(writer);
      MIMEOutputUtils.writeSOAPWithAttachmentsMessage(writer, baos, message.getAttachments(), outputFormat);
    } else {
      message.getMessageElement().serializeAndConsume(baos, outputFormat);
    }
    return baos.toByteArray();
  }
};

代码示例来源:origin: org.apache.axis2/axis2-kernel

public static void writeMessage(MessageContext msgContext, OutputStream out) throws AxisFault {
  SOAPEnvelope envelope = msgContext.getEnvelope();
  OMElement outputMessage = envelope;
  if ((envelope != null) && msgContext.isDoingREST()) {
    outputMessage = envelope.getBody().getFirstElement();
  }
  if (outputMessage != null) {
    try {
      OMOutputFormat format = new OMOutputFormat();
      // Pick the char set encoding from the msgContext
      String charSetEnc =
          (String) msgContext
              .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
      format.setDoOptimize(false);
      format.setDoingSWA(false);
      format.setCharSetEncoding(charSetEnc);
      outputMessage.serializeAndConsume(out, format);
      out.flush();
    } catch (Exception e) {
      throw AxisFault.makeFault(e);
    }
  } else {
    throw new AxisFault(Messages.getMessage("outMessageNull"));
  }
}

代码示例来源:origin: apache/axis2-java

public static void writeMessage(MessageContext msgContext, OutputStream out) throws AxisFault {
  SOAPEnvelope envelope = msgContext.getEnvelope();
  OMElement outputMessage = envelope;
  if ((envelope != null) && msgContext.isDoingREST()) {
    outputMessage = envelope.getBody().getFirstElement();
  }
  if (outputMessage != null) {
    try {
      OMOutputFormat format = new OMOutputFormat();
      // Pick the char set encoding from the msgContext
      String charSetEnc =
          (String) msgContext
              .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
      format.setDoOptimize(false);
      format.setDoingSWA(false);
      format.setCharSetEncoding(charSetEnc);
      outputMessage.serializeAndConsume(out, format);
      out.flush();
    } catch (Exception e) {
      throw AxisFault.makeFault(e);
    }
  } else {
    throw new AxisFault(Messages.getMessage("outMessageNull"));
  }
}

代码示例来源:origin: org.wso2.carbon.data/org.wso2.carbon.dataservices.core

} else {
  result.serializeAndConsume(new NullOutputStream());

代码示例来源:origin: org.apache.axis2/axis2-transport-testkit

public byte[] encode(ClientOptions options, XMLMessage message) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OMOutputFormat outputFormat = new OMOutputFormat();
    outputFormat.setCharSetEncoding(options.getCharset());
    outputFormat.setIgnoreXMLDeclaration(true);
    if (message.getType() == XMLMessage.Type.SWA) {
      outputFormat.setMimeBoundary(options.getMimeBoundary());
      outputFormat.setRootContentId(options.getRootContentId());
      OMMultipartWriter mpw = new OMMultipartWriter(baos, outputFormat);
      OutputStream out = mpw.writeRootPart();
      message.getMessageElement().serializeAndConsume(out);
      out.close();
      Attachments attachments = message.getAttachments();
      for (String id : attachments.getAllContentIDs()) {
        mpw.writePart(attachments.getDataHandler(id), id);
      }
      mpw.complete();
    } else {
      message.getMessageElement().serializeAndConsume(baos, outputFormat);
    }
    return baos.toByteArray();
  }
};

代码示例来源:origin: apache/axis2-java

public byte[] encode(ClientOptions options, XMLMessage message) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OMOutputFormat outputFormat = new OMOutputFormat();
    outputFormat.setCharSetEncoding(options.getCharset());
    outputFormat.setIgnoreXMLDeclaration(true);
    if (message.getType() == XMLMessage.Type.SWA) {
      outputFormat.setMimeBoundary(options.getMimeBoundary());
      outputFormat.setRootContentId(options.getRootContentId());
      OMMultipartWriter mpw = new OMMultipartWriter(baos, outputFormat);
      OutputStream out = mpw.writeRootPart();
      message.getMessageElement().serializeAndConsume(out);
      out.close();
      Attachments attachments = message.getAttachments();
      for (String id : attachments.getAllContentIDs()) {
        mpw.writePart(attachments.getDataHandler(id), id);
      }
      mpw.complete();
    } else {
      message.getMessageElement().serializeAndConsume(baos, outputFormat);
    }
    return baos.toByteArray();
  }
};

相关文章

微信公众号

最新文章

更多