1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.cxf;
12
13 import org.mule.tck.FunctionalTestCase;
14
15 import java.io.ByteArrayOutputStream;
16 import java.io.File;
17 import java.io.InputStream;
18 import java.net.URL;
19
20 import javax.activation.DataHandler;
21 import javax.activation.FileDataSource;
22 import javax.xml.ws.BindingProvider;
23 import javax.xml.ws.Holder;
24 import javax.xml.ws.soap.SOAPBinding;
25
26 import org.apache.cxf.endpoint.Client;
27 import org.apache.cxf.frontend.ClientProxy;
28 import org.apache.cxf.helpers.IOUtils;
29 import org.apache.cxf.mime.TestMtom;
30 import org.apache.cxf.mime.TestMtomService;
31
32 public class MtomTestCase extends FunctionalTestCase
33 {
34
35 public void testEchoService() throws Exception
36 {
37 URL wsdl = getClass().getResource("/wsdl/mtom_xop.wsdl");
38 assertNotNull(wsdl);
39 TestMtomService svc = new TestMtomService(wsdl);
40
41 TestMtom port = svc.getTestMtomPort();
42
43 BindingProvider bp = ((BindingProvider) port);
44 bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
45 "http://localhost:63081/services/mtom");
46 ((SOAPBinding) bp.getBinding()).setMTOMEnabled(true);
47 Client client = ClientProxy.getClient(port);
48
49
50 File file = new File("src/test/resources/mtom-conf.xml");
51 DataHandler dh = new DataHandler(new FileDataSource(file));
52
53 Holder<String> name = new Holder<String>("test");
54 Holder<DataHandler> info = new Holder<DataHandler>(dh);
55
56 port.testXop(name, info);
57
58 assertEquals("return detail + test", name.value);
59 assertNotNull(info.value);
60
61 InputStream input = info.value.getInputStream();
62 ByteArrayOutputStream bos = new ByteArrayOutputStream();
63 IOUtils.copy(input, bos);
64 input.close();
65 }
66
67 protected String getConfigResources()
68 {
69 return "mtom-conf.xml";
70 }
71
72 }
73