本文整理汇总了Java中javax.xml.soap.SOAPMessage.writeTo方法的典型用法代码示例。如果您正苦于以下问题:Java SOAPMessage.writeTo方法的具体用法?Java SOAPMessage.writeTo怎么用?Java SOAPMessage.writeTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.soap.SOAPMessage
的用法示例。
在下文中一共展示了SOAPMessage.writeTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
public void test() throws Exception {
File file = new File("message.xml");
file.deleteOnExit();
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = createMessage(mf);
// Save the soap message to file
try (FileOutputStream sentFile = new FileOutputStream(file)) {
msg.writeTo(sentFile);
}
// See if we get the image object back
try (FileInputStream fin = new FileInputStream(file)) {
SOAPMessage newMsg = mf.createMessage(msg.getMimeHeaders(), fin);
newMsg.writeTo(new ByteArrayOutputStream());
Iterator<?> i = newMsg.getAttachments();
while (i.hasNext()) {
AttachmentPart att = (AttachmentPart) i.next();
Object obj = att.getContent();
if (!(obj instanceof StreamSource)) {
fail("Got incorrect attachment type [" + obj.getClass() + "], " +
"expected [javax.xml.transform.stream.StreamSource]");
}
}
}
}
示例2: toString
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
public static String toString(SOAPMessage soapMessage, String encoding) throws TransformerConfigurationException, TransformerException, SOAPException, IOException, ParserConfigurationException, SAXException {
soapMessage.saveChanges();
if (encoding == null) { // #3803
Engine.logEngine.warn("(SOAPUtils) encoding is null. Set encoding to UTF-8 for toString.");
encoding = "UTF-8";
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
soapMessage.writeTo(out);
String s = new String(out.toByteArray(), encoding);
s = XMLUtils.prettyPrintDOMWithEncoding(s, encoding);
// Ticket #2678: fix empty "xmlns"
s = s.replaceAll("\\sxmlns=\"\"", "");
return s;
}
示例3: createProbeXML
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
private byte[] createProbeXML() throws SOAPException, IOException {
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage message = messageFactory.createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
envelope.addNamespaceDeclaration("wsa", "http://schemas.xmlsoap.org/ws/2004/08/addressing");
envelope.addNamespaceDeclaration("tns", "http://schemas.xmlsoap.org/ws/2005/04/discovery");
envelope.addNamespaceDeclaration("nns", "http://www.onvif.org/ver10/network/wsdl");
QName action = envelope.createQName("Action", "wsa");
QName mid = envelope.createQName("MessageID", "wsa");
QName to = envelope.createQName("To", "wsa");
QName probe = envelope.createQName("Probe", "tns");
QName types = envelope.createQName("Types", "tns");
QName tramsmitter=envelope.createQName("NetworkVideoTransmitter", "nns");
SOAPHeader header = envelope.getHeader();
SOAPElement actionEl = header.addChildElement(action);
actionEl.setTextContent("http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe");
SOAPElement messIsEl = header.addChildElement(mid);
messIsEl.setTextContent("urn:uuid:" + UUID.randomUUID().toString());
SOAPElement toEl = header.addChildElement(to);
toEl.setTextContent("urn:schemas-xmlsoap-org:ws:2005:04:discovery");
SOAPBody body = envelope.getBody();
SOAPElement probeEl = body.addChildElement(probe);
SOAPElement typesEl=probeEl.addChildElement(types);
typesEl.setTextContent("nns:NetworkVideoTransmitter");
ByteArrayOutputStream out = new ByteArrayOutputStream();
message.writeTo(out);
return out.toByteArray();
}
示例4: toByteArray
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
/**
* Converts the given SOAPMessage to byte array.
*
* @param message SOAPMessage object to be converted
* @return byte array containing the SOAPMessage or null
*/
public static byte[] toByteArray(SOAPMessage message) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
message.writeTo(out);
return out.toByteArray();
} catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
return null;
}
}
示例5: toString
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
/**
* Converts the given SOAPMessage to String.
*
* @param message SOAPMessage object to be converted
* @return String presentation of the given SOAPMessage
*/
public static String toString(SOAPMessage message) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
message.writeTo(out);
return new String(out.toByteArray(), CHARSET);
} catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
return "";
}
}