packageorg.duke.jaxws.test;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.InputStream;importjava.io.OutputStream;importjava.net.MalformedURLException;importjava.net.URL;importjava.text.ParseException;importjava.text.SimpleDateFormat;importjava.util.GregorianCalendar;importjavax.activation.DataHandler;importjavax.activation.DataSource;importjavax.activation.FileDataSource;importjavax.xml.datatype.DatatypeConfigurationException;importjavax.xml.datatype.DatatypeFactory;importjavax.xml.namespace.QName;importorg.duke.jaxws.client.Customer;importorg.duke.jaxws.client.Hello;importorg.duke.jaxws.client.Hello_Service;publicclassSoapClient {publicstaticvoidmain(String[] args)throwsParseException,
MalformedURLException {
QName qName=newQName("http://server.jaxws.duke.org/","Hello");
Hello_Service helloService=newHello_Service(newURL("http://localhost:8080/Service/Hello?wsdl"), qName);
Hello hello=(Hello) helloService.getPort(Hello.class);
hello.printContext();
System.out.println("########################################");
Customer customer=newCustomer();
customer.setName("duke");
DataSource ds=hello.selectCustomerByName(customer).getImageData()
.getDataSource();
String attachmentMimeType=ds.getContentType();
System.out.println(attachmentMimeType);try{
InputStream is=ds.getInputStream();
OutputStream os=newFileOutputStream("c:\\Shawn\\duke-real_temp.jpg");byte[] bytes=newbyte[1024];intc;while((c=is.read(bytes))!=-1) {
os.write(bytes,0, c);
}
}catch(IOException e) {
e.printStackTrace();
}
System.out.println("########################################");
Customer c1=newCustomer();
c1.setId(1);
c1.setName("duke");
GregorianCalendar calendar=(GregorianCalendar) GregorianCalendar
.getInstance();
calendar.setTime(newSimpleDateFormat("yyyy-MM-dd").parse("1985-03-14"));try{
c1.setBirthday(DatatypeFactory.newInstance()
.newXMLGregorianCalendar(calendar));
}catch(DatatypeConfigurationException e) {
e.printStackTrace();
}
c1.setImageData(newDataHandler(newFileDataSource("c:\\Shawn\\duke1.jpg")));
Customer c2=newCustomer();
c2.setId(2);
c2.setName("abc");
calendar.setTime(newSimpleDateFormat("yyyy-MM-dd").parse("1986-03-14"));try{
c2.setBirthday(DatatypeFactory.newInstance()
.newXMLGregorianCalendar(calendar));
}catch(DatatypeConfigurationException e) {
e.printStackTrace();
}
c2.setImageData(newDataHandler(newFileDataSource("c:\\Shawn\\duke-real_temp.jpg")));
Customer c=hello.selectMaxAgeCustomer(c1, c2);
System.out.println(c.getName());
}
}