import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.namespace.QName;
import org.duke.jaxws.client.Customer;
import org.duke.jaxws.client.Hello;
import org.duke.jaxws.client.Hello_Service;
public class SoapClient {
public static void main(String[] args) throws ParseException,
MalformedURLException {
QName qName = new QName("http://server.jaxws.duke.org/", "Hello");
Hello_Service helloService = new Hello_Service(new URL(
"http://localhost:8080/Service/Hello wsdl"), qName);
Hello hello = (Hello) helloService.getPort(Hello.class);
hello.printContext();
System.out.println("########################################");
Customer customer = new Customer();
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 = new FileOutputStream(
"c:\\Shawn\\duke-real_temp.jpg");
byte[] bytes = new byte[1024];
int c;
while ((c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("########################################");
Customer c1 = new Customer();
c1.setId(1);
c1.setName("duke");
GregorianCalendar calendar = (GregorianCalendar) GregorianCalendar
.getInstance();
calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("1985-03-14"));
try {
c1.setBirthday(DatatypeFactory.newInstance()
.newXMLGregorianCalendar(calendar));
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
}
c1.setImageData(new DataHandler(new FileDataSource(
"c:\\Shawn\\duke1.jpg")));
Customer c2 = new Customer();
c2.setId(2);
c2.setName("abc");
calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("1986-03-14"));
try {
c2.setBirthday(DatatypeFactory.newInstance()
.newXMLGregorianCalendar(calendar));
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
}
c2.setImageData(new DataHandler(new FileDataSource(
"c:\\Shawn\\duke-real_temp.jpg")));
Customer c = hello.selectMaxAgeCustomer(c1, c2);
System.out.println(c.getName());
}
}
作者:沉默是金