use of javax.activation.DataHandler in project webservices-axiom by apache.
the class DataHandlerWrapperTest method test.
public void test() {
DataHandler dataHandler = new DataHandler("<root/>", "text/plain; charset=UTF-8");
DataHandler wrapper = new DataHandlerWrapper(dataHandler);
assertEquals(dataHandler.getContentType(), wrapper.getContentType());
assertEquals(dataHandler.getName(), wrapper.getName());
assertSame(dataHandler.getDataSource(), wrapper.getDataSource());
}
use of javax.activation.DataHandler in project webservices-axiom by apache.
the class XMLStreamReaderUtilsTest method testGetDataHandlerFromElementWithZeroLength.
private void testGetDataHandlerFromElementWithZeroLength(boolean useDHR) throws Exception {
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<test/>"));
if (useDHR) {
reader = new XMLStreamReaderWithDataHandlerReader(reader);
}
try {
reader.next();
// Check precondition
assertTrue(reader.isStartElement());
DataHandler dh = XMLStreamReaderUtils.getDataHandlerFromElement(reader);
// Check postcondition
assertTrue(reader.isEndElement());
assertEquals(-1, dh.getInputStream().read());
} finally {
reader.close();
}
}
use of javax.activation.DataHandler in project webservices-axiom by apache.
the class TestDataHandlerExpansion method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
DataHandler dh = new DataHandler("some content", "text/plain");
DocumentBean object = new DocumentBean();
object.setId("123456");
object.setContent(dh);
OMElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
OMElement child = (OMElement) element.getFirstOMChild();
assertEquals("id", child.getLocalName());
assertEquals("123456", child.getText());
child = (OMElement) child.getNextOMSibling();
assertEquals("content", child.getLocalName());
OMText content = (OMText) child.getFirstOMChild();
assertTrue(content.isBinary());
assertTrue(content.isOptimized());
assertSame(dh, content.getDataHandler());
}
use of javax.activation.DataHandler in project webservices-axiom by apache.
the class TestDataHandlerSerializationWithoutMTOM method runTest.
@Override
protected void runTest() throws Throwable {
SOAPFactory factory = metaFactory.getSOAP11Factory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
// Construct the original message
DocumentBean orgObject = new DocumentBean();
orgObject.setId("123456");
orgObject.setContent(new DataHandler("some content", "text/plain; charset=utf-8"));
SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, orgObject));
orgEnvelope.getBody().addChild(element);
// Serialize the message
ByteArrayOutputStream out = new ByteArrayOutputStream();
orgEnvelope.serialize(out);
assertFalse(element.isExpanded());
SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(new ByteArrayInputStream(out.toByteArray()), null).getSOAPEnvelope();
DocumentBean object = (DocumentBean) context.createUnmarshaller().unmarshal(envelope.getBody().getFirstElement().getXMLStreamReader(false));
assertEquals("some content", IOUtils.toString(object.getContent().getInputStream(), "utf-8"));
}
use of javax.activation.DataHandler in project webservices-axiom by apache.
the class BufferUtilsTest method testByteArrayDataSourceBackedDataHandlerExceedLimit.
public void testByteArrayDataSourceBackedDataHandlerExceedLimit() throws Exception {
String str = "This is a test String";
byte[] b = str.getBytes();
ByteArrayDataSource bads = new ByteArrayDataSource(b, "text/plain");
DataHandler dh = new DataHandler(bads);
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);
}
Aggregations