1.1 --- a/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/MetadataFinder.java Thu Apr 04 19:05:24 2013 -0700 1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/MetadataFinder.java Tue Apr 09 14:51:13 2013 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2010, 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 @@ -30,7 +30,6 @@ 1.11 import com.sun.tools.internal.ws.resources.WscompileMessages; 1.12 import com.sun.tools.internal.ws.resources.WsdlMessages; 1.13 import com.sun.tools.internal.ws.wscompile.AbortException; 1.14 -import com.sun.tools.internal.ws.wscompile.DefaultAuthenticator; 1.15 import com.sun.tools.internal.ws.wscompile.ErrorReceiver; 1.16 import com.sun.tools.internal.ws.wscompile.WsimportOptions; 1.17 import com.sun.tools.internal.ws.wsdl.document.WSDLConstants; 1.18 @@ -69,28 +68,31 @@ 1.19 1.20 public boolean isMexMetadata; 1.21 private String rootWSDL; 1.22 - private Set<String> rootWsdls = new HashSet<String>(); 1.23 + private final Set<String> rootWsdls = new HashSet<String>(); 1.24 1.25 public MetadataFinder(InternalizationLogic logic, WsimportOptions options, ErrorReceiver errReceiver) { 1.26 super(logic, new WSEntityResolver(options,errReceiver), options, errReceiver); 1.27 1.28 } 1.29 1.30 + @SuppressWarnings("element-type-mismatch") 1.31 public void parseWSDL(){ 1.32 // parse source grammars 1.33 for (InputSource value : options.getWSDLs()) { 1.34 String systemID = value.getSystemId(); 1.35 errorReceiver.pollAbort(); 1.36 1.37 - Document dom ; 1.38 - Element doc = null; 1.39 + Document dom; 1.40 + Element doc; 1.41 1.42 try { 1.43 - //if there is entity resolver use it 1.44 - if (options.entityResolver != null) 1.45 - value = options.entityResolver.resolveEntity(null, systemID); 1.46 - if (value == null) 1.47 - value = new InputSource(systemID); 1.48 + //if there is entity resolver use it 1.49 + if (options.entityResolver != null) { 1.50 + value = options.entityResolver.resolveEntity(null, systemID); 1.51 + } 1.52 + if (value == null) { 1.53 + value = new InputSource(systemID); 1.54 + } 1.55 dom = parse(value, true); 1.56 1.57 doc = dom.getDocumentElement(); 1.58 @@ -100,9 +102,9 @@ 1.59 //if its not a WSDL document, retry with MEX 1.60 if (doc.getNamespaceURI() == null || !doc.getNamespaceURI().equals(WSDLConstants.NS_WSDL) || !doc.getLocalName().equals("definitions")) { 1.61 throw new SAXParseException(WsdlMessages.INVALID_WSDL(systemID, 1.62 - com.sun.xml.internal.ws.wsdl.parser.WSDLConstants.QNAME_DEFINITIONS, doc.getNodeName(), locatorTable.getStartLocation(doc).getLineNumber()), locatorTable.getStartLocation(doc)); 1.63 + com.sun.xml.internal.ws.wsdl.parser.WSDLConstants.QNAME_DEFINITIONS, doc.getNodeName(), locatorTable.getStartLocation(doc).getLineNumber()), locatorTable.getStartLocation(doc)); 1.64 } 1.65 - } catch(FileNotFoundException e){ 1.66 + } catch (FileNotFoundException e) { 1.67 errorReceiver.error(WsdlMessages.FILE_NOT_FOUND(systemID), e); 1.68 return; 1.69 } catch (IOException e) { 1.70 @@ -119,24 +121,27 @@ 1.71 1.72 NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema"); 1.73 for (int i = 0; i < schemas.getLength(); i++) { 1.74 - if(!inlinedSchemaElements.contains(schemas.item(i))) 1.75 + if (!inlinedSchemaElements.contains(schemas.item(i))) { 1.76 inlinedSchemaElements.add((Element) schemas.item(i)); 1.77 + } 1.78 } 1.79 } 1.80 identifyRootWsdls(); 1.81 } 1.82 1.83 public static class WSEntityResolver implements EntityResolver { 1.84 - EntityResolver parentResolver; 1.85 WsimportOptions options; 1.86 ErrorReceiver errorReceiver; 1.87 1.88 + private URLConnection c = null; 1.89 + private boolean doReset = false; 1.90 + 1.91 public WSEntityResolver(WsimportOptions options, ErrorReceiver errReceiver) { 1.92 - this.parentResolver = options.entityResolver; 1.93 this.options = options; 1.94 this.errorReceiver = errReceiver; 1.95 } 1.96 1.97 + @Override 1.98 public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { 1.99 InputSource inputSource = null; 1.100 1.101 @@ -161,6 +166,14 @@ 1.102 ((HttpURLConnection) conn).setInstanceFollowRedirects(false); 1.103 } 1.104 1.105 + if (conn instanceof JarURLConnection) { 1.106 + if (conn.getUseCaches()) { 1.107 + doReset = true; 1.108 + conn.setDefaultUseCaches(false); 1.109 + c = conn; 1.110 + } 1.111 + } 1.112 + 1.113 try { 1.114 is = conn.getInputStream(); 1.115 //is = sun.net.www.protocol.http.HttpURLConnection.openConnectionCheckRedirects(conn); 1.116 @@ -170,7 +183,7 @@ 1.117 int code = httpConn.getResponseCode(); 1.118 if (code == 401) { 1.119 errorReceiver.error(new SAXParseException(WscompileMessages.WSIMPORT_AUTH_INFO_NEEDED(e.getMessage(), 1.120 - systemId, DefaultAuthenticator.defaultAuthfile), null, e)); 1.121 + systemId, WsimportOptions.defaultAuthfile), null, e)); 1.122 throw new AbortException(); 1.123 } 1.124 //FOR other code we will retry with MEX 1.125 @@ -211,11 +224,19 @@ 1.126 return inputSource; 1.127 } 1.128 1.129 + @Override 1.130 + protected void finalize() throws Throwable { 1.131 + //see http://java.net/jira/browse/JAX_WS-1087 1.132 + if (doReset) { 1.133 + c.setDefaultUseCaches(true); 1.134 + } 1.135 + } 1.136 } 1.137 1.138 // overide default SSL HttpClientVerifier to always return true 1.139 // effectively overiding Hostname client verification when using SSL 1.140 private static class HttpClientVerifier implements HostnameVerifier { 1.141 + @Override 1.142 public boolean verify(String s, SSLSession sslSession) { 1.143 return true; 1.144 } 1.145 @@ -263,7 +284,7 @@ 1.146 } 1.147 //no wsdl with wsdl:service found, throw error 1.148 if(rootWSDL == null){ 1.149 - StringBuffer strbuf = new StringBuffer(); 1.150 + StringBuilder strbuf = new StringBuilder(); 1.151 for(String str : rootWsdls){ 1.152 strbuf.append(str); 1.153 strbuf.append('\n');