本文整理汇总了Java中org.apache.axiom.om.OMOutputFormat.setCharSetEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java OMOutputFormat.setCharSetEncoding方法的具体用法?Java OMOutputFormat.setCharSetEncoding怎么用?Java OMOutputFormat.setCharSetEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.axiom.om.OMOutputFormat
的用法示例。
在下文中一共展示了OMOutputFormat.setCharSetEncoding方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOMOutputFormat
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
/**
* Get the OMOutput format for the given message
* @param msgContext the axis message context
* @return the OMOutput format to be used
*/
public static OMOutputFormat getOMOutputFormat(MessageContext msgContext) {
OMOutputFormat format = new OMOutputFormat();
msgContext.setDoingMTOM(TransportUtils.doWriteMTOM(msgContext));
msgContext.setDoingSwA(TransportUtils.doWriteSwA(msgContext));
msgContext.setDoingREST(TransportUtils.isDoingREST(msgContext));
format.setSOAP11(msgContext.isSOAP11());
format.setDoOptimize(msgContext.isDoingMTOM());
format.setDoingSWA(msgContext.isDoingSwA());
format.setCharSetEncoding(TransportUtils.getCharSetEncoding(msgContext));
Object mimeBoundaryProperty = msgContext.getProperty(Constants.Configuration.MIME_BOUNDARY);
if (mimeBoundaryProperty != null) {
format.setMimeBoundary((String) mimeBoundaryProperty);
}
return format;
}
示例2: encode
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
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();
}
示例3: testWithDeclaration
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
public void testWithDeclaration() throws Exception {
ApplicationXMLFormatter xmlFormatter = new ApplicationXMLFormatter();
MessageContext messageContext = new MessageContext();
messageContext.setProperty("WRITE_XML_DECLARATION", "true");
createPayload(messageContext);
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(StandardCharsets.UTF_8.toString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
xmlFormatter.writeTo(messageContext, format, baos, true);
String output = new String(baos.toByteArray());
assertEquals("Compare payload with default XML declaration",
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><hello>world</hello>", output);
}
示例4: testWithCustomEncodingDeclaration
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
public void testWithCustomEncodingDeclaration() throws Exception {
ApplicationXMLFormatter xmlFormatter = new ApplicationXMLFormatter();
MessageContext messageContext = new MessageContext();
messageContext.setProperty("WRITE_XML_DECLARATION", "true");
messageContext.setProperty("XML_DECLARATION_ENCODING", StandardCharsets.ISO_8859_1.toString());
createPayload(messageContext);
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(StandardCharsets.UTF_8.toString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
xmlFormatter.writeTo(messageContext, format, baos, true);
String output = new String(baos.toByteArray());
assertEquals("Compare payload with custom encoding XML declaration",
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?><hello>world</hello>", output);
}
示例5: testWithStandalone
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
public void testWithStandalone() throws Exception {
ApplicationXMLFormatter xmlFormatter = new ApplicationXMLFormatter();
MessageContext messageContext = new MessageContext();
messageContext.setProperty("WRITE_XML_DECLARATION", "true");
messageContext.setProperty("XML_DECLARATION_ENCODING", StandardCharsets.UTF_8.toString());
messageContext.setProperty("XML_DECLARATION_STANDALONE", "yes");
createPayload(messageContext);
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(StandardCharsets.UTF_8.toString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
xmlFormatter.writeTo(messageContext, format, baos, true);
String output = new String(baos.toByteArray());
assertEquals("Compare payload with XML declaration containing standalone attribute",
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><hello>world</hello>", output);
}
示例6: testGetBytes
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
private void testGetBytes(String encoding) throws Exception {
MessageContext messageContext = createMessageContext(testString);
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(encoding);
byte[] bytes = new PlainTextFormatter().getBytes(messageContext, format);
assertEquals(testString, new String(bytes, encoding));
}
示例7: testWriteTo
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
private void testWriteTo(String encoding) throws Exception {
MessageContext messageContext = createMessageContext(testString);
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(encoding);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new PlainTextFormatter().writeTo(messageContext, format, baos, false);
assertEquals(testString, new String(baos.toByteArray(), encoding));
}
示例8: testElementGetBytes
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
private void testElementGetBytes(String encoding) throws Exception {
MessageContext messageContext = createElementMessageContextElement(testElementString);
if (messageContext != null) {
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(encoding);
byte[] bytes = new PlainTextFormatter().getBytes(messageContext, format);
assertEquals(testElementString, new String(bytes, encoding));
}
else {
assertTrue(false);
}
}
示例9: getXMLBytes
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
/**
* Returns a byte[] representing the xml data
* @param encoding String encoding of InputStream
* @return byte[]
* @see getXMLInputStream
*/
public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(encoding);
try {
serialize(baos, format);
} catch (XMLStreamException e) {
new OMException(e);
}
return baos.toByteArray();
}
示例10: getMessageAsString
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
/**
* @return message as String
*/
public String getMessageAsString() {
if (log.isDebugEnabled()) {
log.debug("Enter MessageAccessor");
}
Message msg = mc.getMessage();
String text = null;
if (msg != null) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OMOutputFormat format = new OMOutputFormat();
String charSetEncoding = (String) mc.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
charSetEncoding = (charSetEncoding == null) ? "UTF-8" : charSetEncoding;
format.setCharSetEncoding(charSetEncoding);
MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(baos, format);
msg.outputTo(writer, false);
writer.flush();
text = baos.toString(charSetEncoding);
} catch (Throwable t) {
if (log.isDebugEnabled()) {
log.debug("Cannot access message as string", t);
}
text = null;
}
}
if (log.isDebugEnabled()) {
log.debug("Exit MessageAccessor");
}
return text;
}
示例11: testCustomContentType
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
public void testCustomContentType() throws Exception {
String customContentType = "foo/bar";
String encoding = "UTF-8";
MessageContext messageContext = createElementMessageContextElement(testElementString);
assertNotNull(messageContext);
messageContext.setProperty(Constants.Configuration.CONTENT_TYPE, customContentType);
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(encoding);
PlainTextFormatter formatter = new PlainTextFormatter();
String formattedContentType = formatter.getContentType(messageContext, format, null);
customContentType += "; charset=" + encoding;
assertEquals("ContentType retrieved from message context is invalid",
customContentType, formattedContentType);
}
示例12: writeMessage
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
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"));
}
}
示例13: writeTo
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
/**
* Writes this <CODE>SOAPMessage</CODE> object to the given output stream. The externalization
* format is as defined by the SOAP 1.1 with Attachments specification.
* <p/>
* <P>If there are no attachments, just an XML stream is written out. For those messages that
* have attachments, <CODE>writeTo</CODE> writes a MIME-encoded byte stream.</P>
*
* @param out the <CODE>OutputStream</CODE> object to which this <CODE>SOAPMessage</CODE> object
* will be written
* @throws SOAPException if there was a problem in externalizing this SOAP message
* @throws IOException if an I/O error occurs
*/
public void writeTo(OutputStream out) throws SOAPException, IOException {
try {
OMOutputFormat format = new OMOutputFormat();
String enc = (String)getProperty(CHARACTER_SET_ENCODING);
format.setCharSetEncoding(enc != null ? enc : OMOutputFormat.DEFAULT_CHAR_SET_ENCODING);
String writeXmlDecl = (String)getProperty(WRITE_XML_DECLARATION);
if (writeXmlDecl == null || writeXmlDecl.equals("false")) {
//SAAJ default case doesn't send XML decl
format.setIgnoreXMLDeclaration(true);
}
SOAPEnvelope envelope = ((SOAPEnvelopeImpl)soapPart.getEnvelope()).getOMEnvelope();
if (attachmentParts.isEmpty()) {
envelope.serialize(out, format);
} else {
format.setSOAP11(((SOAPEnvelopeImpl)soapPart.getEnvelope()).getOMFactory()
instanceof SOAP11Factory);
OMMultipartWriter mpw = new OMMultipartWriter(out, format);
OutputStream rootPartOutputStream = mpw.writeRootPart();
envelope.serialize(rootPartOutputStream);
rootPartOutputStream.close();
for (AttachmentPart ap : attachmentParts) {
mpw.writePart(ap.getDataHandler(), ap.getContentId());
}
mpw.complete();
}
saveChanges();
} catch (Exception e) {
throw new SOAPException(e);
}
}
示例14: testBadgerfishOMSerialization1
import org.apache.axiom.om.OMOutputFormat; //导入方法依赖的package包/类
public void testBadgerfishOMSerialization1() throws IOException {
String jsonString = getBadgerfishJSONString();
ByteArrayInputStream inStream = new ByteArrayInputStream(jsonString.getBytes());
MessageContext msgCtx = new MessageContext();
JSONOMBuilder omBuilder = new JSONOMBuilder();
OMElement elem = omBuilder.processDocument(inStream, JSONTestConstants.CONTENT_TYPE_BADGERFISH, msgCtx);
elem.toString();
SOAPEnvelope envelope = TransportUtils.createSOAPEnvelope(elem);
msgCtx.setEnvelope(envelope);
OMOutputFormat outputFormat = new OMOutputFormat();
outputFormat.setCharSetEncoding(MessageContext.DEFAULT_CHAR_SET_ENCODING);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
SOAPMessageFormatter formatter = new SOAPMessageFormatter();
formatter.writeTo(msgCtx, outputFormat, outStream, true);
outStream.flush();
outStream.close();
}