本文整理匯總了Java中javax.xml.soap.SOAPEnvelope.getBody方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPEnvelope.getBody方法的具體用法?Java SOAPEnvelope.getBody怎麽用?Java SOAPEnvelope.getBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPEnvelope
的用法示例。
在下文中一共展示了SOAPEnvelope.getBody方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createXPath
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* Constructs XPath query over the SOAP message
*
* @param query XPath query
* @param response SOAP message
* @return XPath query
* @throws SOAPException in case of SOAP issue
* @throws JaxenException XPath problem
*/
public final XPath createXPath(final String query, final SOAPMessage response) throws SOAPException, JaxenException {
/* Uses DOM to XPath mapping */
final XPath xpath = new DOMXPath(query);
/* Define a namespaces used in response */
final SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
final SOAPPart sp = response.getSOAPPart();
final SOAPEnvelope env = sp.getEnvelope();
final SOAPBody bdy = env.getBody();
/* Add namespaces from SOAP envelope */
addNamespaces(nsContext, env);
/* Add namespaces of top body element */
final Iterator<?> bodyElements = bdy.getChildElements();
while (bodyElements.hasNext()) {
SOAPElement element = (SOAPElement) bodyElements.next();
addNamespaces(nsContext, element);
}
xpath.setNamespaceContext(nsContext);
return xpath;
}
示例2: createSimpleSOAPPart
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
private void createSimpleSOAPPart(SOAPMessage message) throws SOAPException {
SOAPPart sPart = message.getSOAPPart();
SOAPEnvelope env = sPart.getEnvelope();
SOAPBody body = env.getBody();
SOAPHeader header = env.getHeader();
header.addHeaderElement(env.createName("Header1",
"pref",
"http://test.apach.org/test"))
.addTextNode("This is header1");
Name ns = env.createName("echo", "swa2", "http://fakeNamespace2.org");
final SOAPBodyElement bodyElement = body.addBodyElement(ns);
Name ns2 = env.createName("something");
final SOAPElement ele1 = bodyElement.addChildElement(ns2);
ele1.addTextNode("This is some text");
Name ns3 = env.createName("ping", "swa3", "http://fakeNamespace3.org");
final SOAPBodyElement bodyElement2 = body.addBodyElement(ns3);
Name ns4 = env.createName("another");
final SOAPElement ele2 = bodyElement2.addChildElement(ns4);
ele2.addTextNode("This is another text");
}
示例3: testSendReceiveMessageWithEmptyNSPrefix
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Validated @Test
public void testSendReceiveMessageWithEmptyNSPrefix() throws Exception {
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage request = mf.createMessage();
SOAPPart sPart = request.getSOAPPart();
SOAPEnvelope env = sPart.getEnvelope();
SOAPBody body = env.getBody();
//Namespace prefix is empty
body.addBodyElement(new QName("http://fakeNamespace2.org","echo"))
.addTextNode("This is some text");
SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage response = sCon.call(request, getAddress());
assertFalse(response.getAttachments().hasNext());
assertEquals(0, response.countAttachments());
String requestStr = printSOAPMessage(request);
String responseStr = printSOAPMessage(response);
assertTrue(responseStr.indexOf("echo") > -1);
sCon.close();
}
示例4: create
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
public static SOAPMessage create() throws SOAPException {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("codecentric", "https://www.codecentric.de");
SOAPBody envelopeBody = envelope.getBody();
SOAPElement soapBodyElem = envelopeBody.addChildElement("location", "codecentric");
SOAPElement place = soapBodyElem.addChildElement("place", "codecentric");
place.addTextNode("Berlin");
MimeHeaders headers = message.getMimeHeaders();
headers.addHeader("SOAPAction", "https://www.codecentric.de/location");
message.saveChanges();
return message;
}
示例5: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!isRequest) { // only incoming messages
try {
SOAPMessage soapMsg = context.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPBody soapBody = soapEnv.getBody();
if (soapBody != null) {
// Should have a SOAPBody and a listall response...
NodeList nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_LIST_ALL_RESPONSE);
if (nodeList.getLength() > 0) { // check for listAllResponse
// tag first!
nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_ELEMENT);
recursiveRenamespace(nodeList); // renamespace...
soapMsg.saveChanges();
}
}
} catch (Exception e) {
catchMessages(e);
}
}
return true;
}
示例6: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!isRequest) { // only incoming messages
try {
SOAPMessage soapMsg = context.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPBody soapBody = soapEnv.getBody();
if (soapBody != null) {
// Should have a SOAPBody and a listall response...
NodeList nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDY_LIST_ALL_RESPONSE);
if (nodeList.getLength() > 0) { // check for listAllResponse
// tag first!
nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDIES_ELEMENT);
recursiveRenamespace(nodeList); // renamespace...
soapMsg.saveChanges();
}
}
} catch (Exception e) {
catchMessages(e);
}
}
return true;
}
示例7: addFault
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* Adds a SOAP fault to the SOAP message of this response.
*
* @param code the fault code.
* @param actor the fault actor.
* @param desc the fault description.
* @return the SOAP fault which has been added to the SOAP message. null if
* there is no SOAP message in this response or the fault has
* already been added.
* @throws SOAPException a SOAP error occurred when adding the the fault.
*/
public SOAPFault addFault(String code, String actor, String desc)
throws SOAPException {
SOAPMessage msg = getMessage();
if (msg != null) {
SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
SOAPBody body = env.getBody();
if (body != null && !body.hasFault()) {
SOAPFault fault = body.addFault();
if (code != null) {
fault.setFaultCode(env.getElementName().getPrefix() + ":"
+ code);
}
if (actor != null) {
fault.setFaultActor(actor);
}
if (desc != null) {
fault.setFaultString(desc);
}
return fault;
}
}
return null;
}
示例8: processSOAP
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
public SOAPMessage processSOAP(Exchange exchange) {
// Since the Camel-CXF endpoint uses a list to store the parameters
// and bean component uses the bodyAs expression to get the value
// we'll need to deal with the parameters ourself
SOAPMessage soapMessage = (SOAPMessage)exchange.getIn().getBody(List.class).get(0);
if (soapMessage == null) {
System.out.println("Incoming null message detected...");
return createDefaultSoapMessage("Greetings from Apache Camel!!!!", "null");
}
try {
SOAPPart sp = soapMessage.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
String requestText = sb.getFirstChild().getTextContent();
System.out.println(requestText);
return createDefaultSoapMessage("Greetings from Apache Camel!!!!", requestText);
} catch (Exception e) {
e.printStackTrace();
return createDefaultSoapMessage("Greetings from Apache Camel!!!!", e.getClass().getName());
}
}
示例9: verifyXOPPackage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
private boolean verifyXOPPackage(MessageContext context)
{
try
{
SOAPMessageContext msgContext = (SOAPMessageContext)context;
SOAPMessage soapMsg = msgContext.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPBody body = soapEnv.getBody();
boolean found = scanNodes(body.getChildNodes());
if(found) throw new IllegalStateException("XOP request not properly inlined");
}
catch (SOAPException ex)
{
throw new WebServiceException(ex);
}
return true;
}
示例10: invoke
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public SOAPMessage invoke(SOAPMessage soapMsg) {
int[] args = null;
Operation operation = null;
try {
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPBody soapBody = soapEnv.getBody();
args = getArgs(soapBody);
operation = getOperation(soapMsg);
} catch (SOAPException e) {
String errorMsg = "A problem occurred while parsing the SOAPMessage";
throw new SOAPFaultException(newSOAPFault(errorMsg));
}
int result = computeResult(operation, args[0], args[1]);
return output(result);
}
示例11: testAddDetailsTwice
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Validated @Test
public void testAddDetailsTwice() throws Exception {
MessageFactory fac = MessageFactory.newInstance();
//Create the response to the message
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
body.addFault().addDetail();
try {
body.getFault().addDetail();
fail("Expected Exception did not occur");
} catch (SOAPException e) {
assertTrue(true);
}
}
示例12: testFaultCodeWithPrefix1
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Test
public void testFaultCodeWithPrefix1() throws Exception {
MessageFactory fac = MessageFactory.newInstance();
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPFault sf = body.addFault();
String prefix = "wso2";
sf.setFaultCode(prefix + ":Server");
String result = sf.getFaultCode();
assertNotNull(result);
assertEquals(prefix + ":Server", result);
}
示例13: _testFaults
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
public void _testFaults() throws Exception {
SOAPEnvelope envelope = getSOAPEnvelope();
SOAPBody body = envelope.getBody();
assertFalse(body.hasFault());
SOAPFault soapFault = body.addFault();
soapFault.setFaultString("myFault");
soapFault.setFaultCode("CODE");
assertTrue(body.hasFault());
assertNotNull(body.getFault());
assertSame(soapFault, body.getFault());
assertEquals("myFault", soapFault.getFaultString());
assertEquals("CODE", soapFault.getFaultCode());
}
示例14: testNonCommentText
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Validated @Test
public void testNonCommentText() throws Exception {
SOAPEnvelope envelope = getSOAPEnvelope();
SOAPBody body = envelope.getBody();
SOAPElement se = body.addChildElement("Child");
se.addTextNode("This is text");
Iterator iterator = se.getChildElements();
Object o = null;
while (iterator.hasNext()) {
o = iterator.next();
if (o instanceof Text) {
break;
}
}
assertTrue(o instanceof Text);
Text t = (Text)o;
assertTrue(!t.isComment());
}
示例15: _testGetFaultReasonTexts
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
public void _testGetFaultReasonTexts() throws Exception {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.addFaultReasonText("myReason", new Locale("en"));
soapFault.addFaultReasonText("de-myReason", new Locale("de"));
soapFault.addFaultReasonText("si-myReason", new Locale("si"));
soapMessage.saveChanges();
Iterator reasonTexts = soapFault.getFaultReasonTexts();
while (reasonTexts.hasNext()) {
String reasonText = (String)reasonTexts.next();
assertNotNull(reasonText);
}
}