1 22 package org.jboss.test.webservice.attachmentstepbystep; 23 24 import java.io.BufferedReader ; 25 import java.io.InputStreamReader ; 26 import javax.activation.DataHandler ; 27 import javax.activation.FileDataSource ; 28 import javax.xml.namespace.QName ; 29 import javax.xml.rpc.Call ; 30 import javax.xml.rpc.ParameterMode ; 31 import javax.xml.rpc.Service ; 32 import javax.xml.rpc.ServiceFactory ; 33 import junit.framework.Test; 34 import org.jboss.test.JBossTestCase; 35 import org.jboss.test.webservice.WebserviceTestBase; 36 import org.jboss.test.webservice.attachment.AttachmentDIITestCase; 37 38 public class MyServiceClientTestCase extends WebserviceTestBase 39 { 40 public MyServiceClientTestCase(String name) 41 { 42 super(name); 43 } 44 45 46 public static Test suite() throws Exception 47 { 48 return getDeploySetup(MyServiceClientTestCase.class, "myservice.war"); 49 } 50 51 public void testMyService() throws Exception 52 { 53 String NS_URI = "http://org.jboss.test.webservice.attachmentstepbystep/MyService"; 54 QName ATTACHMENT_TYPE; 55 56 if (isWS4EEAvailable()) 57 ATTACHMENT_TYPE = new QName ("http://xml.apache.org/xml-soap", "DataHandler"); 58 else 59 ATTACHMENT_TYPE = new QName ("http://www.jboss.org/jbossws/attachment/mimetype", "text_plain"); 60 61 ServiceFactory factory = ServiceFactory.newInstance(); 62 Service service = factory.createService(new QName (NS_URI, "MyService")); 63 Call call = service.createCall(new QName (NS_URI, "MyService")); 64 call.setTargetEndpointAddress("http://" + getServerHost() + ":8080/myservice/MyService"); 65 66 call.setOperationName(new QName (NS_URI, "myService")); 68 call.addParameter("mimepart", ATTACHMENT_TYPE, DataHandler .class, ParameterMode.IN); 69 call.setReturnType(ATTACHMENT_TYPE, DataHandler .class); 70 DataHandler dh = (DataHandler )call.invoke(new Object [] { new DataHandler (new FileDataSource ( 71 "resources/webservice/attachmentstepbystep/attachment_client2server.txt")) }); 72 73 assertNotNull(dh); 74 75 if (dh != null) 76 { 77 BufferedReader in = new BufferedReader (new InputStreamReader (dh.getInputStream())); 78 String line = ""; 79 String result = ""; 80 line = in.readLine(); 81 result = "" + line; 82 while (line != null) 83 { 84 line = in.readLine(); 85 result = result + line; 86 } 87 in.close(); 88 assertEquals(192, result.length()); 89 } 90 } 91 } 92 | Popular Tags |