src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/MetadataFinder.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -28,11 +28,10 @@
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import com.sun.tools.internal.ws.resources.WscompileMessages;
import com.sun.tools.internal.ws.resources.WsdlMessages;
import com.sun.tools.internal.ws.wscompile.AbortException;
-import com.sun.tools.internal.ws.wscompile.DefaultAuthenticator;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants;
import com.sun.tools.internal.ws.wsdl.framework.ParseException;
@@ -67,32 +66,35 @@
*/
public final class MetadataFinder extends DOMForest{
public boolean isMexMetadata;
private String rootWSDL;
- private Set<String> rootWsdls = new HashSet<String>();
+ private final Set<String> rootWsdls = new HashSet<String>();
public MetadataFinder(InternalizationLogic logic, WsimportOptions options, ErrorReceiver errReceiver) {
super(logic, new WSEntityResolver(options,errReceiver), options, errReceiver);
}
+ @SuppressWarnings("element-type-mismatch")
public void parseWSDL(){
// parse source grammars
for (InputSource value : options.getWSDLs()) {
String systemID = value.getSystemId();
errorReceiver.pollAbort();
- Document dom ;
- Element doc = null;
+ Document dom;
+ Element doc;
try {
//if there is entity resolver use it
- if (options.entityResolver != null)
+ if (options.entityResolver != null) {
value = options.entityResolver.resolveEntity(null, systemID);
- if (value == null)
+ }
+ if (value == null) {
value = new InputSource(systemID);
+ }
dom = parse(value, true);
doc = dom.getDocumentElement();
if (doc == null) {
continue;
@@ -100,11 +102,11 @@
//if its not a WSDL document, retry with MEX
if (doc.getNamespaceURI() == null || !doc.getNamespaceURI().equals(WSDLConstants.NS_WSDL) || !doc.getLocalName().equals("definitions")) {
throw new SAXParseException(WsdlMessages.INVALID_WSDL(systemID,
com.sun.xml.internal.ws.wsdl.parser.WSDLConstants.QNAME_DEFINITIONS, doc.getNodeName(), locatorTable.getStartLocation(doc).getLineNumber()), locatorTable.getStartLocation(doc));
}
- } catch(FileNotFoundException e){
+ } catch (FileNotFoundException e) {
errorReceiver.error(WsdlMessages.FILE_NOT_FOUND(systemID), e);
return;
} catch (IOException e) {
doc = getFromMetadataResolver(systemID, e);
} catch (SAXParseException e) {
@@ -117,28 +119,31 @@
continue;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
- if(!inlinedSchemaElements.contains(schemas.item(i)))
+ if (!inlinedSchemaElements.contains(schemas.item(i))) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
}
+ }
identifyRootWsdls();
}
public static class WSEntityResolver implements EntityResolver {
- EntityResolver parentResolver;
WsimportOptions options;
ErrorReceiver errorReceiver;
+ private URLConnection c = null;
+ private boolean doReset = false;
+
public WSEntityResolver(WsimportOptions options, ErrorReceiver errReceiver) {
- this.parentResolver = options.entityResolver;
this.options = options;
this.errorReceiver = errReceiver;
}
+ @Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
InputSource inputSource = null;
if(options.entityResolver != null ) {
inputSource = options.entityResolver.resolveEntity(null, systemId);
@@ -159,20 +164,28 @@
redirect = false;
if (conn instanceof HttpURLConnection) {
((HttpURLConnection) conn).setInstanceFollowRedirects(false);
}
+ if (conn instanceof JarURLConnection) {
+ if (conn.getUseCaches()) {
+ doReset = true;
+ conn.setDefaultUseCaches(false);
+ c = conn;
+ }
+ }
+
try {
is = conn.getInputStream();
//is = sun.net.www.protocol.http.HttpURLConnection.openConnectionCheckRedirects(conn);
} catch (IOException e) {
if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = ((HttpURLConnection) conn);
int code = httpConn.getResponseCode();
if (code == 401) {
errorReceiver.error(new SAXParseException(WscompileMessages.WSIMPORT_AUTH_INFO_NEEDED(e.getMessage(),
- systemId, DefaultAuthenticator.defaultAuthfile), null, e));
+ systemId, WsimportOptions.defaultAuthfile), null, e));
throw new AbortException();
}
//FOR other code we will retry with MEX
}
throw e;
@@ -209,15 +222,23 @@
}
return inputSource;
}
+ @Override
+ protected void finalize() throws Throwable {
+ //see http://java.net/jira/browse/JAX_WS-1087
+ if (doReset) {
+ c.setDefaultUseCaches(true);
+ }
+ }
}
// overide default SSL HttpClientVerifier to always return true
// effectively overiding Hostname client verification when using SSL
private static class HttpClientVerifier implements HostnameVerifier {
+ @Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
}
@@ -261,11 +282,11 @@
}
}
}
//no wsdl with wsdl:service found, throw error
if(rootWSDL == null){
- StringBuffer strbuf = new StringBuffer();
+ StringBuilder strbuf = new StringBuilder();
for(String str : rootWsdls){
strbuf.append(str);
strbuf.append('\n');
}
errorReceiver.error(null, WsdlMessages.FAILED_NOSERVICE(strbuf.toString()));