src/share/jaxws_classes/com/sun/tools/internal/ws/util/WSDLFetcher.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 68,78 **** /** * Fetches the wsdls in the DOMForest to the options.destDir * @param forest ! * @return * @throws IOException * @throws XMLStreamException * @throws FileNotFoundException */ public String fetchWsdls(MetadataFinder forest) throws IOException, XMLStreamException { --- 68,78 ---- /** * Fetches the wsdls in the DOMForest to the options.destDir * @param forest ! * @return location of fetched root WSDL document * @throws IOException * @throws XMLStreamException * @throws FileNotFoundException */ public String fetchWsdls(MetadataFinder forest) throws IOException, XMLStreamException {
*** 98,127 **** public String getAddressFor(@NotNull QName serviceName, @NotNull String portName) { return null; } }, docLocator); ! //XMLInputFactory readerFactory = XMLInputFactory.newInstance(); ! //XMLStreamReader xsr = readerFactory.createXMLStreamReader(new DOMSource(forest.get(rootWsdl))); ! ! XMLStreamReader xsr = SourceReaderFactory.createSourceReader(new DOMSource(forest.get(doc)), false); ! XMLOutputFactory writerfactory = XMLOutputFactory.newInstance(); ! String resolvedRootWsdl = docLocator.getLocationFor(null, doc); File outFile = new File(destDir, resolvedRootWsdl); ! OutputStream os = new FileOutputStream(outFile); if(options.verbose) { listener.message(WscompileMessages.WSIMPORT_DOCUMENT_DOWNLOAD(doc,outFile)); } ! XMLStreamWriter xsw = writerfactory.createXMLStreamWriter(os); //DOMForest eats away the whitespace loosing all the indentation, so write it through // indenting writer for better readability of fetched documents IndentingXMLStreamWriter indentingWriter = new IndentingXMLStreamWriter(xsw); wsdlPatcher.bridge(xsr, indentingWriter); - xsr.close(); - xsw.close(); - os.close(); options.addGeneratedFile(outFile); return resolvedRootWsdl; } private Map<String,String> createDocumentMap(MetadataFinder forest, File baseDir, final String rootWsdl, Set<String> externalReferences) { --- 98,135 ---- public String getAddressFor(@NotNull QName serviceName, @NotNull String portName) { return null; } }, docLocator); ! XMLStreamReader xsr = null; ! XMLStreamWriter xsw = null; ! OutputStream os = null; ! String resolvedRootWsdl = null; ! try { ! XMLOutputFactory writerfactory; ! xsr = SourceReaderFactory.createSourceReader(new DOMSource(forest.get(doc)), false); ! writerfactory = XMLOutputFactory.newInstance(); ! resolvedRootWsdl = docLocator.getLocationFor(null, doc); File outFile = new File(destDir, resolvedRootWsdl); ! os = new FileOutputStream(outFile); if(options.verbose) { listener.message(WscompileMessages.WSIMPORT_DOCUMENT_DOWNLOAD(doc,outFile)); } ! xsw = writerfactory.createXMLStreamWriter(os); //DOMForest eats away the whitespace loosing all the indentation, so write it through // indenting writer for better readability of fetched documents IndentingXMLStreamWriter indentingWriter = new IndentingXMLStreamWriter(xsw); wsdlPatcher.bridge(xsr, indentingWriter); options.addGeneratedFile(outFile); + } finally { + try { + if (xsr != null) {xsr.close();} + if (xsw != null) {xsw.close();} + } finally { + if (os != null) {os.close();} + } + } return resolvedRootWsdl; } private Map<String,String> createDocumentMap(MetadataFinder forest, File baseDir, final String rootWsdl, Set<String> externalReferences) {
*** 134,146 **** rootWsdlFileName = rootWsdl.substring(slashIndex+1); } if(!rootWsdlFileName.endsWith(WSDL_FILE_EXTENSION)) { Document rootWsdlDoc = forest.get(rootWsdl); NodeList serviceNodes = rootWsdlDoc.getElementsByTagNameNS(WSDLConstants.QNAME_SERVICE.getNamespaceURI(),WSDLConstants.QNAME_SERVICE.getLocalPart()); ! if(serviceNodes.getLength() == 0) rootWsdlName = "Service"; ! else { Node serviceNode = serviceNodes.item(0); String serviceName = ((Element)serviceNode).getAttribute( WSDLConstants.ATTR_NAME); rootWsdlName = serviceName; } rootWsdlFileName = rootWsdlName+ WSDL_FILE_EXTENSION; --- 142,154 ---- rootWsdlFileName = rootWsdl.substring(slashIndex+1); } if(!rootWsdlFileName.endsWith(WSDL_FILE_EXTENSION)) { Document rootWsdlDoc = forest.get(rootWsdl); NodeList serviceNodes = rootWsdlDoc.getElementsByTagNameNS(WSDLConstants.QNAME_SERVICE.getNamespaceURI(),WSDLConstants.QNAME_SERVICE.getLocalPart()); ! if (serviceNodes.getLength() == 0) { rootWsdlName = "Service"; ! } else { Node serviceNode = serviceNodes.item(0); String serviceName = ((Element)serviceNode).getAttribute( WSDLConstants.ATTR_NAME); rootWsdlName = serviceName; } rootWsdlFileName = rootWsdlName+ WSDL_FILE_EXTENSION;
*** 175,186 **** } return map; } private DocumentLocationResolver createDocResolver(final String baseWsdl, final DOMForest forest, final Map<String,String> documentMap) { - return new DocumentLocationResolver() { public String getLocationFor(String namespaceURI, String systemId) { try { URL reference = new URL(new URL(baseWsdl),systemId); systemId = reference.toExternalForm(); } catch (MalformedURLException e) { --- 183,194 ---- } return map; } private DocumentLocationResolver createDocResolver(final String baseWsdl, final DOMForest forest, final Map<String,String> documentMap) { return new DocumentLocationResolver() { + @Override public String getLocationFor(String namespaceURI, String systemId) { try { URL reference = new URL(new URL(baseWsdl),systemId); systemId = reference.toExternalForm(); } catch (MalformedURLException e) {
*** 196,206 **** }; } private String sanitize(String fileName) { fileName = fileName.replace('?', '.'); ! StringBuffer sb = new StringBuffer(fileName); for (int i = 0; i < sb.length(); i++) { char c = sb.charAt(i); if (Character.isLetterOrDigit(c) || (c == '/') || (c == '.') || --- 204,214 ---- }; } private String sanitize(String fileName) { fileName = fileName.replace('?', '.'); ! StringBuilder sb = new StringBuilder(fileName); for (int i = 0; i < sb.length(); i++) { char c = sb.charAt(i); if (Character.isLetterOrDigit(c) || (c == '/') || (c == '.') ||
*** 214,225 **** } return sb.toString(); } private File getWSDLDownloadDir() { ! File wsdlDir = new File(options.destDir,WSDL_PATH); ! wsdlDir.mkdirs(); return wsdlDir; } private static String WSDL_PATH="META-INF/wsdl"; private static String WSDL_FILE_EXTENSION=".wsdl"; --- 222,236 ---- } return sb.toString(); } private File getWSDLDownloadDir() { ! File wsdlDir = new File(options.destDir, WSDL_PATH); ! boolean created = wsdlDir.mkdirs(); ! if (options.verbose && !created) { ! listener.message(WscompileMessages.WSCOMPILE_NO_SUCH_DIRECTORY(wsdlDir)); ! } return wsdlDir; } private static String WSDL_PATH="META-INF/wsdl"; private static String WSDL_FILE_EXTENSION=".wsdl";