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);
/**/
}
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);
/**/
}
}
Aggregations