use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class SourceMessageTester method testWriteSOAP11MessagePayloadToXMLStreamWriter.
public void testWriteSOAP11MessagePayloadToXMLStreamWriter() {
Message msg = createPayloadSourceMessage();
ByteArrayBuffer baos = new ByteArrayBuffer();
XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
try {
msg.writePayloadTo(writer);
writer.flush();
Transformer transformer = XmlUtil.newTransformer();
StreamSource source = new StreamSource(baos.newInputStream());
DOMResult domResult = new DOMResult();
transformer.transform(source, domResult);
Node n = domResult.getNode().getFirstChild();
assertTrue(n.getLocalName().equals("Body") && n.getNamespaceURI().equals("urn:test:types"));
Node c = n.getFirstChild();
assertTrue(c.getLocalName().equals("value") && c.getNamespaceURI().equals("urn:test:types"));
assertTrue(c.getFirstChild().getNodeValue().equals("Its Body"));
} catch (XMLStreamException e) {
e.printStackTrace();
assertTrue(false);
} catch (TransformerException e) {
e.printStackTrace();
assertTrue(false);
}
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class WSDLGen method run.
public static int run() throws Exception {
if (!useLocal()) {
return 0;
}
String outputDir = System.getProperty("tempdir");
if (outputDir == null) {
System.err.println("**** Set tempdir system property ****");
return -1;
}
String riFile = outputDir + "/WEB-INF/sun-jaxws.xml";
DeploymentDescriptorParser<WSEndpoint> parser = new DeploymentDescriptorParser<WSEndpoint>(Thread.currentThread().getContextClassLoader(), new FileSystemResourceLoader(new File(outputDir)), null, new AdapterFactory<WSEndpoint>() {
public WSEndpoint createAdapter(String name, String urlPattern, WSEndpoint<?> endpoint) {
return endpoint;
}
});
List<WSEndpoint> endpoints = parser.parse(new File(riFile));
final String addr = new File(outputDir).toURL().toExternalForm();
// file:// -> local://
final String address = "local" + addr.substring(4);
for (WSEndpoint endpoint : endpoints) {
ServiceDefinition def = endpoint.getServiceDefinition();
if (def == null) {
continue;
}
SDDocument primary = def.getPrimary();
File file = new File(primary.getURL().toURI());
if (file.exists()) {
System.out.println("**** Primary WSDL " + file + " already exists - not generating any WSDL artifacts ****");
// Primary WSDL already exists
continue;
}
for (SDDocument doc : def) {
int index = doc.getURL().getFile().indexOf("/WEB-INF/wsdl");
String name = "";
if (index == -1)
name = outputDir + "/WEB-INF/wsdl" + doc.getURL().getFile();
else
name = doc.getURL().getFile();
System.out.println("Creating WSDL artifact=" + name);
ByteArrayBuffer buffer = new ByteArrayBuffer();
doc.writeTo(new PortAddressResolver() {
public String getAddressFor(QName serviceName, String portName) {
return address;
}
}, new DocumentAddressResolver() {
public String getRelativeAddressFor(SDDocument current, SDDocument referenced) {
String rel = referenced.getURL().toExternalForm();
// remove file:/
return rel.substring(6);
}
}, buffer);
FileOutputStream fos = new FileOutputStream(name);
buffer.writeTo(fos);
fos.close();
}
}
return 0;
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class AttachmentHelper method getBytes.
private static byte[] getBytes(InputStream is) throws IOException {
ByteArrayBuffer bab = new ByteArrayBuffer();
bab.write(is);
return bab.toByteArray();
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class ReferenceParametersTest method testFaultToReferenceParametersJAXBMessage1.
public void testFaultToReferenceParametersJAXBMessage1() throws Exception {
String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:user=\"http://foo.bar\" " + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + "<S:Header>" + "<wsa:Action>http://example.org/action/echoIn</wsa:Action>" + "<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "<wsa:MessageID>urn:uuid:1234567890</wsa:MessageID>" + "<wsa:FaultTo>" + "<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>" + "<wsa:ReferenceParameters>" + "<user:foo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter='true'>bar</user:foo>" + "<user:bar xmlns:user=\"http://foo.bar\">" + "<user:foobar>barfoo</user:foobar>" + "</user:bar>" + "</wsa:ReferenceParameters>" + "</wsa:FaultTo>" + "</S:Header>" + "<S:Body><DataType xmlns=\"http://foo.org/xsd\"><param>foo bar</param></DataType></S:Body></S:Envelope>";
Message message = useStreamCodec(requestStr);
WSEndpointReference wsepr = message.getHeaders().getFaultTo(AddressingVersion.W3C, SOAPVersion.SOAP_11);
Message m2 = Messages.create("Test Unsupported", AddressingVersion.W3C, SOAPVersion.SOAP_11);
wsepr.addReferenceParametersToList(m2.getHeaders());
ByteArrayBuffer baos = new ByteArrayBuffer();
XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
m2.writeTo(writer);
writer.flush();
XMLInputFactory readerFactory = XMLInputFactory.newInstance();
XMLStreamReader reader = readerFactory.createXMLStreamReader(baos.newInputStream());
Message sm = Messages.create(reader);
Packet sm_packet = new Packet(sm);
List<Element> refParams = sm_packet.getReferenceParameters();
assertEquals("Did n't get expected ReferenceParameters", 2, refParams.size());
for (Element e : refParams) {
assertTrue("isReferenceParameter attribute not present on header", e.getAttributeNodeNS(W3CAddressingConstants.WSA_NAMESPACE_NAME, "IsReferenceParameter") != null);
assertEquals("NS Decl did not match", "http://foo.bar", e.getNamespaceURI());
}
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class StreamMessageTest method testMessageWriteTo.
/**
* jax-ws issue 610
* @throws Exception
*/
public void testMessageWriteTo() throws Exception {
String soapMsg = "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<Header>" + "</Header>" + "<Body>" + "<GetCountryCodesResponse xmlns='http://www.strikeiron.com'> <GetCountryCodesResult/></GetCountryCodesResponse>" + "</Body>" + "</Envelope>";
Message message = createSOAP11StreamMessage(soapMsg);
ByteArrayBuffer baos = new ByteArrayBuffer();
XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
message.writeTo(writer);
writer.flush();
baos.writeTo(System.out);
}
Aggregations