Author: chris.laprun(a)jboss.com
Date: 2007-03-06 01:50:49 -0500 (Tue, 06 Mar 2007)
New Revision: 6547
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java
Log:
- JBPORTAL-1279: Open the URL in a different thread and wait for it to finish for 1 second
or declare failure.
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java 2007-03-05
21:50:53 UTC (rev 6546)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java 2007-03-06
06:50:49 UTC (rev 6547)
@@ -24,6 +24,7 @@
package org.jboss.portal.wsrp.services;
import org.jboss.logging.Logger;
+import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.common.util.Tools;
import org.xml.sax.InputSource;
@@ -92,6 +93,7 @@
}
catch (Exception e)
{
+ log.info("Couldn't access WSDL information. Service won't be
available", e);
available = false;
}
}
@@ -171,9 +173,86 @@
log.info("Retrieving WSDL from " + url);
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
javax.wsdl.xml.WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
- return wsdlReader.readWSDL(new WSDLLocatorImpl(url));
+ try
+ {
+ return wsdlReader.readWSDL(new WSDLLocatorImpl(url));
+ }
+ catch (RuntimeException e)
+ {
+ throw new WSDLException(WSDLException.PARSER_ERROR, "Error while reading
WSDL", e);
+ }
}
+
+ static class URLThread extends Thread
+ {
+ volatile private URL url;
+ private InputSource inputSource;
+ /** Exception in the event a connection error occurs */
+ private IOException exception = null;
+
+ // Connect to the specified host and port number
+ public URLThread(URL wsdlFile)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(wsdlFile, "WSDL
URL");
+
+ this.url = wsdlFile;
+ }
+
+ public void run()
+ {
+ try
+ {
+ InputStream is = Tools.safeBufferedWrapper(url.openStream());
+ if (is == null)
+ {
+ throw new IllegalArgumentException("Cannot obtain wsdl from [" +
url + "]");
+ }
+
+ inputSource = new InputSource(is);
+ }
+ catch (IOException e)
+ {
+ exception = e;
+ }
+ }
+
+ public boolean isConnected()
+ {
+ if (inputSource == null)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ public boolean isError()
+ {
+ if (exception == null)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+
+ public InputSource getInputSource()
+ {
+ return inputSource;
+ }
+
+ public IOException getException()
+ {
+ return exception;
+ }
+ }
+
/** A WSDLLocator that can handle wsdl imports */
public static class WSDLLocatorImpl implements WSDLLocator
{
@@ -183,10 +262,7 @@
public WSDLLocatorImpl(URL wsdlFile)
{
- if (wsdlFile == null)
- {
- throw new IllegalArgumentException("WSDL file argument cannot be
null");
- }
+ ParameterValidation.throwIllegalArgExceptionIfNull(wsdlFile, "WSDL
URL");
this.wsdlURL = wsdlFile;
}
@@ -195,7 +271,44 @@
{
log.info("getBaseInputSource [wsdlUrl=" + wsdlURL + "]");
- // use 1 second time outs and remember previous values
+ URLThread thread = new URLThread(wsdlURL);
+ thread.start();
+
+ // Wait for the thread to finish but don't wait longer than a
+ // specified time
+ long delayMillis = 1000;
+ try
+ {
+ thread.join(delayMillis);
+
+ if (thread.isAlive())
+ {
+ // Timeout occurred; thread has not finished
+ // todo: do we need clean up here?
+ throw new RuntimeException("Couldn't connect to " + wsdlURL
+ " within " + delayMillis / 1000
+ + " seconds. Check your connection parameters or the URL.");
+ }
+ else
+ {
+ // Finished
+ if (thread.isConnected() && !thread.isError())
+ {
+ return thread.getInputSource();
+ }
+ else
+ {
+ throw new RuntimeException("An error occured while parsing the
WSDL file at " + wsdlURL,
+ thread.getException());
+ }
+ }
+ }
+ catch (InterruptedException e)
+ {
+ // Thread was interrupted
+ throw new RuntimeException("Parsing thread was interrupted!", e);
+ }
+
+ /*// use 1 second time outs and remember previous values
String connectTimeOut =
System.setProperty("sun.net.client.defaultConnectTimeout", "1000");
String readTimeOut =
System.setProperty("sun.net.client.defaultReadTimeout", "1000");
@@ -225,8 +338,7 @@
{
System.setProperty("sun.net.client.defaultReadTimeout",
readTimeOut);
}
- }
-
+ }*/
}
public String getBaseURI()