use of com.sun.xml.ws.transport.http.DeploymentDescriptorParser in project metro-jax-ws by eclipse-ee4j.
the class WSDLGen method run.
public static int run() throws Exception {
if (!useLocal()) {
return 0;
}
String outputDir = System.getProperty("tempdir");
if (outputDir == null) {
System.err.println("**** Set tempdir system property ****");
return -1;
}
String riFile = outputDir + "/WEB-INF/sun-jaxws.xml";
DeploymentDescriptorParser<WSEndpoint> parser = new DeploymentDescriptorParser<WSEndpoint>(Thread.currentThread().getContextClassLoader(), new FileSystemResourceLoader(new File(outputDir)), null, new AdapterFactory<WSEndpoint>() {
public WSEndpoint createAdapter(String name, String urlPattern, WSEndpoint<?> endpoint) {
return endpoint;
}
});
List<WSEndpoint> endpoints = parser.parse(new File(riFile));
final String addr = new File(outputDir).toURL().toExternalForm();
// file:// -> local://
final String address = "local" + addr.substring(4);
for (WSEndpoint endpoint : endpoints) {
ServiceDefinition def = endpoint.getServiceDefinition();
if (def == null) {
continue;
}
SDDocument primary = def.getPrimary();
File file = new File(primary.getURL().toURI());
if (file.exists()) {
System.out.println("**** Primary WSDL " + file + " already exists - not generating any WSDL artifacts ****");
// Primary WSDL already exists
continue;
}
for (SDDocument doc : def) {
int index = doc.getURL().getFile().indexOf("/WEB-INF/wsdl");
String name = "";
if (index == -1)
name = outputDir + "/WEB-INF/wsdl" + doc.getURL().getFile();
else
name = doc.getURL().getFile();
System.out.println("Creating WSDL artifact=" + name);
ByteArrayBuffer buffer = new ByteArrayBuffer();
doc.writeTo(new PortAddressResolver() {
public String getAddressFor(QName serviceName, String portName) {
return address;
}
}, new DocumentAddressResolver() {
public String getRelativeAddressFor(SDDocument current, SDDocument referenced) {
String rel = referenced.getURL().toExternalForm();
// remove file:/
return rel.substring(6);
}
}, buffer);
FileOutputStream fos = new FileOutputStream(name);
buffer.writeTo(fos);
fos.close();
}
}
return 0;
}
Aggregations