当前位置: 首页>>代码示例>>Java>>正文


Java SOAPMessage.writeTo方法代码示例

本文整理汇总了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]");
                }
            }
        }

    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:XmlTest.java

示例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;
  }
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:20,代码来源:SOAPUtils.java

示例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();
}
 
开发者ID:D2Edev,项目名称:onvifjava,代码行数:30,代码来源:CameraDiscovery.java

示例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;
    }
}
 
开发者ID:vrk-kpa,项目名称:xrd4j,代码行数:17,代码来源:SOAPHelper.java

示例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 "";
    }
}
 
开发者ID:vrk-kpa,项目名称:xrd4j,代码行数:17,代码来源:SOAPHelper.java


注:本文中的javax.xml.soap.SOAPMessage.writeTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。