use of javax.activation.DataHandler in project webservices-axiom by apache.
the class BufferUtilsTest method testObjectBackedDataHandlerExceedLimit.
public void testObjectBackedDataHandlerExceedLimit() throws Exception {
String str = "This is a test String";
DataHandler dh = new DataHandler(str, "text/plain");
int unsupported = BufferUtils.doesDataHandlerExceedLimit(dh, 0);
assertEquals(-1, unsupported);
int doesExceed = BufferUtils.doesDataHandlerExceedLimit(dh, 10);
assertEquals(1, doesExceed);
int doesNotExceed = BufferUtils.doesDataHandlerExceedLimit(dh, 100);
assertEquals(0, doesNotExceed);
}
use of javax.activation.DataHandler in project webservices-axiom by apache.
the class TestMTOMForwardStreaming method runTest.
@Override
protected void runTest() throws Throwable {
DataSource ds1 = new TestDataSource('A', Runtime.getRuntime().maxMemory());
DataSource ds2 = new TestDataSource('B', Runtime.getRuntime().maxMemory());
// Programmatically create the original message
SOAPFactory factory = metaFactory.getSOAP12Factory();
final SOAPEnvelope orgEnvelope = factory.createSOAPEnvelope();
SOAPBody orgBody = factory.createSOAPBody(orgEnvelope);
OMElement orgBodyElement = factory.createOMElement("test", factory.createOMNamespace("urn:test", "p"), orgBody);
OMElement orgData1 = factory.createOMElement("data", null, orgBodyElement);
orgData1.addChild(factory.createOMText(new DataHandler(ds1), true));
OMElement orgData2 = factory.createOMElement("data", null, orgBodyElement);
orgData2.addChild(factory.createOMText(new DataHandler(ds2), true));
final OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
format.setSOAP11(false);
final String contentType = format.getContentType();
final PipedOutputStream pipe1Out = new PipedOutputStream();
final PipedInputStream pipe1In = new PipedInputStream(pipe1Out);
// Create the producer thread (simulating the client sending the MTOM message)
Thread producerThread = new Thread(new Runnable() {
@Override
public void run() {
try {
try {
orgEnvelope.serialize(pipe1Out, format);
} finally {
pipe1Out.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
producerThread.start();
final PipedOutputStream pipe2Out = new PipedOutputStream();
PipedInputStream pipe2In = new PipedInputStream(pipe2Out);
// Create the forwarder thread (simulating the mediation engine that forwards the message)
Thread forwarderThread = new Thread(new Runnable() {
@Override
public void run() {
try {
try {
MultipartBody mb = MultipartBody.builder().setInputStream(pipe1In).setContentType(contentType).build();
SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb).getSOAPEnvelope();
// the element is built. Therefore we need two different test executions.
if (buildSOAPPart) {
envelope.build();
}
// Usage of serializeAndConsume should enable streaming
envelope.serializeAndConsume(pipe2Out, format);
} finally {
pipe2Out.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
forwarderThread.start();
try {
MultipartBody mb = MultipartBody.builder().setInputStream(pipe2In).setContentType(contentType).build();
SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb).getSOAPEnvelope();
OMElement bodyElement = envelope.getBody().getFirstElement();
Iterator<OMElement> it = bodyElement.getChildElements();
OMElement data1 = it.next();
OMElement data2 = it.next();
IOTestUtils.compareStreams(ds1.getInputStream(), ((PartDataHandler) ((OMText) data1.getFirstOMChild()).getDataHandler()).getPart().getInputStream(false));
IOTestUtils.compareStreams(ds2.getInputStream(), ((PartDataHandler) ((OMText) data2.getFirstOMChild()).getDataHandler()).getPart().getInputStream(false));
} finally {
pipe2In.close();
}
}
use of javax.activation.DataHandler in project podam by devopsfolks.
the class AbnormalPojosTest method podamShouldHandlePojosWithAMixOfCircularAndNonCircularConstructors.
@Test
@Title("Invoking Podam on a POJO with both circular and non circular constructors (e.g. javax.activation.DataHandler) should lead to a non empty POJO")
public void podamShouldHandlePojosWithAMixOfCircularAndNonCircularConstructors() throws Exception {
PodamFactory podamFactory = podamFactorySteps.givenAStandardPodamFactory();
DataHandler pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(DataHandler.class, podamFactory);
podamValidationSteps.theObjectShouldNotBeNull(pojo);
}
use of javax.activation.DataHandler in project camel by apache.
the class SoapAttachmentResponseProcessor method process.
public void process(Exchange exchange) throws Exception {
exchange.setOut(exchange.getIn());
exchange.getOut().addAttachment("responseAttachment1.txt", new DataHandler("responseAttachment1", "text/plain"));
exchange.getOut().addAttachment("responseAttachment2.xml", new DataHandler("<responseAttachment2/>", "application/xml"));
}
use of javax.activation.DataHandler in project camel by apache.
the class StringTemplateTest method test.
@Test
public void test() throws Exception {
final DataHandler dataHandler = new DataHandler("my attachment", "text/plain");
Exchange response = template.request("direct:a", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().addAttachment("item", dataHandler);
exchange.getIn().setBody("Monday");
exchange.getIn().setHeader("name", "Christian");
exchange.setProperty("item", "7");
}
});
assertEquals("Dear Christian. You ordered item 7 on Monday.", response.getOut().getBody());
assertEquals("org/apache/camel/component/stringtemplate/template.tm", response.getOut().getHeader(StringTemplateConstants.STRINGTEMPLATE_RESOURCE_URI));
assertEquals("Christian", response.getOut().getHeader("name"));
assertSame(dataHandler, response.getOut().getAttachment("item"));
}
Aggregations