use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class MTOMStAXSOAPModelBuilderTest method testUTF16MTOMMessage.
public void testUTF16MTOMMessage() throws Exception {
String contentTypeString = "multipart/Related; charset=\"UTF-8\"; type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; start=\"SOAPPart\"";
String cid = "1.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org";
String xmlPlusMime1 = "------=_AxIs2_Def_boundary_=42214532\r\n" + "Content-Type: application/xop+xml; charset=UTF-16; type=\"application/soap+xml\"\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "Content-ID: SOAPPart\r\n" + "\r\n";
String xmlPlusMime2 = "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"><soapenv:Body><m:data xmlns:m=\"http://www.example.org/stuff\"><m:name m:contentType=\"text/plain\"><xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"cid:" + cid + "\"></xop:Include></m:name></m:data></soapenv:Body></soapenv:Envelope>\r\n";
String xmlPlusMime3 = "\r\n------=_AxIs2_Def_boundary_=42214532\r\n" + "Content-Transfer-Encoding: binary\r\n" + "Content-ID: " + cid + "\r\n" + "\r\n" + "Foo Bar\r\n" + "------=_AxIs2_Def_boundary_=42214532--\r\n";
byte[] bytes1 = xmlPlusMime1.getBytes();
byte[] bytes2 = xmlPlusMime2.getBytes("UTF-16");
byte[] bytes3 = xmlPlusMime3.getBytes();
byte[] full = append(bytes1, bytes2);
full = append(full, bytes3);
InputStream inStream = new BufferedInputStream(new ByteArrayInputStream(full));
Attachments attachments = new Attachments(inStream, contentTypeString);
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments);
OMElement root = builder.getDocumentElement();
root.build();
}
use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class FirstElementNameWithParserTestCase method runTest.
@Override
protected final void runTest() throws Throwable {
SOAPEnvelope orgEnvelope = soapFactory.getDefaultEnvelope();
orgEnvelope.getBody().addChild(soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()));
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(orgEnvelope.toString()));
SOAPBody body = builder.getSOAPEnvelope().getBody();
runTest(body);
if (supportsOptimization) {
// The expectation is that even after looking at the payload element name, registering
// a custom builder still transforms the element.
((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new CustomBuilder() {
@Override
public OMDataSource create(OMElement element) throws OMException {
try {
element.getXMLStreamReaderWithoutCaching().close();
} catch (XMLStreamException ex) {
throw new OMException(ex);
}
return new AbstractPushOMDataSource() {
@Override
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
xmlWriter.writeEmptyElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
}
@Override
public boolean isDestructiveWrite() {
return false;
}
};
}
});
assertThat(body.getFirstElement()).isInstanceOf(OMSourcedElement.class);
}
}
use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class TestGetFirstElementLocalNameWithParserNoLookahead method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope orgEnvelope = soapFactory.getDefaultEnvelope();
OMElement payload = soapFactory.createOMElement("payload", soapFactory.createOMNamespace("urn:test", "p"), orgEnvelope.getBody());
OMElement child = soapFactory.createOMElement("child", null, payload);
soapFactory.createOMElement("grandchild", null, child);
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(orgEnvelope.toString()));
SOAPBody body = builder.getSOAPEnvelope().getBody();
body.getFirstElement().getFirstElement();
assertThat(body.getFirstElementLocalName()).isEqualTo("payload");
}
Aggregations