use of javax.activation.FileDataSource in project webservices-axiom by apache.
the class TextHelperTest method test_fromOMText.
/**
* Test the OMText -> StringBuffer code
* @throws Exception
*/
public void test_fromOMText() throws Exception {
OMFactory factory = OMAbstractFactory.getOMFactory();
FileDataSource fds = new FileDataSource(file);
DataHandler dh = new DataHandler(fds);
OMText omText = factory.createOMText(dh, true);
StringBuffer buffer = new StringBuffer();
TextHelper.toStringBuffer(omText, buffer);
assertTrue(buffer.length() > SIZE);
String text = buffer.toString();
assertTrue(text.length() == EXPECTED_BASE64_SIZE);
assertTrue(text.startsWith(EXPECTED_STARTS_WITH));
}
use of javax.activation.FileDataSource in project webservices-axiom by apache.
the class BufferUtilsTest method testDataSourceBackedDataHandlerExceedLimit.
public void testDataSourceBackedDataHandlerExceedLimit() throws IOException {
File file = File.createTempFile("bufferUtils", "tst");
file.deleteOnExit();
try {
RandomAccessFile raf = new RandomAccessFile(file, "rw");
try {
raf.setLength(5000);
} finally {
raf.close();
}
FileDataSource fds = new FileDataSource(file);
DataHandler dh = new DataHandler(fds);
int unsupported = BufferUtils.doesDataHandlerExceedLimit(dh, 0);
assertEquals(-1, unsupported);
int doesExceed = BufferUtils.doesDataHandlerExceedLimit(dh, 1000);
assertEquals(1, doesExceed);
int doesNotExceed = BufferUtils.doesDataHandlerExceedLimit(dh, 100000);
assertEquals(0, doesNotExceed);
} finally {
file.delete();
}
}
use of javax.activation.FileDataSource in project cxf by apache.
the class AttachmentUtil method createMtomAttachmentFromDH.
public static Attachment createMtomAttachmentFromDH(boolean isXop, DataHandler handler, String elementNS, int threshold) {
if (!isXop) {
return null;
}
// apply the threshold.
try {
DataSource ds = handler.getDataSource();
if (ds instanceof FileDataSource) {
FileDataSource fds = (FileDataSource) ds;
File file = fds.getFile();
if (file.length() < threshold) {
return null;
}
} else if (ds.getClass().getName().endsWith("ObjectDataSource")) {
Object o = handler.getContent();
if (o instanceof String && ((String) o).length() < threshold) {
return null;
} else if (o instanceof byte[] && ((byte[]) o).length < threshold) {
return null;
}
}
} catch (IOException e1) {
// ignore, just do the normal attachment thing
}
String id;
try {
id = AttachmentUtil.createContentID(elementNS);
} catch (UnsupportedEncodingException e) {
throw new Fault(e);
}
AttachmentImpl att = new AttachmentImpl(id, handler);
if (!StringUtils.isEmpty(handler.getName())) {
// set Content-Disposition attachment header if filename isn't null
String file = handler.getName();
File f = new File(file);
if (f.exists() && f.isFile()) {
file = f.getName();
}
att.setHeader("Content-Disposition", "attachment;name=\"" + file + "\"");
}
att.setXOP(isXop);
return att;
}
use of javax.activation.FileDataSource in project cxf by apache.
the class MTOMSecurityTest method testSymmetricBinaryBytesInAttachment.
@org.junit.Test
public void testSymmetricBinaryBytesInAttachment() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = MTOMSecurityTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = MTOMSecurityTest.class.getResource("DoubleItMtom.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItSymmetricBinaryPort");
DoubleItMtomPortType port = service.getPort(portQName, DoubleItMtomPortType.class);
updateAddressPort(port, PORT);
DataSource source = new FileDataSource(new File("src/test/resources/java.jpg"));
DoubleIt4 doubleIt = new DoubleIt4();
doubleIt.setNumberToDouble(25);
port.doubleIt4(25, new DataHandler(source));
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of javax.activation.FileDataSource in project cxf by apache.
the class MTOMSecurityTest method testSignedMTOMAction.
// Sign an attachment without inlining
@org.junit.Test
public void testSignedMTOMAction() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = MTOMSecurityTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = MTOMSecurityTest.class.getResource("DoubleItMtom.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItSignedMTOMActionPort");
DoubleItMtomPortType port = service.getPort(portQName, DoubleItMtomPortType.class);
updateAddressPort(port, PORT);
DataSource source = new FileDataSource(new File("src/test/resources/java.jpg"));
DoubleIt4 doubleIt = new DoubleIt4();
doubleIt.setNumberToDouble(25);
port.doubleIt4(25, new DataHandler(source));
((java.io.Closeable) port).close();
bus.shutdown(true);
}
Aggregations