本文整理匯總了Java中javax.xml.soap.SOAPPart.setContent方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPPart.setContent方法的具體用法?Java SOAPPart.setContent怎麽用?Java SOAPPart.setContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPPart
的用法示例。
在下文中一共展示了SOAPPart.setContent方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: substitute
import javax.xml.soap.SOAPPart; //導入方法依賴的package包/類
/**
* Substitutes all occurences of some given string inside the given {@link WebServiceMessage} with another value.
*
* @param message message to substitute in
* @param from the value to substitute
* @param to the value to substitute with
* @throws TransformerException
*/
public static void substitute(WebServiceMessage message, String from, String to) throws TransformerException {
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
SOAPPart soapPart = saajSoapMessage.getSaajMessage().getSOAPPart();
Source source = new DOMSource(soapPart);
StringResult stringResult = new StringResult();
TransformerFactory.newInstance().newTransformer().transform(source, stringResult);
String content = stringResult.toString().replaceAll(from, to);
try {
soapPart.setContent(new StringSource(content));
} catch (SOAPException e) {
throw new TransformerException(e);
}
}
示例2: testAddSource2
import javax.xml.soap.SOAPPart; //導入方法依賴的package包/類
@Validated @Test
public void testAddSource2() throws Exception {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader header = soapEnv.getHeader();
SOAPBody body = soapEnv.getBody();
assertTrue(header.addChildElement("ebxmlms1", "ch2",
"http://test.apache.org") instanceof SOAPHeaderElement);
assertTrue(header.addHeaderElement(
soapEnv.createName("ebxmlms2", "ch3", "http://test2.apache.org")) != null);
assertTrue(header.addHeaderElement(
new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ch5")) != null);
body.addChildElement("bodyEle1", "ele1", "http://ws.apache.org");
soapMessage.saveChanges();
SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = soapMessage2.getSOAPPart();
soapPart.setContent(soapMessage.getSOAPPart().getContent());
soapMessage2.saveChanges();
assertNotNull(soapMessage2);
}
示例3: testAddSource3
import javax.xml.soap.SOAPPart; //導入方法依賴的package包/類
@Validated @Test
public void testAddSource3() throws Exception {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader header = soapEnv.getHeader();
SOAPBody body = soapEnv.getBody();
assertTrue(header.addChildElement("ebxmlms1", "ch2",
"http://test.apache.org") instanceof SOAPHeaderElement);
assertTrue(header.addHeaderElement(
soapEnv.createName("ebxmlms2", "ch3", "http://test2.apache.org")) != null);
assertTrue(header.addHeaderElement(
new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ch5")) != null);
body.addChildElement("bodyEle1", "ele1", "http://ws.apache.org");
soapMessage.saveChanges();
SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = soapMessage2.getSOAPPart();
soapPart.setContent(soapMessage.getSOAPPart().getContent());
soapMessage2.saveChanges();
assertNotNull(soapMessage2);
}
示例4: _testInputEncoding
import javax.xml.soap.SOAPPart; //導入方法依賴的package包/類
public void _testInputEncoding() throws Exception {
DOMSource domSource;
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(new File(System.getProperty("basedir", ".") +
"/test-resources" + File.separator + "soap-part.xml"));
domSource = new DOMSource(document);
SOAPMessage message = MessageFactory.newInstance().createMessage();
// Get the SOAP part and set its content to domSource
SOAPPart soapPart = message.getSOAPPart();
soapPart.setContent(domSource);
message.saveChanges();
SOAPPart sp = message.getSOAPPart();
// String inputEncoding = sp.getInputEncoding();
// assertNotNull(inputEncoding);
}
示例5: readFrom
import javax.xml.soap.SOAPPart; //導入方法依賴的package包/類
public SOAPMessage readFrom(Class<SOAPMessage> soapEnvelopeClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> stringStringMultivaluedMap, InputStream inputStream) throws IOException, WebApplicationException {
try {
MessageFactory messageFactory = MessageFactory.newInstance();
StreamSource messageSource = new StreamSource(inputStream);
SOAPMessage message = messageFactory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
soapPart.setContent(messageSource);
return message;
} catch (SOAPException e) {
e.printStackTrace();
}
return null;
}
示例6: modifyMessage
import javax.xml.soap.SOAPPart; //導入方法依賴的package包/類
protected SOAPMessage modifyMessage( String soapProtocol, InputStream inputStream ) throws SOAPException
{
MessageFactory messageFactory = MessageFactory.newInstance( soapProtocol );
StreamSource messageSource = new StreamSource( inputStream );
SOAPMessage message = messageFactory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
soapPart.setContent( messageSource );
message.saveChanges();
return message;
}
示例7: toMessage
import javax.xml.soap.SOAPPart; //導入方法依賴的package包/類
private static final SOAPMessage toMessage(final Document jdomDocument)
throws IOException, SOAPException {
final SOAPMessage message = MessageFactory.newInstance()
.createMessage();
final SOAPPart sp = message.getSOAPPart();
sp.setContent(new DOMSource(jdomDocument.getFirstChild()));
return message;
}
示例8: testAddSource
import javax.xml.soap.SOAPPart; //導入方法依賴的package包/類
@Validated @Test
public void testAddSource() throws Exception {
/*
FileReader testFile = new FileReader(new File(System.getProperty("basedir",".")+"/test-resources" + File.separator + "soap-part.xml"));
StAXOMBuilder stAXOMBuilder =
OMXMLBuilderFactory.createStAXOMBuilder(
OMAbstractFactory.getSOAP11Factory(),
XMLInputFactory.newInstance().createXMLStreamReader(
testFile));
*/
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder builder = dbf.newDocumentBuilder();
Document document = builder.parse(TestUtils.getTestFileURI("soap-part.xml"));
DOMSource domSource = new DOMSource(document);
SOAPMessage message = MessageFactory.newInstance().createMessage();
// Get the SOAP part and set its content to domSource
SOAPPart soapPart = message.getSOAPPart();
soapPart.setContent(domSource);
message.saveChanges();
SOAPHeader header = message.getSOAPHeader();
if (header != null) {
Iterator iter1 = header.getChildElements();
getContents(iter1, "");
}
SOAPBody body = message.getSOAPBody();
Iterator iter2 = body.getChildElements();
getContents(iter2, "");
}
示例9: getSOAPMessageFromStream
import javax.xml.soap.SOAPPart; //導入方法依賴的package包/類
public SOAPMessage getSOAPMessageFromStream(InputStream inputStream) throws Exception {
SOAPMessage message = factory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
soapPart.setContent(getDOMSourceFromStream(inputStream));
return message;
}