本文整理汇总了Java中org.apache.axiom.soap.SOAPEnvelope.serialize方法的典型用法代码示例。如果您正苦于以下问题:Java SOAPEnvelope.serialize方法的具体用法?Java SOAPEnvelope.serialize怎么用?Java SOAPEnvelope.serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.axiom.soap.SOAPEnvelope
的用法示例。
在下文中一共展示了SOAPEnvelope.serialize方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendSOAPResponse
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
public static String sendSOAPResponse(HttpServletResponse response, OMElement resultElements) {
try {
SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope responseEnvelope = soapFactory.createSOAPEnvelope();
SOAPBody responseBody = soapFactory.createSOAPBody();
responseBody.addChild(resultElements);
responseEnvelope.addChild(responseBody);
// log the response message
if (Debug.infoOn()) {
Debug.logInfo("SOAP Response Message:\n" + responseEnvelope + "\n", module);
}
response.setContentType(SoapService.XML_TYPE);
OutputStream out = response.getOutputStream();
responseEnvelope.serialize(out);
out.flush();
}
catch (Exception ex) {
Debug.logError("Error invoking soap service " + ex.getMessage(), module);
return "error";
}
return "success";
}
示例2: testConvertToDOOM
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
public void testConvertToDOOM() throws Exception {
String xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soapenv:Body><ns1:createAccountRequest xmlns:ns1=\"http://www.wso2.com/types\">" +
"<clientinfo xmlns=\"http://www.wso2.com/types\"><name>bob</name><ssn>123456789</ssn></clientinfo>" +
"<password xmlns=\"\">passwd</password></ns1:createAccountRequest></soapenv:Body></soapenv:Envelope>";
StAXSOAPModelBuilder builder2 = new StAXSOAPModelBuilder(
getTestEnvelope().getXMLStreamReader(),
DOOMAbstractFactory.getSOAP11Factory(),
SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
SOAPEnvelope envelope = builder2.getSOAPEnvelope();
envelope.build();
StringWriter writer = new StringWriter();
envelope.serialize(writer);
writer.flush();
String s2 = writer.toString();
assertXMLEqual(s2, xml);
}
示例3: testSerializeDeserializeUsingMTOMWithoutOptimize
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
private static void testSerializeDeserializeUsingMTOMWithoutOptimize(Object bean, Object expectedResult) throws Exception {
SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
envelope.getBody().addChild(ADBBeanUtil.getOMElement(bean));
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
OMOutputFormat format = new OMOutputFormat();
MultipartWriter mpWriter = JavaMailMultipartWriterFactory.INSTANCE.createMultipartWriter(buffer, format.getMimeBoundary());
OutputStream rootPartWriter = mpWriter.writePart("application/xop+xml; charset=UTF-8; type=\"text/xml\"", "binary", format.getRootContentId());
envelope.serialize(rootPartWriter, format);
rootPartWriter.close();
mpWriter.complete();
// System.out.write(buffer.toByteArray());
String contentType = format.getContentTypeForMTOM("text/xml");
Attachments attachments = new Attachments(new ByteArrayInputStream(buffer.toByteArray()), contentType);
MTOMStAXSOAPModelBuilder builder = new MTOMStAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(attachments.getSOAPPartInputStream()), attachments);
OMElement bodyElement = builder.getSOAPEnvelope().getBody().getFirstElement();
assertBeanEquals(expectedResult, ADBBeanUtil.parse(bean.getClass(), bodyElement.getXMLStreamReaderWithoutCaching()));
}
示例4: testMessageBuilingFromByteArray
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
public void testMessageBuilingFromByteArray() throws Exception {
SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
SOAPEnvelope env = fac.createSOAPEnvelope();
fac.createSOAPBody(env);
env.getBody().addChild(fac.createOMElement("test", "http://t", "t"));
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
try {
env.serialize(outStream);
MessageFactory mf = MessageFactory.newInstance();
mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(outStream.toByteArray()));
} catch (Exception e) {
e.printStackTrace();
assertTrue(true);
}
}
示例5: sendError
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
private void sendError(HttpServletResponse res, Object object, String serviceName) throws EventHandlerException {
try {
// setup the response
res.setContentType("text/xml");
String xmlResults= SoapSerializer.serialize(object);
XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlResults));
StAXOMBuilder resultsBuilder = new StAXOMBuilder(xmlReader);
OMElement resultSer = resultsBuilder.getDocumentElement();
// create the response soap
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope resEnv = factory.createSOAPEnvelope();
SOAPBody resBody = factory.createSOAPBody();
OMElement errMsg = factory.createOMElement(new QName((serviceName != null ? serviceName : "") + "Response"));
errMsg.addChild(resultSer.getFirstElement());
resBody.addChild(errMsg);
resEnv.addChild(resBody);
// The declareDefaultNamespace method doesn't work see (https://issues.apache.org/jira/browse/AXIS2-3156)
// so the following doesn't work:
// resService.declareDefaultNamespace(ModelService.TNS);
// instead, create the xmlns attribute directly:
OMAttribute defaultNS = factory.createOMAttribute("xmlns", null, ModelService.TNS);
errMsg.addAttribute(defaultNS);
// log the response message
if (Debug.verboseOn()) {
try {
Debug.logInfo("Response Message:\n" + resEnv + "\n", module);
} catch (Throwable t) {
}
}
resEnv.serialize(res.getOutputStream());
res.getOutputStream().flush();
} catch (Exception e) {
throw new EventHandlerException(e.getMessage(), e);
}
}
示例6: sendError
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
private void sendError(HttpServletResponse res, Map<String, Object> object, String serviceName) throws EventHandlerException {
try {
// setup the response
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
res.setContentType("text/xml");
OMElement resultSer = SoapService.serializeParamsToXML(
factory.createOMElement(serviceName + "Response",
factory.createOMNamespace(ModelService.TNS, "tns")), object);
// create the response soap
SOAPEnvelope resEnv = factory.createSOAPEnvelope();
SOAPBody resBody = factory.createSOAPBody();
resBody.addChild(resultSer);
resEnv.addChild(resBody);
// log the response message
if (Debug.verboseOn()) {
try {
Debug.logInfo("Response Message:\n" + resEnv + "\n", module);
} catch (Throwable t) {
}
}
resEnv.serialize(res.getOutputStream());
res.getOutputStream().flush();
} catch (Exception e) {
throw new EventHandlerException(e.getMessage(), e);
}
}
示例7: testUserMessageOnly
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
/**
* Test of creating the SOAP header for one user message only
*/
@Test
public void testUserMessageOnly() {
final SOAPEnvelope env = SOAPEnv.createEnvelope(SOAPEnv.SOAPVersion.SOAP_12);
final SOAPHeaderBlock messaging = Messaging.createElement(env);
MessageMetaData mmd = TestUtils.getMMD("packagetest/mmd_pcktest.xml", this);
final OMElement umElement = UserMessageElement.createElement(messaging, mmd);
// The SOAP enveloppe should be valid according to the ebMS schema, write the
// xml to file and validate it using Xerces
final String xmlPath = TestUtils.getPath(this.getClass(), "packagetest") + "/xml_testUserMessageOnly.xml";
final File xmlFile = new File(xmlPath);
try {
final XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileWriter(xmlFile));
env.serialize(writer);
writer.flush();
} catch (final XMLStreamException xse) {
Logger.getLogger(PackagingTest.class.getName()).log(Level.SEVERE, null, xse);
fail();
} catch (final IOException ex) {
Logger.getLogger(PackagingTest.class.getName()).log(Level.SEVERE, null, ex);
fail();
}
assertValidXML(xmlPath);
}
示例8: testConvertToDOOM2
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
public void testConvertToDOOM2() throws Exception {
String xml =
"<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header /><soapenv:Body><ns1:createAccountRequest xmlns:ns1=\"http://www.wso2.com/types\"><ns1:clientinfo><name xmlns=\"\">bob</name><ssn xmlns=\"\">123456789</ssn></ns1:clientinfo><password xmlns=\"\">passwd</password></ns1:createAccountRequest></soapenv:Body></soapenv:Envelope>";
CreateAccountRequest request = new CreateAccountRequest();
ClientInfo clientInfo = new ClientInfo();
clientInfo.setName("bob");
clientInfo.setSsn("123456789");
request.setClientInfo(clientInfo);
request.setPassword("passwd");
ADBSOAPModelBuilder builder = new ADBSOAPModelBuilder(request
.getPullParser(CreateAccountRequest.MY_QNAME),
OMAbstractFactory.getSOAP11Factory());
SOAPEnvelope env = builder.getEnvelope();
StAXSOAPModelBuilder builder2 = new StAXSOAPModelBuilder(
getTestEnvelope().getXMLStreamReaderWithoutCaching(),
DOOMAbstractFactory.getSOAP11Factory(),
SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
SOAPEnvelope envelope = builder2.getSOAPEnvelope();
envelope.build();
StringWriter writer = new StringWriter();
envelope.serialize(writer);
writer.flush();
XMLStreamReader r = StAXUtils.createXMLStreamReader(new StringReader(writer.toString()));
PrintEvents.print(r);
//TODO: FIXME. Simpler test in testPrintEvents2
//assertXMLEqual(writer.toString(),xml);
}
示例9: writeTo
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
/**
* Writes this <CODE>SOAPMessage</CODE> object to the given output stream. The externalization
* format is as defined by the SOAP 1.1 with Attachments specification.
* <p/>
* <P>If there are no attachments, just an XML stream is written out. For those messages that
* have attachments, <CODE>writeTo</CODE> writes a MIME-encoded byte stream.</P>
*
* @param out the <CODE>OutputStream</CODE> object to which this <CODE>SOAPMessage</CODE> object
* will be written
* @throws SOAPException if there was a problem in externalizing this SOAP message
* @throws IOException if an I/O error occurs
*/
public void writeTo(OutputStream out) throws SOAPException, IOException {
try {
OMOutputFormat format = new OMOutputFormat();
String enc = (String)getProperty(CHARACTER_SET_ENCODING);
format.setCharSetEncoding(enc != null ? enc : OMOutputFormat.DEFAULT_CHAR_SET_ENCODING);
String writeXmlDecl = (String)getProperty(WRITE_XML_DECLARATION);
if (writeXmlDecl == null || writeXmlDecl.equals("false")) {
//SAAJ default case doesn't send XML decl
format.setIgnoreXMLDeclaration(true);
}
SOAPEnvelope envelope = ((SOAPEnvelopeImpl)soapPart.getEnvelope()).getOMEnvelope();
if (attachmentParts.isEmpty()) {
envelope.serialize(out, format);
} else {
format.setSOAP11(((SOAPEnvelopeImpl)soapPart.getEnvelope()).getOMFactory()
instanceof SOAP11Factory);
OMMultipartWriter mpw = new OMMultipartWriter(out, format);
OutputStream rootPartOutputStream = mpw.writeRootPart();
envelope.serialize(rootPartOutputStream);
rootPartOutputStream.close();
for (AttachmentPart ap : attachmentParts) {
mpw.writePart(ap.getDataHandler(), ap.getContentId());
}
mpw.complete();
}
saveChanges();
} catch (Exception e) {
throw new SOAPException(e);
}
}
示例10: testSerializeDeserializeUsingMTOM
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
private static void testSerializeDeserializeUsingMTOM(Object bean, Object expectedResult, boolean cache) throws Exception {
SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
envelope.getBody().addChild(ADBBeanUtil.getOMElement(bean));
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
envelope.serialize(buffer, format);
// envelope.serialize(System.out, format);
String contentType = format.getContentTypeForMTOM("text/xml");
Attachments attachments = new Attachments(new ByteArrayInputStream(buffer.toByteArray()), contentType);
assertEquals(countDataHandlers(bean) + 1, attachments.getAllContentIDs().length);
MTOMStAXSOAPModelBuilder builder = new MTOMStAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(attachments.getSOAPPartInputStream()), attachments);
OMElement bodyElement = builder.getSOAPEnvelope().getBody().getFirstElement();
assertBeanEquals(expectedResult, ADBBeanUtil.parse(bean.getClass(), cache ? bodyElement.getXMLStreamReader() : bodyElement.getXMLStreamReaderWithoutCaching()));
}
示例11: createAndSendSOAPResponse
import org.apache.axiom.soap.SOAPEnvelope; //导入方法依赖的package包/类
private void createAndSendSOAPResponse(Map<String, Object> serviceResults, String serviceName, HttpServletResponse response) throws EventHandlerException {
try {
// setup the response
Debug.logVerbose("[EventHandler] : Setting up response message", module);
String xmlResults = SoapSerializer.serialize(serviceResults);
//Debug.logInfo("xmlResults ==================" + xmlResults, module);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlResults));
StAXOMBuilder resultsBuilder = new StAXOMBuilder(reader);
OMElement resultSer = resultsBuilder.getDocumentElement();
// create the response soap
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope resEnv = factory.createSOAPEnvelope();
SOAPBody resBody = factory.createSOAPBody();
OMElement resService = factory.createOMElement(new QName(serviceName + "Response"));
resService.addChild(resultSer.getFirstElement());
resBody.addChild(resService);
resEnv.addChild(resBody);
// The declareDefaultNamespace method doesn't work see (https://issues.apache.org/jira/browse/AXIS2-3156)
// so the following doesn't work:
// resService.declareDefaultNamespace(ModelService.TNS);
// instead, create the xmlns attribute directly:
OMAttribute defaultNS = factory.createOMAttribute("xmlns", null, ModelService.TNS);
resService.addAttribute(defaultNS);
// log the response message
if (Debug.verboseOn()) {
try {
Debug.logInfo("Response Message:\n" + resEnv + "\n", module);
} catch (Throwable t) {
}
}
resEnv.serialize(response.getOutputStream());
response.getOutputStream().flush();
} catch (Exception e) {
Debug.logError(e, module);
throw new EventHandlerException(e.getMessage(), e);
}
}