本文整理匯總了Java中javax.xml.soap.SOAPBody.addDocument方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPBody.addDocument方法的具體用法?Java SOAPBody.addDocument怎麽用?Java SOAPBody.addDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPBody
的用法示例。
在下文中一共展示了SOAPBody.addDocument方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createOldStyleSoapResponse
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
protected String createOldStyleSoapResponse(String soapVersion, String xml)
throws SOAPException {
try {
SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage();
SOAPBody soapBody = soapMessage.getSOAPBody();
soapBody.addDocument(DomHelper.toDomDocument(xml));
return DomHelper.toXmlNoWhiteSpace(soapMessage.getSOAPPart());
}
catch (Exception ex) {
throw new SOAPException(ex.getMessage(), ex);
}
}
示例2: handleOutbound
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Override
protected boolean handleOutbound(final SOAPMessageContext msgContext)
{
try
{
SOAPMessage message = msgContext.getMessage();
SOAPBody body = message.getSOAPBody();
Document document = body.extractContentAsDocument();
NodeList nodes = document.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++)
{
Node current = nodes.item(i);
NodeList childNodes = current.getChildNodes();
for (int j = 0; j < childNodes.getLength(); j++)
{
Node currentChildNode = childNodes.item(j);
if ("return".equals(currentChildNode.getLocalName()))
{
currentChildNode.setTextContent("PutByServerSOAPHandler");
}
}
}
body.addDocument(document);
message.saveChanges();
}
catch (SOAPException e)
{
throw new RuntimeException(e);
}
return true;
}
示例3: xmlStrToSOAPElement
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Converts the given XML string to SOAPElement.
*
* @param xml XML string
* @return given XML string as a SOAPElement or null if the conversion
* failed
*/
public static SOAPElement xmlStrToSOAPElement(String xml) {
LOGGER.debug("Convert XML string to SOAPElement. XML : \"{}\"", xml);
// Try to conver XML string to XML Document
Document doc = SOAPHelper.xmlStrToDoc(xml);
if (doc == null) {
LOGGER.warn("Convertin XML string to SOAP element failed.");
return null;
}
try {
// Use SAAJ to convert Document to SOAPElement
// Create SoapMessage
SOAPMessage message = createSOAPMessage();
SOAPBody soapBody = message.getSOAPBody();
// This returns the SOAPBodyElement
// that contains ONLY the Payload
SOAPElement payload = soapBody.addDocument(doc);
if (payload == null) {
LOGGER.warn("Converting XML string to SOAPElement failed.");
} else {
LOGGER.debug("Converting XML string to SOAPElement succeeded.");
}
return payload;
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
LOGGER.warn("Converting XML document to SOAPElement failed.");
return null;
}
}
示例4: createSoapRequest
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Create the SOAP request object based on the document variable value.
*/
protected SOAPMessage createSoapRequest(Object requestObj) throws ActivityException {
try {
MessageFactory messageFactory = getSoapMessageFactory();
SOAPMessage soapMessage = messageFactory.createMessage();
Map<Name,String> soapReqHeaders = getSoapRequestHeaders();
if (soapReqHeaders != null) {
SOAPHeader header = soapMessage.getSOAPHeader();
for (Name name : soapReqHeaders.keySet()) {
header.addHeaderElement(name).setTextContent(soapReqHeaders.get(name));
}
}
SOAPBody soapBody = soapMessage.getSOAPBody();
Document requestDoc = null;
if (requestObj instanceof String) {
requestDoc = DomHelper.toDomDocument((String)requestObj);
soapBody.addDocument(requestDoc);
}
else {
Variable reqVar = getProcessDefinition().getVariable(getAttributeValue(REQUEST_VARIABLE));
XmlDocumentTranslator docRefTrans = (XmlDocumentTranslator)VariableTranslator.getTranslator(getPackage(), reqVar.getType());
requestDoc = docRefTrans.toDomDocument(requestObj);
Document copiedDocument = DomHelper.copyDomDocument(requestDoc);
soapBody.addDocument(copiedDocument);
}
return soapMessage;
}
catch (Exception ex) {
throw new ActivityException(ex.getMessage(), ex);
}
}
示例5: createSoapResponse
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Allow version specific factory passed in TODO: allow specifying response
* headers
*/
protected String createSoapResponse(String soapVersion, String xml) throws SOAPException {
try {
SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage();
SOAPBody soapBody = soapMessage.getSOAPBody();
soapBody.addDocument(DomHelper.toDomDocument(xml));
return DomHelper.toXml(soapMessage.getSOAPPart().getDocumentElement());
}
catch (Exception ex) {
throw new SOAPException(ex.getMessage(), ex);
}
}
示例6: createSoapMessage
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
/**
* Create a new SOAP message from the specified XMLBeans object. The XmlObject
* will be injected into the SOAP Body.
* @param xmlObject The XmlObject to create a SOAP message from
* @return a SOAPMessage containing the contents of the specified XmlObject
* @throws SOAPException
*/
public SOAPMessage createSoapMessage(XmlObject xmlObject) throws SOAPException {
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = msgFactory.createMessage();
SOAPPart prt = soapMessage.getSOAPPart();
SOAPEnvelope env = prt.getEnvelope();
addWssHeader(env);
SOAPBody soapBody = env.getBody();
org.w3c.dom.Node node = xmlObject.getDomNode();
soapBody.addDocument((Document) node);
return soapMessage;
}
示例7: handleInbound
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Override
protected boolean handleInbound(final SOAPMessageContext msgContext)
{
try
{
SOAPMessage message = msgContext.getMessage();
SOAPBody body = message.getSOAPBody();
Document document = body.extractContentAsDocument();
NodeList nodes = document.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++)
{
Node current = nodes.item(i);
NodeList childNodes = current.getChildNodes();
for (int j = 0; j < childNodes.getLength(); j++)
{
Node currentChildNode = childNodes.item(j);
if ("return".equals(currentChildNode.getLocalName()))
{
currentChildNode.setTextContent("PutByClientSOAPHandler");
}
}
}
body.addDocument(document);
message.saveChanges();
}
catch (SOAPException e)
{
throw new RuntimeException(e);
}
return true;
}
示例8: invokeAdd
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
int invokeAdd(AddRequest addRequest) {
int sum = 0;
try {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory
.newInstance();
builderFactory.setNamespaceAware(true);
Document doc = builderFactory.newDocumentBuilder().newDocument();
JAXBContext context = JAXBContext.newInstance(AddRequest.class,
AddResponse.class);
context.createMarshaller().marshal(addRequest, doc);
MessageFactory mf = MessageFactory
.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage request = mf.createMessage();
SOAPBody body = request.getSOAPBody();
body.addDocument(doc);
SOAPMessage response = dispatch.invoke(request);
AddResponse addResponse = context
.createUnmarshaller()
.unmarshal(response.getSOAPBody().getFirstChild(),
AddResponse.class).getValue();
sum = addResponse.getSum();
} catch (Exception e) {
e.printStackTrace();
}
return sum;
}
示例9: _testAddDocument
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
public void _testAddDocument() {
try {
Document document = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(TestUtils.getTestFileURI("soap-body.xml"));
MessageFactory fact = MessageFactory.newInstance();
SOAPMessage message = fact.createMessage();
message.getSOAPHeader().detachNode();
// assertNull(message.getSOAPHeader());
// TODO:this fails. Header is always being created if it doesnt exist in DOOM
SOAPBody soapBody = message.getSOAPBody();
soapBody.addDocument(document);
message.saveChanges();
// Get contents using SAAJ APIs
Iterator iter1 = soapBody.getChildElements();
getContents(iter1, "");
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected Exception : " + e);
}
}
示例10: handleInbound
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Override
protected boolean handleInbound(final SOAPMessageContext msgContext)
{
log.info("handleInbound()");
try
{
SOAPMessage message = msgContext.getMessage();
SOAPBody body = message.getSOAPBody();
Document document = body.extractContentAsDocument();
Node node = document;
log.info(DOMWriter.printNode(node, true));
NodeList nodes = node.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++)
{
Node current = nodes.item(i);
NodeList childNodes = current.getChildNodes();
for (int j = 0; j < childNodes.getLength(); j++)
{
Node currentChildNode = childNodes.item(j);
if ("result".equals(currentChildNode.getLocalName()))
{
currentChildNode.setTextContent(currentChildNode.getTextContent() + " modified in handler");
}
}
}
log.info(DOMWriter.printNode(node, true));
// Add document back as removed by call to 'extractContentAsDocument()'
body.addDocument(document);
message.saveChanges();
}
catch (SOAPException e)
{
throw new RuntimeException("Error in Handler", e);
}
log.info("Finished");
return true;
}
示例11: invokeSubtract1
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
private void invokeSubtract1(int i, int j) {
int diff = 0;
try {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory
.newInstance();
builderFactory.setNamespaceAware(true);
Document doc = builderFactory.newDocumentBuilder().newDocument();
OperationRequest operationRequest = new OperationRequest(i, j);
JAXBContext context = JAXBContext.newInstance(
OperationRequest.class, OperationResponse.class);
context.createMarshaller().marshal(operationRequest, doc);
MessageFactory mf = MessageFactory
.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage request = mf.createMessage();
// Specify operation in a SOAP header
addOperationSOAPHdr("subtract", request);
SOAPBody body = request.getSOAPBody();
body.addDocument(doc);
SOAPMessage response = dispatch.invoke(request);
OperationResponse operationResponse = context
.createUnmarshaller()
.unmarshal(response.getSOAPBody().getFirstChild(),
OperationResponse.class).getValue();
diff = operationResponse.getResult();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Difference of " + i + " and " + j + " is " + diff);
}
示例12: invoke
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@WebMethod
public SOAPMessage invoke(SOAPMessage request)
{
logger.log(Level.FINE, "DOMDocumentProviderProvider.invoke");
try
{
if (logger.isLoggable(Level.FINER))
{
ByteArrayOutputStream requestOutputStream = new ByteArrayOutputStream();
request.writeTo(requestOutputStream);
logger.log(Level.FINER, "DOMDocumentProviderProvider.invoke: request: " + requestOutputStream.toString());
requestOutputStream.close();
}
if (_domDocumentProviderJunction != null)
{
String id = null;
SOAPPart requestPart = request.getSOAPPart();
SOAPEnvelope requestEnvelope = requestPart.getEnvelope();
SOAPBody requestBody = requestEnvelope.getBody();
Iterator<SOAPElement> requestElements = (Iterator<SOAPElement>) requestBody.getChildElements();
while (requestElements.hasNext())
{
SOAPElement requestElement = requestElements.next();
if ((requestElement.getNodeType() == Node.ELEMENT_NODE) && CommonDefs.INTERCONNECT_OPERATIONNAME_PROVIDER_OBTAINDATA.equals(requestElement.getLocalName()) && CommonDefs.INTERCONNECT_NAMESPACE.equals(requestElement.getNamespaceURI()))
{
Iterator<SOAPElement> requestParameters = (Iterator<SOAPElement>) requestElement.getChildElements();
while ((id == null) && requestParameters.hasNext())
{
SOAPElement requestParameter = requestParameters.next();
if ((requestParameter.getNodeType() == Node.ELEMENT_NODE) && CommonDefs.INTERCONNECT_PARAMETERNAME_ID.equals(requestParameter.getLocalName()) && CommonDefs.INTERCONNECT_NAMESPACE.equals(requestParameter.getNamespaceURI()))
id = requestParameter.getTextContent();
}
}
}
MessageFactory responceFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage responce = responceFactory.createMessage();
SOAPPart responcePart = responce.getSOAPPart();
SOAPEnvelope responceEnvelope = responcePart.getEnvelope();
SOAPBody responceBody = responceEnvelope.getBody();
logger.log(Level.FINE, "DOMDocumentProviderProvider.invoke: id = " + id);
if (id != null)
{
Document document = _domDocumentProviderJunction.withdraw(id);
if (document != null)
responceBody.addDocument(document);
}
if (logger.isLoggable(Level.FINER))
{
ByteArrayOutputStream responceOutputStream = new ByteArrayOutputStream();
request.writeTo(responceOutputStream);
logger.log(Level.FINER, "DOMDocumentProviderProvider.invoke: responce = " + responceOutputStream.toString());
responceOutputStream.close();
}
return responce;
}
}
catch (SOAPException soapException)
{
logger.log(Level.WARNING, "DOMDocumentProviderProvider ", soapException);
}
catch (IOException ioException)
{
logger.log(Level.WARNING, "DOMDocumentProviderProvider ", ioException);
}
return null;
}
開發者ID:arjuna-technologies,項目名稱:Interconnect_DataBroker_PlugIn,代碼行數:82,代碼來源:DOMDocumentProviderProvider.java
示例13: consume
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
public void consume(Document data)
{
logger.log(Level.FINE, "DOMDocumentPushDataSink.consume");
try
{
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage request = messageFactory.createMessage();
SOAPPart requestPart = request.getSOAPPart();
SOAPEnvelope requestEnvelope = requestPart.getEnvelope();
SOAPBody requestBody = requestEnvelope.getBody();
Document requestData = (Document) data.cloneNode(true);
Element requestElement = requestData.getDocumentElement();
Element requestIdElement = requestData.createElementNS(CommonDefs.INTERCONNECT_NAMESPACE, CommonDefs.INTERCONNECT_PARAMETERNAME_ID);
requestIdElement.appendChild(requestData.createTextNode(_endpointPath));
requestElement.appendChild(requestIdElement);
requestBody.addDocument(requestData);
if (logger.isLoggable(Level.FINE))
{
ByteArrayOutputStream requestOutputStream = new ByteArrayOutputStream();
request.writeTo(requestOutputStream);
logger.log(Level.FINE, "DOMDocumentPushDataSink.consume: request = " + requestOutputStream.toString());
requestOutputStream.close();
}
SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = connectionFactory.createConnection();
URL serviceURL = new URL(_serviceRootURL + "/" + CommonDefs.INTERCONNECT_SERVICE_PATH + "/" + CommonDefs.INTERCONNECT_SERVICENAME_ACCEPTOR);
SOAPMessage responce = connection.call(request, serviceURL);
if (logger.isLoggable(Level.FINE))
{
ByteArrayOutputStream responceOutputStream = new ByteArrayOutputStream();
responce.writeTo(responceOutputStream);
logger.log(Level.FINE, "DOMDocumentPushDataSink.consume: responce = " + responceOutputStream.toString());
responceOutputStream.close();
}
}
catch (Throwable throwable)
{
logger.log(Level.WARNING, "Problems with web service invoke", throwable);
}
}
開發者ID:arjuna-technologies,項目名稱:Interconnect_DataBroker_PlugIn,代碼行數:46,代碼來源:DOMDocumentPushDataSink.java
示例14: consume
import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
public void consume(Document data)
{
logger.log(Level.FINE, "PushWebServiceDataSink.consume");
try
{
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage request = messageFactory.createMessage();
SOAPPart requestPart = request.getSOAPPart();
SOAPEnvelope requestEnvelope = requestPart.getEnvelope();
SOAPBody requestBody = requestEnvelope.getBody();
requestEnvelope.addNamespaceDeclaration("oper", _operationNamespace);
requestBody.addBodyElement(requestEnvelope.createQName(_operationName, "oper"));
requestBody.addDocument(data);
if (logger.isLoggable(Level.FINE))
{
ByteArrayOutputStream requestOutputStream = new ByteArrayOutputStream();
request.writeTo(requestOutputStream);
logger.log(Level.FINE, "Request: " + requestOutputStream.toString());
requestOutputStream.close();
}
SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = connectionFactory.createConnection();
SOAPMessage responce = connection.call(request, _serviceURL);
if (logger.isLoggable(Level.FINE))
{
ByteArrayOutputStream responceOutputStream = new ByteArrayOutputStream();
responce.writeTo(responceOutputStream);
logger.log(Level.FINE, "Responce: " + responceOutputStream.toString());
responceOutputStream.close();
}
}
catch (Throwable throwable)
{
logger.log(Level.WARNING, "Problems with web service invoke", throwable);
}
}
開發者ID:arjuna-technologies,項目名稱:WebService_DataBroker_PlugIn,代碼行數:42,代碼來源:PushSOAPWebServiceDataSink.java