JWS Task 5: wsimport and Quine

Write WS client that uses artifacts generated with wsimport. Use quine trick as a web method.
Example Solution
Service Implementation Bean
package com.fuzilaga.jws.quine;
import javax.jws.WebService;
@WebService(endpointInterface = "com.fuzilaga.jws.quine.QuineService")
public class QuineServiceImpl implements QuineService
{
@Override
public String printYourself()
{
String str = "package com.fuzilaga.jws.quine;%2$1c%2$1cimport javax.jws.WebService;%2$1c%2$1c@WebService(endpointInterface = %3$1ccom.fuzilaga.jws.quine.QuineService%3$1c)%2$1cpublic class QuineServiceImpl implements QuineService%2$1c{%2$1c @Override%2$1c public String printYourself()%2$1c {%2$1c String str = %3$1c%1$1s%3$1c;%2$1c return String.format(str, str, '%4$1cn', '%4$1c%3$1c', '%4$1c%4$1c');%2$1c }%2$1c}";
return String.format(str, str, '\n', '\"', '\\');
}
}
wsimport generated artifact
package com.fuzilaga.jws.quine;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.1 in JDK 6
* Generated source version: 2.1
*
*/
@WebServiceClient(name = "QuineServiceImplService", targetNamespace = "http://quine.jws.fuzilaga.com/", wsdlLocation = "http://localhost:8880/quine?wsdl")
public class QuineServiceImplService
extends Service
{
private final static URL QUINESERVICEIMPLSERVICE_WSDL_LOCATION;
static {
URL url = null;
try {
url = new URL("http://localhost:8880/quine?wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
QUINESERVICEIMPLSERVICE_WSDL_LOCATION = url;
}
public QuineServiceImplService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public QuineServiceImplService() {
super(QUINESERVICEIMPLSERVICE_WSDL_LOCATION, new QName("http://quine.jws.fuzilaga.com/", "QuineServiceImplService"));
}
/**
*
* @return
* returns QuineService
*/
@WebEndpoint(name = "QuineServiceImplPort")
public QuineService getQuineServiceImplPort() {
return (QuineService)super.getPort(new QName("http://quine.jws.fuzilaga.com/", "QuineServiceImplPort"), QuineService.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns QuineService
*/
@WebEndpoint(name = "QuineServiceImplPort")
public QuineService getQuineServiceImplPort(WebServiceFeature... features) {
return (QuineService)super.getPort(new QName("http://quine.jws.fuzilaga.com/", "QuineServiceImplPort"), QuineService.class, features);
}
}
Service Client
package com.fuzilaga.jws.quine;
public class QuineClient
{
public static void main(String[] args)
{
QuineServiceImplService service = new QuineServiceImplService();
QuineService port = service.getQuineServiceImplPort();
System.out.println(port.printYourself());
}
}
The result output will be exactly the same source code as listed for the Service Implementation Bean.
NOTE: Full source and instructions on how to run locally can be found here.