Search in sources :

Example 1 with TestMtom

use of org.apache.cxf.mime.TestMtom in project cxf by apache.

the class ClientMtomXopTest method testMtomXop.

@Test
public void testMtomXop() throws Exception {
    TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class, true, true);
    try {
        Holder<DataHandler> param = new Holder<DataHandler>();
        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<String>("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<String>("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<String>("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<String>("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) {
        if (ex.getMessage().contains("Connection reset") && System.getProperty("java.specification.version", "1.5").contains("1.6")) {
            // we'll ignore for now
            return;
        }
        System.out.println(System.getProperties());
        throw ex;
    }
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) InputStream(java.io.InputStream) Holder(javax.xml.ws.Holder) TestMtom(org.apache.cxf.mime.TestMtom) DataHandler(javax.activation.DataHandler) Endpoint(org.apache.cxf.endpoint.Endpoint) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Example 2 with TestMtom

use of org.apache.cxf.mime.TestMtom in project cxf by apache.

the class ClientMtomXopTest method testMtomWithFileName.

@Test
public void testMtomWithFileName() throws Exception {
    TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class, true, true);
    try {
        Holder<DataHandler> param = new Holder<DataHandler>();
        Holder<String> name;
        URL fileURL = getClass().getClassLoader().getResource("me.bmp");
        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(fileURL);
            name = new Holder<String>("have name");
            mtomPort.testXop(name, param);
            assertEquals("can't get file name", "return detail + me.bmp", name.value);
            assertNotNull(param.value);
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    } catch (Exception ex) {
        if (ex.getMessage().contains("Connection reset") && System.getProperty("java.specification.version", "1.5").contains("1.6")) {
            // we'll ignore for now
            return;
        }
        System.out.println(System.getProperties());
        throw ex;
    }
}
Also used : Holder(javax.xml.ws.Holder) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) TestMtom(org.apache.cxf.mime.TestMtom) DataHandler(javax.activation.DataHandler) URL(java.net.URL) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Test(org.junit.Test)

Example 3 with TestMtom

use of org.apache.cxf.mime.TestMtom in project cxf by apache.

the class ClientMtomXopTest method testMtoMString.

// see CXF-1395
@org.junit.Ignore
@Test
public void testMtoMString() throws Exception {
    TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class, true, false);
    InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl");
    long fileSize = 0;
    for (int i = pre.read(); i != -1; i = pre.read()) {
        fileSize++;
    }
    byte[] data = new byte[(int) fileSize];
    this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data);
    String stringValue = new String(data, "utf-8");
    XopStringType xsv = new XopStringType();
    xsv.setAttachinfo(stringValue);
    xsv.setName("eman");
    XopStringType r = mtomPort.testXopString(xsv);
    assertNotNull(r);
}
Also used : InputStream(java.io.InputStream) XopStringType(org.apache.cxf.mime.types.XopStringType) TestMtom(org.apache.cxf.mime.TestMtom) Endpoint(org.apache.cxf.endpoint.Endpoint) Test(org.junit.Test)

Example 4 with TestMtom

use of org.apache.cxf.mime.TestMtom 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<DataHandler>();
        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<String>("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<String>("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<String>("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<String>("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) {
        if (ex.getMessage().contains("Connection reset") && System.getProperty("java.specification.version", "1.5").contains("1.6")) {
            // we'll ignore for now
            return;
        }
        System.out.println(System.getProperties());
        throw ex;
    }
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) InputStream(java.io.InputStream) Holder(javax.xml.ws.Holder) TestMtom(org.apache.cxf.mime.TestMtom) DataHandler(javax.activation.DataHandler) Endpoint(org.apache.cxf.endpoint.Endpoint) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Example 5 with TestMtom

use of org.apache.cxf.mime.TestMtom 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<DataHandler>();
    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<String>("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();
}
Also used : InputStream(java.io.InputStream) Holder(javax.xml.ws.Holder) TestMtom(org.apache.cxf.mime.TestMtom) DataHandler(javax.activation.DataHandler) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) Endpoint(javax.xml.ws.Endpoint) Test(org.junit.Test)

Aggregations

TestMtom (org.apache.cxf.mime.TestMtom)5 Test (org.junit.Test)5 InputStream (java.io.InputStream)4 DataHandler (javax.activation.DataHandler)4 Holder (javax.xml.ws.Holder)4 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)3 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)3 Endpoint (org.apache.cxf.endpoint.Endpoint)3 SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)2 SAAJOutInterceptor (org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor)2 URL (java.net.URL)1 Endpoint (javax.xml.ws.Endpoint)1 XopStringType (org.apache.cxf.mime.types.XopStringType)1