Search in sources :

Example 1 with AttachmentWSService

use of com.alibaba.csb.ws.wsimpl.AttachmentWSService in project csb-sdk by aliyun.

the class Main method testWithProxy.

/**
 * Call MTOM/WS with static proxy client
 *
 * @throws Exception
 */
public void testWithProxy() throws Exception {
    // Create the service client endpoint
    AttachmentWSService service = new AttachmentWSService(new URL(wsdlAddr));
    // Get the proxy port
    AttachmentWS port = service.getAttachmentWSPort(new javax.xml.ws.soap.MTOMFeature());
    // Set enable MTOM
    BindingProvider bp = (BindingProvider) port;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddr);
    binding.setMTOMEnabled(true);
    // 使用SDK将AK, SK传输的调用client端
    port = WSClientSDK.bind(port, ak, sk);
    String testString = "this is a mtom String";
    String retStr = port.echoBinaryAsString(testString.getBytes());
    System.out.println("return Str=" + retStr);
    // Assert.assertTrue("Not equal", testString.equals(retStr));
    byte[] retBytes = port.echoStringAsBinary(testString);
    // Assert.assertTrue("Not equal", testString.equals(new String(retBytes)));
    System.out.println("return Str=" + retBytes);
    final File f = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "com/alibaba/csb/sdk/ws/mtom/MtomSDKTest.class");
    String upFile = "/tmp/a.class";
    // file upload
    port.fileUpload(upFile, new DataHandler(new FileDataSource(f)));
    // file download
    upFile = "/tmp/b.class";
    DataHandler dh = port.fileDownload(upFile);
    OutputStream os = new FileOutputStream(new File(upFile));
    dh.writeTo(os);
/**/
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) DataHandler(javax.activation.DataHandler) AttachmentWSService(com.alibaba.csb.ws.wsimpl.AttachmentWSService) URL(java.net.URL) AttachmentWS(com.alibaba.csb.ws.wsimpl.AttachmentWS) FileOutputStream(java.io.FileOutputStream) FileDataSource(javax.activation.FileDataSource) File(java.io.File)

Example 2 with AttachmentWSService

use of com.alibaba.csb.ws.wsimpl.AttachmentWSService in project csb-sdk by aliyun.

the class MtomSDKTest method testWithProxy.

@Test
public /**
 * Call MTOM/WS with static proxy client
 *
 * @throws Exception
 */
void testWithProxy() throws Exception {
    // Create the service client endpoint
    AttachmentWSService service = new AttachmentWSService(new URL(wsdlAddr));
    // Get the proxy port
    AttachmentWS port = service.getAttachmentWSPort(new javax.xml.ws.soap.MTOMFeature());
    // Set enable MTOM
    BindingProvider bp = (BindingProvider) port;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddr);
    binding.setMTOMEnabled(true);
    // 使用SDK将AK, SK传输的调用client端
    port = WSClientSDK.bind(port, ak, sk, "ci-ws2ws-mtom-import", "1.0.0");
    int times = Integer.getInteger("times", 1);
    for (int i = 0; i < times; i++) {
        System.out.println("----- Execute the test with #" + i + " time");
        String testString = "this is a mtom String";
        String retStr = port.echoBinaryAsString(testString.getBytes());
        System.out.println("return Str=" + retStr);
        Assert.assertTrue("Not equal", testString.equals(retStr));
        byte[] retBytes = port.echoStringAsBinary(testString);
        Assert.assertTrue("Not equal", testString.equals(new String(retBytes)));
        System.out.println("return Str=" + retBytes);
        final File f = new File(MtomSDKTest.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "com/alibaba/csb/sdk/ws/mtom/MtomSDKTest.class");
        String upFile = "/tmp/new.class";
        // file upload
        port.fileUpload(upFile, new DataHandler(new FileDataSource(f)));
        // file download
        DataHandler dh = port.fileDownload(upFile);
        OutputStream os = new FileOutputStream(new File(upFile));
        dh.writeTo(os);
    /**/
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) DataHandler(javax.activation.DataHandler) AttachmentWSService(com.alibaba.csb.ws.wsimpl.AttachmentWSService) URL(java.net.URL) AttachmentWS(com.alibaba.csb.ws.wsimpl.AttachmentWS) FileOutputStream(java.io.FileOutputStream) FileDataSource(javax.activation.FileDataSource) File(java.io.File) Test(org.junit.Test)

Aggregations

AttachmentWS (com.alibaba.csb.ws.wsimpl.AttachmentWS)2 AttachmentWSService (com.alibaba.csb.ws.wsimpl.AttachmentWSService)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 URL (java.net.URL)2 DataHandler (javax.activation.DataHandler)2 FileDataSource (javax.activation.FileDataSource)2 BindingProvider (javax.xml.ws.BindingProvider)2 SOAPBinding (javax.xml.ws.soap.SOAPBinding)2 Test (org.junit.Test)1