use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class SwANoMimeServiceImpl method echoDataRef.
public void echoDataRef(Holder<DataStruct> data) {
try {
InputStream bis = null;
bis = data.value.getDataRef().getDataSource().getInputStream();
byte[] b = new byte[6];
bis.read(b, 0, 6);
String string = IOUtils.newStringFromBytes(b);
ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream");
data.value.setDataRef(new DataHandler(source));
} catch (IOException e) {
e.printStackTrace();
}
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class ClientMtomXopWithJMSTest method testMtomXop.
@Test
public void testMtomXop() throws Exception {
TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class, true);
InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl");
int fileSize = 0;
for (int i = pre.read(); i != -1; i = pre.read()) {
fileSize++;
}
Holder<DataHandler> param = new Holder<>();
int count = 50;
byte[] data = new byte[fileSize * count];
for (int x = 0; x < count; x++) {
this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data, fileSize * x, fileSize);
}
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
Holder<String> name = new Holder<>("call detail");
mtomPort.testXop(name, param);
// TODO Why should it fail here?
// Assert.fail("Expect the exception here !");
Assert.assertEquals("name unchanged", "return detail + call detail", name.value);
Assert.assertNotNull(param.value);
param.value.getInputStream().close();
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class ClientMtomXopTest method testMtomWithValidationErrorOnServer.
@Test
public void testMtomWithValidationErrorOnServer() throws Exception {
TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class, true, true);
try {
Holder<DataHandler> param = new Holder<>();
Holder<String> name;
InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl");
int fileSize = 0;
for (int i = pre.read(); i != -1; i = pre.read()) {
fileSize++;
}
int count = 1;
byte[] data = new byte[fileSize * count];
for (int x = 0; x < count; x++) {
this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data, fileSize * x, fileSize);
}
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
// name length > 80 to break the schema
// will throw exception on server side
name = new Holder<>("break schema");
ClientProxy.getClient(mtomPort).getInInterceptors().add(new LoggingInInterceptor());
ClientProxy.getClient(mtomPort).getOutInterceptors().add(new LoggingOutInterceptor());
((HTTPConduit) ClientProxy.getClient(mtomPort).getConduit()).getClient().setReceiveTimeout(60000);
mtomPort.testXop(name, param);
fail("should throw javax.xml.ws.soap.SOAPFaultException");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
} catch (Exception ex) {
fail("should throw javax.xml.ws.soap.SOAPFaultException");
}
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class ClientMtomXopTest method testMtomXopProvider.
@Test
public void testMtomXopProvider() throws Exception {
TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT_PROVIDER, TestMtom.class, true, true);
try {
Holder<DataHandler> param = new Holder<>();
Holder<String> name;
byte[] bytes;
InputStream in;
InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl");
int fileSize = 0;
for (int i = pre.read(); i != -1; i = pre.read()) {
fileSize++;
}
int count = 50;
byte[] data = new byte[fileSize * count];
for (int x = 0; x < count; x++) {
this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data, fileSize * x, fileSize);
}
Object[] validationTypes = new Object[] { Boolean.TRUE, SchemaValidationType.IN, SchemaValidationType.BOTH };
for (Object validationType : validationTypes) {
((BindingProvider) mtomPort).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, validationType);
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
name = new Holder<>("call detail");
mtomPort.testXop(name, param);
assertEquals("name unchanged", "return detail + call detail", name.value);
assertNotNull(param.value);
in = param.value.getInputStream();
bytes = IOUtils.readBytesFromStream(in);
assertEquals(data.length, bytes.length);
in.close();
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
name = new Holder<>("call detail");
mtomPort.testXop(name, param);
assertEquals("name unchanged", "return detail + call detail", name.value);
assertNotNull(param.value);
in = param.value.getInputStream();
bytes = IOUtils.readBytesFromStream(in);
assertEquals(data.length, bytes.length);
in.close();
}
validationTypes = new Object[] { Boolean.FALSE, SchemaValidationType.OUT, SchemaValidationType.NONE };
for (Object validationType : validationTypes) {
((BindingProvider) mtomPort).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, validationType);
SAAJOutInterceptor saajOut = new SAAJOutInterceptor();
SAAJInInterceptor saajIn = new SAAJInInterceptor();
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
name = new Holder<>("call detail");
mtomPort.testXop(name, param);
assertEquals("name unchanged", "return detail + call detail", name.value);
assertNotNull(param.value);
in = param.value.getInputStream();
bytes = IOUtils.readBytesFromStream(in);
assertEquals(data.length, bytes.length);
in.close();
ClientProxy.getClient(mtomPort).getInInterceptors().add(saajIn);
ClientProxy.getClient(mtomPort).getInInterceptors().add(saajOut);
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
name = new Holder<>("call detail");
mtomPort.testXop(name, param);
assertEquals("name unchanged", "return detail + call detail", name.value);
assertNotNull(param.value);
in = param.value.getInputStream();
bytes = IOUtils.readBytesFromStream(in);
assertEquals(data.length, bytes.length);
in.close();
ClientProxy.getClient(mtomPort).getInInterceptors().remove(saajIn);
ClientProxy.getClient(mtomPort).getInInterceptors().remove(saajOut);
}
} catch (UndeclaredThrowableException ex) {
throw (Exception) ex.getCause();
} catch (Exception ex) {
System.out.println(System.getProperties());
throw ex;
}
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class TestMtomProviderImpl method invoke.
public SOAPMessage invoke(final SOAPMessage request) {
try {
System.out.println("=== Received client request ===");
// create the SOAPMessage
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPBodyElement testResponse = body.addBodyElement(envelope.createName("testXopResponse", null, "http://cxf.apache.org/mime/types"));
SOAPElement name = testResponse.addChildElement("name", null, "http://cxf.apache.org/mime/types");
name.setTextContent("return detail + call detail");
SOAPElement attachinfo = testResponse.addChildElement("attachinfo", null, "http://cxf.apache.org/mime/types");
SOAPElement include = attachinfo.addChildElement("Include", "xop", "http://www.w3.org/2004/08/xop/include");
int fileSize = 0;
try (InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl")) {
for (int i = pre.read(); i != -1; i = pre.read()) {
fileSize++;
}
}
int count = 50;
byte[] data = new byte[fileSize * count];
for (int x = 0; x < count; x++) {
this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data, fileSize * x, fileSize);
}
DataHandler dh = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
// create the image attachment
AttachmentPart attachment = message.createAttachmentPart(dh);
attachment.setContentId("mtom_xop.wsdl");
message.addAttachmentPart(attachment);
System.out.println("Adding attachment: " + attachment.getContentId() + ":" + attachment.getSize());
// add the reference to the image attachment
include.addAttribute(envelope.createName("href"), "cid:" + attachment.getContentId());
return message;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations