Search in sources :

Example 1 with DataStruct

use of org.apache.cxf.swa.types.DataStruct in project cxf by apache.

the class ClientServerSwaTest method testSwaDataStruct.

@Test
public void testSwaDataStruct() throws Exception {
    SwAService service = new SwAService();
    SwAServiceInterface port = service.getSwAServiceHttpPort();
    setAddress(port, "http://localhost:" + serverPort + "/swa");
    Holder<DataStruct> structHolder = new Holder<DataStruct>();
    ByteArrayDataSource source = new ByteArrayDataSource("foobar".getBytes(), "application/octet-stream");
    DataHandler handler = new DataHandler(source);
    DataStruct struct = new DataStruct();
    struct.setDataRef(handler);
    structHolder.value = struct;
    port.echoDataRef(structHolder);
    handler = structHolder.value.getDataRef();
    InputStream bis = handler.getDataSource().getInputStream();
    byte[] b = new byte[10];
    bis.read(b, 0, 10);
    String string = IOUtils.newStringFromBytes(b);
    assertEquals("testfoobar", string);
    bis.close();
}
Also used : SwAService(org.apache.cxf.swa.SwAService) DataStruct(org.apache.cxf.swa.types.DataStruct) SwAServiceInterface(org.apache.cxf.swa.SwAServiceInterface) InputStream(java.io.InputStream) Holder(javax.xml.ws.Holder) DataHandler(javax.activation.DataHandler) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)1 DataHandler (javax.activation.DataHandler)1 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)1 Holder (javax.xml.ws.Holder)1 SwAService (org.apache.cxf.swa.SwAService)1 SwAServiceInterface (org.apache.cxf.swa.SwAServiceInterface)1 DataStruct (org.apache.cxf.swa.types.DataStruct)1 Test (org.junit.Test)1