1.1 --- a/src/share/jaxws_classes/com/sun/tools/internal/ws/wscompile/WsgenTool.java Thu Apr 04 19:05:24 2013 -0700 1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wscompile/WsgenTool.java Tue Apr 09 14:51:13 2013 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -25,6 +25,7 @@ 1.11 1.12 package com.sun.tools.internal.ws.wscompile; 1.13 1.14 +import com.oracle.webservices.internal.api.databinding.WSDLResolver; 1.15 import com.sun.istack.internal.tools.ParallelWorldClassLoader; 1.16 import com.sun.tools.internal.ws.ToolVersion; 1.17 import com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceAp; 1.18 @@ -43,9 +44,9 @@ 1.19 import com.sun.xml.internal.ws.api.server.Container; 1.20 import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension; 1.21 import com.sun.xml.internal.ws.binding.WebServiceFeatureList; 1.22 +import com.sun.xml.internal.ws.model.ExternalMetadataReader; 1.23 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; 1.24 import com.sun.xml.internal.ws.util.ServiceFinder; 1.25 -import com.sun.xml.internal.ws.wsdl.writer.WSDLResolver; 1.26 import org.xml.sax.SAXParseException; 1.27 1.28 import javax.tools.DiagnosticCollector; 1.29 @@ -71,6 +72,7 @@ 1.30 import java.util.Collection; 1.31 import java.util.Collections; 1.32 import java.util.HashMap; 1.33 +import java.util.List; 1.34 import java.util.Map; 1.35 1.36 /** 1.37 @@ -86,7 +88,7 @@ 1.38 1.39 1.40 public WsgenTool(OutputStream out, Container container) { 1.41 - this.out = (out instanceof PrintStream)?(PrintStream)out:new PrintStream(out); 1.42 + this.out = (out instanceof PrintStream) ? (PrintStream) out : new PrintStream(out); 1.43 this.container = container; 1.44 } 1.45 1.46 @@ -95,7 +97,7 @@ 1.47 this(out, null); 1.48 } 1.49 1.50 - public boolean run(String[] args){ 1.51 + public boolean run(String[] args) { 1.52 final Listener listener = new Listener(); 1.53 for (String arg : args) { 1.54 if (arg.equals("-version")) { 1.55 @@ -112,22 +114,22 @@ 1.56 try { 1.57 options.parseArguments(args); 1.58 options.validate(); 1.59 - if(!buildModel(options.endpoint.getName(), listener)){ 1.60 + if (!buildModel(options.endpoint.getName(), listener)) { 1.61 return false; 1.62 } 1.63 - }catch (Options.WeAreDone done){ 1.64 - usage((WsgenOptions)done.getOptions()); 1.65 - }catch (BadCommandLineException e) { 1.66 - if(e.getMessage()!=null) { 1.67 + } catch (Options.WeAreDone done) { 1.68 + usage(done.getOptions()); 1.69 + } catch (BadCommandLineException e) { 1.70 + if (e.getMessage() != null) { 1.71 System.out.println(e.getMessage()); 1.72 System.out.println(); 1.73 } 1.74 - usage((WsgenOptions)e.getOptions()); 1.75 + usage(e.getOptions()); 1.76 return false; 1.77 - }catch(AbortException e){ 1.78 + } catch (AbortException e) { 1.79 //error might have been reported 1.80 - }finally{ 1.81 - if(!options.keep){ 1.82 + } finally { 1.83 + if (!options.keep) { 1.84 options.removeGeneratedFiles(); 1.85 } 1.86 } 1.87 @@ -136,21 +138,25 @@ 1.88 1.89 private final Container container; 1.90 1.91 - private int round = 0; 1.92 - 1.93 /* 1.94 * To take care of JDK6-JDK6u3, where 2.1 API classes are not there 1.95 */ 1.96 private static boolean useBootClasspath(Class clazz) { 1.97 try { 1.98 - ParallelWorldClassLoader.toJarUrl(clazz.getResource('/'+clazz.getName().replace('.','/')+".class")); 1.99 + ParallelWorldClassLoader.toJarUrl(clazz.getResource('/' + clazz.getName().replace('.', '/') + ".class")); 1.100 return true; 1.101 - } catch(Exception e) { 1.102 + } catch (Exception e) { 1.103 return false; 1.104 } 1.105 } 1.106 1.107 - 1.108 + /** 1.109 + * 1.110 + * @param endpoint 1.111 + * @param listener 1.112 + * @return 1.113 + * @throws BadCommandLineException 1.114 + */ 1.115 public boolean buildModel(String endpoint, Listener listener) throws BadCommandLineException { 1.116 final ErrorReceiverFilter errReceiver = new ErrorReceiverFilter(listener); 1.117 1.118 @@ -178,7 +184,7 @@ 1.119 .append(JavaCompilerHelper.getJarFile(XmlSeeAlso.class)).toString()); 1.120 } 1.121 1.122 - JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 1.123 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();// compiler = JavacTool.create(); 1.124 DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); 1.125 StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); 1.126 JavaCompiler.CompilationTask task = compiler.getTask( 1.127 @@ -196,8 +202,15 @@ 1.128 return false; 1.129 } 1.130 if (options.genWsdl) { 1.131 - DatabindingConfig config = new DatabindingConfig(); 1.132 - String tmpPath = options.destDir.getAbsolutePath()+ File.pathSeparator+options.classpath; 1.133 + DatabindingConfig config = new DatabindingConfig(); 1.134 + 1.135 + List<String> externalMetadataFileNames = options.externalMetadataFiles; 1.136 + boolean disableSecureXmlProcessing = options.disableSecureXmlProcessing; 1.137 + if (externalMetadataFileNames != null && externalMetadataFileNames.size() > 0) { 1.138 + config.setMetadataReader(new ExternalMetadataReader(getExternalFiles(externalMetadataFileNames), null, null, true, disableSecureXmlProcessing)); 1.139 + } 1.140 + 1.141 + String tmpPath = options.destDir.getAbsolutePath() + File.pathSeparator + options.classpath; 1.142 ClassLoader classLoader = new URLClassLoader(Options.pathToURLs(tmpPath), 1.143 this.getClass().getClassLoader()); 1.144 Class<?> endpointClass; 1.145 @@ -218,23 +231,26 @@ 1.146 config.getMappingInfo().setPortName(options.portName);//rtModeler.setPortName(options.portName); 1.147 // AbstractSEIModelImpl rtModel = rtModeler.buildRuntimeModel(); 1.148 1.149 - DatabindingFactory fac = DatabindingFactory.newInstance(); 1.150 - config.setEndpointClass(endpointClass); 1.151 - config.getMappingInfo().setServiceName(options.serviceName); 1.152 - config.setFeatures(wsfeatures.toArray()); 1.153 - config.setClassLoader(classLoader); 1.154 - config.getMappingInfo().setBindingID(bindingID); 1.155 - com.sun.xml.internal.ws.db.DatabindingImpl rt = (com.sun.xml.internal.ws.db.DatabindingImpl)fac.createRuntime(config); 1.156 + DatabindingFactory fac = DatabindingFactory.newInstance(); 1.157 + config.setEndpointClass(endpointClass); 1.158 + config.getMappingInfo().setServiceName(options.serviceName); 1.159 + config.setFeatures(wsfeatures.toArray()); 1.160 + config.setClassLoader(classLoader); 1.161 + config.getMappingInfo().setBindingID(bindingID); 1.162 + com.sun.xml.internal.ws.db.DatabindingImpl rt = (com.sun.xml.internal.ws.db.DatabindingImpl) fac.createRuntime(config); 1.163 1.164 final File[] wsdlFileName = new File[1]; // used to capture the generated WSDL file. 1.165 - final Map<String,File> schemaFiles = new HashMap<String,File>(); 1.166 + final Map<String, File> schemaFiles = new HashMap<String, File>(); 1.167 1.168 WSDLGenInfo wsdlGenInfo = new WSDLGenInfo(); 1.169 + wsdlGenInfo.setSecureXmlProcessingDisabled(disableSecureXmlProcessing); 1.170 + 1.171 wsdlGenInfo.setWsdlResolver( 1.172 new WSDLResolver() { 1.173 private File toFile(String suggestedFilename) { 1.174 return new File(options.nonclassDestDir, suggestedFilename); 1.175 } 1.176 + 1.177 private Result toResult(File file) { 1.178 Result result; 1.179 try { 1.180 @@ -247,21 +263,27 @@ 1.181 return result; 1.182 } 1.183 1.184 + @Override 1.185 public Result getWSDL(String suggestedFilename) { 1.186 File f = toFile(suggestedFilename); 1.187 wsdlFileName[0] = f; 1.188 return toResult(f); 1.189 } 1.190 + 1.191 public Result getSchemaOutput(String namespace, String suggestedFilename) { 1.192 if (namespace == null) 1.193 return null; 1.194 File f = toFile(suggestedFilename); 1.195 - schemaFiles.put(namespace,f); 1.196 + schemaFiles.put(namespace, f); 1.197 return toResult(f); 1.198 } 1.199 + 1.200 + @Override 1.201 public Result getAbstractWSDL(Holder<String> filename) { 1.202 return toResult(toFile(filename.value)); 1.203 } 1.204 + 1.205 + @Override 1.206 public Result getSchemaOutput(String namespace, Holder<String> filename) { 1.207 return getSchemaOutput(namespace, filename.value); 1.208 } 1.209 @@ -274,20 +296,34 @@ 1.210 rt.generateWSDL(wsdlGenInfo); 1.211 1.212 1.213 - if(options.wsgenReport!=null) 1.214 - generateWsgenReport(endpointClass,(AbstractSEIModelImpl)rt.getModel(),wsdlFileName[0],schemaFiles); 1.215 + if (options.wsgenReport != null) 1.216 + generateWsgenReport(endpointClass, (AbstractSEIModelImpl) rt.getModel(), wsdlFileName[0], schemaFiles); 1.217 } 1.218 return true; 1.219 } 1.220 1.221 + private List<File> getExternalFiles(List<String> exts) { 1.222 + List<File> files = new ArrayList<File>(); 1.223 + for (String ext : exts) { 1.224 + // first try absolute path ... 1.225 + File file = new File(ext); 1.226 + if (!file.exists()) { 1.227 + // then relative path ... 1.228 + file = new File(options.sourceDir.getAbsolutePath() + File.separator + ext); 1.229 + } 1.230 + files.add(file); 1.231 + } 1.232 + return files; 1.233 + } 1.234 + 1.235 /** 1.236 * Generates a small XML file that captures the key activity of wsgen, 1.237 * so that test harness can pick up artifacts. 1.238 */ 1.239 - private void generateWsgenReport(Class<?> endpointClass, AbstractSEIModelImpl rtModel, File wsdlFile, Map<String,File> schemaFiles) { 1.240 + private void generateWsgenReport(Class<?> endpointClass, AbstractSEIModelImpl rtModel, File wsdlFile, Map<String, File> schemaFiles) { 1.241 try { 1.242 ReportOutput.Report report = TXW.create(ReportOutput.Report.class, 1.243 - new StreamSerializer(new BufferedOutputStream(new FileOutputStream(options.wsgenReport)))); 1.244 + new StreamSerializer(new BufferedOutputStream(new FileOutputStream(options.wsgenReport)))); 1.245 1.246 report.wsdl(wsdlFile.getAbsolutePath()); 1.247 ReportOutput.writeQName(rtModel.getServiceQName(), report.service()); 1.248 @@ -296,7 +332,7 @@ 1.249 1.250 report.implClass(endpointClass.getName()); 1.251 1.252 - for (Map.Entry<String,File> e : schemaFiles.entrySet()) { 1.253 + for (Map.Entry<String, File> e : schemaFiles.entrySet()) { 1.254 ReportOutput.Schema s = report.schema(); 1.255 s.ns(e.getKey()); 1.256 s.location(e.getValue().getAbsolutePath()); 1.257 @@ -317,10 +353,13 @@ 1.258 interface Report extends TypedXmlWriter { 1.259 @XmlElement 1.260 void wsdl(String file); // location of WSDL 1.261 + 1.262 @XmlElement 1.263 QualifiedName portType(); 1.264 + 1.265 @XmlElement 1.266 QualifiedName service(); 1.267 + 1.268 @XmlElement 1.269 QualifiedName port(); 1.270 1.271 @@ -337,6 +376,7 @@ 1.272 interface QualifiedName extends TypedXmlWriter { 1.273 @XmlAttribute 1.274 void uri(String ns); 1.275 + 1.276 @XmlAttribute 1.277 void localName(String localName); 1.278 } 1.279 @@ -344,23 +384,28 @@ 1.280 interface Schema extends TypedXmlWriter { 1.281 @XmlAttribute 1.282 void ns(String ns); 1.283 + 1.284 @XmlAttribute 1.285 void location(String filePath); 1.286 } 1.287 1.288 - private static void writeQName( QName n, QualifiedName w ) { 1.289 + private static void writeQName(QName n, QualifiedName w) { 1.290 w.uri(n.getNamespaceURI()); 1.291 w.localName(n.getLocalPart()); 1.292 } 1.293 } 1.294 1.295 - protected void usage(WsgenOptions options) { 1.296 + protected void usage(Options options) { 1.297 // Just don't see any point in passing WsgenOptions 1.298 // BadCommandLineException also shouldn't have options 1.299 if (options == null) 1.300 options = this.options; 1.301 - System.out.println(WscompileMessages.WSGEN_HELP("WSGEN", options.protocols, options.nonstdProtocols.keySet())); 1.302 - System.out.println(WscompileMessages.WSGEN_USAGE_EXAMPLES()); 1.303 + if (options instanceof WsgenOptions) { 1.304 + System.out.println(WscompileMessages.WSGEN_HELP("WSGEN", 1.305 + ((WsgenOptions)options).protocols, 1.306 + ((WsgenOptions)options).nonstdProtocols.keySet())); 1.307 + System.out.println(WscompileMessages.WSGEN_USAGE_EXAMPLES()); 1.308 + } 1.309 } 1.310 1.311 class Listener extends WsimportListener {