src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/MetadataFinder.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
28 import com.sun.istack.internal.NotNull; 28 import com.sun.istack.internal.NotNull;
29 import com.sun.istack.internal.Nullable; 29 import com.sun.istack.internal.Nullable;
30 import com.sun.tools.internal.ws.resources.WscompileMessages; 30 import com.sun.tools.internal.ws.resources.WscompileMessages;
31 import com.sun.tools.internal.ws.resources.WsdlMessages; 31 import com.sun.tools.internal.ws.resources.WsdlMessages;
32 import com.sun.tools.internal.ws.wscompile.AbortException; 32 import com.sun.tools.internal.ws.wscompile.AbortException;
33 import com.sun.tools.internal.ws.wscompile.DefaultAuthenticator;
34 import com.sun.tools.internal.ws.wscompile.ErrorReceiver; 33 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
35 import com.sun.tools.internal.ws.wscompile.WsimportOptions; 34 import com.sun.tools.internal.ws.wscompile.WsimportOptions;
36 import com.sun.tools.internal.ws.wsdl.document.WSDLConstants; 35 import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
37 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants; 36 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants;
38 import com.sun.tools.internal.ws.wsdl.framework.ParseException; 37 import com.sun.tools.internal.ws.wsdl.framework.ParseException;
67 */ 66 */
68 public final class MetadataFinder extends DOMForest{ 67 public final class MetadataFinder extends DOMForest{
69 68
70 public boolean isMexMetadata; 69 public boolean isMexMetadata;
71 private String rootWSDL; 70 private String rootWSDL;
72 private Set<String> rootWsdls = new HashSet<String>(); 71 private final Set<String> rootWsdls = new HashSet<String>();
73 72
74 public MetadataFinder(InternalizationLogic logic, WsimportOptions options, ErrorReceiver errReceiver) { 73 public MetadataFinder(InternalizationLogic logic, WsimportOptions options, ErrorReceiver errReceiver) {
75 super(logic, new WSEntityResolver(options,errReceiver), options, errReceiver); 74 super(logic, new WSEntityResolver(options,errReceiver), options, errReceiver);
76 75
77 } 76 }
78 77
78 @SuppressWarnings("element-type-mismatch")
79 public void parseWSDL(){ 79 public void parseWSDL(){
80 // parse source grammars 80 // parse source grammars
81 for (InputSource value : options.getWSDLs()) { 81 for (InputSource value : options.getWSDLs()) {
82 String systemID = value.getSystemId(); 82 String systemID = value.getSystemId();
83 errorReceiver.pollAbort(); 83 errorReceiver.pollAbort();
84 84
85 Document dom ; 85 Document dom;
86 Element doc = null; 86 Element doc;
87 87
88 try { 88 try {
89 //if there is entity resolver use it 89 //if there is entity resolver use it
90 if (options.entityResolver != null) 90 if (options.entityResolver != null) {
91 value = options.entityResolver.resolveEntity(null, systemID); 91 value = options.entityResolver.resolveEntity(null, systemID);
92 if (value == null) 92 }
93 value = new InputSource(systemID); 93 if (value == null) {
94 value = new InputSource(systemID);
95 }
94 dom = parse(value, true); 96 dom = parse(value, true);
95 97
96 doc = dom.getDocumentElement(); 98 doc = dom.getDocumentElement();
97 if (doc == null) { 99 if (doc == null) {
98 continue; 100 continue;
99 } 101 }
100 //if its not a WSDL document, retry with MEX 102 //if its not a WSDL document, retry with MEX
101 if (doc.getNamespaceURI() == null || !doc.getNamespaceURI().equals(WSDLConstants.NS_WSDL) || !doc.getLocalName().equals("definitions")) { 103 if (doc.getNamespaceURI() == null || !doc.getNamespaceURI().equals(WSDLConstants.NS_WSDL) || !doc.getLocalName().equals("definitions")) {
102 throw new SAXParseException(WsdlMessages.INVALID_WSDL(systemID, 104 throw new SAXParseException(WsdlMessages.INVALID_WSDL(systemID,
103 com.sun.xml.internal.ws.wsdl.parser.WSDLConstants.QNAME_DEFINITIONS, doc.getNodeName(), locatorTable.getStartLocation(doc).getLineNumber()), locatorTable.getStartLocation(doc)); 105 com.sun.xml.internal.ws.wsdl.parser.WSDLConstants.QNAME_DEFINITIONS, doc.getNodeName(), locatorTable.getStartLocation(doc).getLineNumber()), locatorTable.getStartLocation(doc));
104 } 106 }
105 } catch(FileNotFoundException e){ 107 } catch (FileNotFoundException e) {
106 errorReceiver.error(WsdlMessages.FILE_NOT_FOUND(systemID), e); 108 errorReceiver.error(WsdlMessages.FILE_NOT_FOUND(systemID), e);
107 return; 109 return;
108 } catch (IOException e) { 110 } catch (IOException e) {
109 doc = getFromMetadataResolver(systemID, e); 111 doc = getFromMetadataResolver(systemID, e);
110 } catch (SAXParseException e) { 112 } catch (SAXParseException e) {
117 continue; 119 continue;
118 } 120 }
119 121
120 NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema"); 122 NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
121 for (int i = 0; i < schemas.getLength(); i++) { 123 for (int i = 0; i < schemas.getLength(); i++) {
122 if(!inlinedSchemaElements.contains(schemas.item(i))) 124 if (!inlinedSchemaElements.contains(schemas.item(i))) {
123 inlinedSchemaElements.add((Element) schemas.item(i)); 125 inlinedSchemaElements.add((Element) schemas.item(i));
126 }
124 } 127 }
125 } 128 }
126 identifyRootWsdls(); 129 identifyRootWsdls();
127 } 130 }
128 131
129 public static class WSEntityResolver implements EntityResolver { 132 public static class WSEntityResolver implements EntityResolver {
130 EntityResolver parentResolver;
131 WsimportOptions options; 133 WsimportOptions options;
132 ErrorReceiver errorReceiver; 134 ErrorReceiver errorReceiver;
133 135
136 private URLConnection c = null;
137 private boolean doReset = false;
138
134 public WSEntityResolver(WsimportOptions options, ErrorReceiver errReceiver) { 139 public WSEntityResolver(WsimportOptions options, ErrorReceiver errReceiver) {
135 this.parentResolver = options.entityResolver;
136 this.options = options; 140 this.options = options;
137 this.errorReceiver = errReceiver; 141 this.errorReceiver = errReceiver;
138 } 142 }
139 143
144 @Override
140 public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { 145 public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
141 InputSource inputSource = null; 146 InputSource inputSource = null;
142 147
143 if(options.entityResolver != null ) { 148 if(options.entityResolver != null ) {
144 inputSource = options.entityResolver.resolveEntity(null, systemId); 149 inputSource = options.entityResolver.resolveEntity(null, systemId);
159 redirect = false; 164 redirect = false;
160 if (conn instanceof HttpURLConnection) { 165 if (conn instanceof HttpURLConnection) {
161 ((HttpURLConnection) conn).setInstanceFollowRedirects(false); 166 ((HttpURLConnection) conn).setInstanceFollowRedirects(false);
162 } 167 }
163 168
169 if (conn instanceof JarURLConnection) {
170 if (conn.getUseCaches()) {
171 doReset = true;
172 conn.setDefaultUseCaches(false);
173 c = conn;
174 }
175 }
176
164 try { 177 try {
165 is = conn.getInputStream(); 178 is = conn.getInputStream();
166 //is = sun.net.www.protocol.http.HttpURLConnection.openConnectionCheckRedirects(conn); 179 //is = sun.net.www.protocol.http.HttpURLConnection.openConnectionCheckRedirects(conn);
167 } catch (IOException e) { 180 } catch (IOException e) {
168 if (conn instanceof HttpURLConnection) { 181 if (conn instanceof HttpURLConnection) {
169 HttpURLConnection httpConn = ((HttpURLConnection) conn); 182 HttpURLConnection httpConn = ((HttpURLConnection) conn);
170 int code = httpConn.getResponseCode(); 183 int code = httpConn.getResponseCode();
171 if (code == 401) { 184 if (code == 401) {
172 errorReceiver.error(new SAXParseException(WscompileMessages.WSIMPORT_AUTH_INFO_NEEDED(e.getMessage(), 185 errorReceiver.error(new SAXParseException(WscompileMessages.WSIMPORT_AUTH_INFO_NEEDED(e.getMessage(),
173 systemId, DefaultAuthenticator.defaultAuthfile), null, e)); 186 systemId, WsimportOptions.defaultAuthfile), null, e));
174 throw new AbortException(); 187 throw new AbortException();
175 } 188 }
176 //FOR other code we will retry with MEX 189 //FOR other code we will retry with MEX
177 } 190 }
178 throw e; 191 throw e;
209 } 222 }
210 223
211 return inputSource; 224 return inputSource;
212 } 225 }
213 226
227 @Override
228 protected void finalize() throws Throwable {
229 //see http://java.net/jira/browse/JAX_WS-1087
230 if (doReset) {
231 c.setDefaultUseCaches(true);
232 }
233 }
214 } 234 }
215 235
216 // overide default SSL HttpClientVerifier to always return true 236 // overide default SSL HttpClientVerifier to always return true
217 // effectively overiding Hostname client verification when using SSL 237 // effectively overiding Hostname client verification when using SSL
218 private static class HttpClientVerifier implements HostnameVerifier { 238 private static class HttpClientVerifier implements HostnameVerifier {
239 @Override
219 public boolean verify(String s, SSLSession sslSession) { 240 public boolean verify(String s, SSLSession sslSession) {
220 return true; 241 return true;
221 } 242 }
222 } 243 }
223 244
261 } 282 }
262 } 283 }
263 } 284 }
264 //no wsdl with wsdl:service found, throw error 285 //no wsdl with wsdl:service found, throw error
265 if(rootWSDL == null){ 286 if(rootWSDL == null){
266 StringBuffer strbuf = new StringBuffer(); 287 StringBuilder strbuf = new StringBuilder();
267 for(String str : rootWsdls){ 288 for(String str : rootWsdls){
268 strbuf.append(str); 289 strbuf.append(str);
269 strbuf.append('\n'); 290 strbuf.append('\n');
270 } 291 }
271 errorReceiver.error(null, WsdlMessages.FAILED_NOSERVICE(strbuf.toString())); 292 errorReceiver.error(null, WsdlMessages.FAILED_NOSERVICE(strbuf.toString()));

mercurial