/** * Creates a new URL, handling the case where the relative URL begins with a '?' * @param base - the URL to start from * @param spec - additional specification string * @return the URL */ private URL newURL( final URL base, final String spec ) throws MalformedURLException { if (spec.toLowerCase().startsWith( "javascript:" )) { return new URL( "javascript", null, -1, spec.substring( "javascript:".length() ), JAVASCRIPT_STREAM_HANDLER ); } else if (spec.toLowerCase().startsWith( "https:" ) && !HttpsProtocolSupport.hasHttpsSupport()) { return new URL( "https", null, -1, spec.substring( "https:".length() ), HTTPS_STREAM_HANDLER ); } else { if (getURLBase() == null || getURLString().indexOf( ':' ) > 0) { if (getURLString().indexOf(':') <= 0) { throw new RuntimeException( "No protocol specified in URL '" + getURLString() + "'" ); } HttpsProtocolSupport.verifyProtocolSupport( getURLString().substring( 0, getURLString().indexOf( ':' ) ) ); } return spec.startsWith( "?" ) ? new URL( base + spec ) : newCombinedURL( base, spec ); } }
/** * Creates a new URL, handling the case where the relative URL begins with a '?' * @param base - the URL to start from * @param spec - additional specification string * @return the URL */ private URL newURL( final URL base, final String spec ) throws MalformedURLException { if (spec.toLowerCase().startsWith( "javascript:" )) { return new URL( "javascript", null, -1, spec.substring( "javascript:".length() ), JAVASCRIPT_STREAM_HANDLER ); } else if (spec.toLowerCase().startsWith( "https:" ) && !HttpsProtocolSupport.hasHttpsSupport()) { return new URL( "https", null, -1, spec.substring( "https:".length() ), HTTPS_STREAM_HANDLER ); } else { if (getURLBase() == null || getURLString().indexOf( ':' ) > 0) { if (getURLString().indexOf(':') <= 0) { throw new RuntimeException( "No protocol specified in URL '" + getURLString() + "'" ); } HttpsProtocolSupport.verifyProtocolSupport( getURLString().substring( 0, getURLString().indexOf( ':' ) ) ); } return spec.startsWith( "?" ) ? new URL( base + spec ) : newCombinedURL( base, spec ); } }
/** * Creates a new URL, handling the case where the relative URL begins with a '?' * @param base - the URL to start from * @param spec - additional specification string * @return the URL */ private URL newURL( final URL base, final String spec ) throws MalformedURLException { if (spec.toLowerCase().startsWith( "javascript:" )) { return new URL( "javascript", null, -1, spec.substring( "javascript:".length() ), JAVASCRIPT_STREAM_HANDLER ); } else if (spec.toLowerCase().startsWith( "https:" ) && !HttpsProtocolSupport.hasHttpsSupport()) { return new URL( "https", null, -1, spec.substring( "https:".length() ), HTTPS_STREAM_HANDLER ); } else { if (getURLBase() == null || getURLString().indexOf( ':' ) > 0) { if (getURLString().indexOf(':') <= 0) { throw new RuntimeException( "No protocol specified in URL '" + getURLString() + "'" ); } HttpsProtocolSupport.verifyProtocolSupport( getURLString().substring( 0, getURLString().indexOf( ':' ) ) ); } return spec.startsWith( "?" ) ? new URL( base + spec ) : newCombinedURL( base, spec ); } }
/** * Returns the final URL associated with this web request. * @return the Uniform Resource Locator for this Web request * @throws MalformedURLException if the URL is not o.k. **/ public URL getURL() throws MalformedURLException { if (getURLBase() == null || getURLBase().toString().indexOf( "?" ) < 0) { return newURL( getURLBase(), getURLString() ); } else { final String urlBaseString = getURLBase().toString(); URL newurlbase = new URL( urlBaseString.substring( 0, urlBaseString.indexOf( "?" ) ) ); return newURL( newurlbase, getURLString() ); } }
/** * Returns the final URL associated with this web request. * @return the Uniform Resource Locator for this Web request * @throws MalformedURLException if the URL is not o.k. **/ public URL getURL() throws MalformedURLException { if (getURLBase() == null || getURLBase().toString().indexOf( "?" ) < 0) { return newURL( getURLBase(), getURLString() ); } else { final String urlBaseString = getURLBase().toString(); URL newurlbase = new URL( urlBaseString.substring( 0, urlBaseString.indexOf( "?" ) ) ); return newURL( newurlbase, getURLString() ); } }
/** * Returns the final URL associated with this web request. * @return the Uniform Resource Locator for this Web request * @throws MalformedURLException if the URL is not o.k. **/ public URL getURL() throws MalformedURLException { if (getURLBase() == null || getURLBase().toString().indexOf( "?" ) < 0) { return newURL( getURLBase(), getURLString() ); } else { final String urlBaseString = getURLBase().toString(); URL newurlbase = new URL( urlBaseString.substring( 0, urlBaseString.indexOf( "?" ) ) ); return newURL( newurlbase, getURLString() ); } }
public String toString() { return getMethod() + " request for (" + getURLBase() + ") " + getURLString(); }
public String toString() { return getMethod() + " request for (" + getURLBase() + ") " + getURLString(); }
public String toString() { return getMethod() + " request for (" + getURLBase() + ") " + getURLString(); }
/** * Creates a web response object which represents the response to the specified web request. **/ protected WebResponse newResponse( WebRequest request, FrameSelector targetFrame ) throws MalformedURLException, IOException { Properties savedProperties = (Properties) System.getProperties().clone(); try { if (_proxyHost != null) { System.setProperty( "proxyHost", _proxyHost ); System.setProperty( "proxyPort", Integer.toString( _proxyPort ) ); } URLConnection connection = openConnection( getRequestURL( request ) ); // [ 1518901 ] enable http connect and read timeouts (needs JDK 1.5) // XXX enable for 1.7 release in 2008 // comment out if you need this and have JDK 1.5 // if (_connectTimeout>=0) connection.setConnectTimeout( _connectTimeout ); // if (_readTimeout>=0) connection.setReadTimeout( _readTimeout ); if (HttpUnitOptions.isLoggingHttpHeaders()) { String urlString = request.getURLString(); System.out.println( "\nConnecting to " + request.getURL().getHost() ); System.out.println( "Sending:: " + request.getMethod() + " " + urlString ); } sendHeaders( connection, getHeaderFields( request.getURL() ) ); sendHeaders( connection, request.getHeaderDictionary() ); request.completeRequest( connection ); return new HttpWebResponse( this, targetFrame, request, connection, getExceptionsThrownOnErrorStatus() ); } finally { System.setProperties( savedProperties ); } }
/** * Creates a web response object which represents the response to the specified web request. **/ protected WebResponse newResponse( WebRequest request, FrameSelector targetFrame ) throws MalformedURLException, IOException { Properties savedProperties = (Properties) System.getProperties().clone(); try { if (_proxyHost != null) { System.setProperty( "proxyHost", _proxyHost ); System.setProperty( "proxyPort", Integer.toString( _proxyPort ) ); } URLConnection connection = openConnection( getRequestURL( request ) ); // [ 1518901 ] enable http connect and read timeouts (needs JDK 1.5) // XXX enable for 1.7 release in 2008 // comment out if you need this and have JDK 1.5 // if (_connectTimeout>=0) connection.setConnectTimeout( _connectTimeout ); // if (_readTimeout>=0) connection.setReadTimeout( _readTimeout ); if (HttpUnitOptions.isLoggingHttpHeaders()) { String urlString = request.getURLString(); System.out.println( "\nConnecting to " + request.getURL().getHost() ); System.out.println( "Sending:: " + request.getMethod() + " " + urlString ); } sendHeaders( connection, getHeaderFields( request.getURL() ) ); sendHeaders( connection, request.getHeaderDictionary() ); request.completeRequest( connection ); return new HttpWebResponse( this, targetFrame, request, connection, getExceptionsThrownOnErrorStatus() ); } finally { System.setProperties( savedProperties ); } }
/** * Creates a web response object which represents the response to the specified web request. **/ protected WebResponse newResponse( WebRequest request, FrameSelector targetFrame ) throws MalformedURLException, IOException { Properties savedProperties = (Properties) System.getProperties().clone(); try { if (_proxyHost != null) { System.setProperty( "proxyHost", _proxyHost ); System.setProperty( "proxyPort", Integer.toString( _proxyPort ) ); } URLConnection connection = openConnection( getRequestURL( request ) ); // [ 1518901 ] enable http connect and read timeouts (needs JDK 1.5) // XXX enable for 1.7 release in 2008 // comment out if you need this and have JDK 1.5 // if (_connectTimeout>=0) connection.setConnectTimeout( _connectTimeout ); // if (_readTimeout>=0) connection.setReadTimeout( _readTimeout ); if (HttpUnitOptions.isLoggingHttpHeaders()) { String urlString = request.getURLString(); System.out.println( "\nConnecting to " + request.getURL().getHost() ); System.out.println( "Sending:: " + request.getMethod() + " " + urlString ); } sendHeaders( connection, getHeaderFields( request.getURL() ) ); sendHeaders( connection, request.getHeaderDictionary() ); request.completeRequest( connection ); return new HttpWebResponse( this, targetFrame, request, connection, getExceptionsThrownOnErrorStatus() ); } finally { System.setProperties( savedProperties ); } }
void updateFrames( WebResponse response, FrameSelector frame, RequestContext requestContext ) throws MalformedURLException, IOException, SAXException { removeSubFrames( frame ); _contents.put( frame, response ); if (response.isHTML()) { HttpUnitOptions.getScriptingEngine().associate( response ); requestContext.addNewResponse( response ); WebRequest[] requests = response.getFrameRequests(); if (requests.length > 0) { createSubFrames( frame, response.getFrameSelectors() ); for (int i = 0; i < requests.length; i++) { if (requests[i].getURLString().length() != 0) { response.getWindow().getSubframeResponse( requests[i], requestContext ); } } } } }
void updateFrames( WebResponse response, FrameSelector frame, RequestContext requestContext ) throws MalformedURLException, IOException, SAXException { removeSubFrames( frame ); _contents.put( frame, response ); if (response.isHTML()) { HttpUnitOptions.getScriptingEngine().associate( response ); requestContext.addNewResponse( response ); WebRequest[] requests = response.getFrameRequests(); if (requests.length > 0) { createSubFrames( frame, response.getFrameSelectors() ); for (int i = 0; i < requests.length; i++) { if (requests[i].getURLString().length() != 0) { response.getWindow().getSubframeResponse( requests[i], requestContext ); } } } } }
void updateFrames( WebResponse response, FrameSelector frame, RequestContext requestContext ) throws MalformedURLException, IOException, SAXException { removeSubFrames( frame ); _contents.put( frame, response ); if (response.isHTML()) { HttpUnitOptions.getScriptingEngine().associate( response ); requestContext.addNewResponse( response ); WebRequest[] requests = response.getFrameRequests(); if (requests.length > 0) { createSubFrames( frame, response.getFrameSelectors() ); for (int i = 0; i < requests.length; i++) { if (requests[i].getURLString().length() != 0) { response.getWindow().getSubframeResponse( requests[i], requestContext ); } } } } }
/** * Returns the resource specified by the request. Does not update the window or load included framesets. * May return null if the resource is a JavaScript URL which would normally leave the client unchanged. */ public WebResponse getResource( WebRequest request ) throws IOException { _client.tellListeners( request ); WebResponse response = null; String urlString = request.getURLString().trim(); FrameSelector targetFrame = _frameContents.getTargetFrame( request ); if (urlString.startsWith( "about:" )) { response = new DefaultWebResponse( _client, targetFrame, null, "" ); } else if (!HttpUnitUtils.isJavaScriptURL( urlString )) { response = _client.createResponse( request, targetFrame ); } else { ScriptingHandler handler = request.getSourceScriptingHandler(); if (handler == null) handler = getCurrentPage().getScriptingHandler(); Object result = handler.evaluateExpression( urlString ); if (result != null) { response = new DefaultWebResponse( _client, targetFrame, request.getURL(), result.toString() ); } } if (response != null) _client.tellListeners( response ); return response; }
/** * Returns the resource specified by the request. Does not update the window or load included framesets. * May return null if the resource is a JavaScript URL which would normally leave the client unchanged. */ public WebResponse getResource( WebRequest request ) throws IOException { _client.tellListeners( request ); WebResponse response = null; String urlString = request.getURLString().trim(); FrameSelector targetFrame = _frameContents.getTargetFrame( request ); if (urlString.startsWith( "about:" )) { response = new DefaultWebResponse( _client, targetFrame, null, "" ); } else if (!HttpUnitUtils.isJavaScriptURL( urlString )) { response = _client.createResponse( request, targetFrame ); } else { ScriptingHandler handler = request.getSourceScriptingHandler(); if (handler == null) handler = getCurrentPage().getScriptingHandler(); Object result = handler.evaluateExpression( urlString ); if (result != null) { response = new DefaultWebResponse( _client, targetFrame, request.getURL(), result.toString() ); } } if (response != null) _client.tellListeners( response ); return response; }
/** * Returns the resource specified by the request. Does not update the window or load included framesets. * May return null if the resource is a JavaScript URL which would normally leave the client unchanged. */ public WebResponse getResource( WebRequest request ) throws IOException { _client.tellListeners( request ); WebResponse response = null; String urlString = request.getURLString().trim(); FrameSelector targetFrame = _frameContents.getTargetFrame( request ); if (urlString.startsWith( "about:" )) { response = new DefaultWebResponse( _client, targetFrame, null, "" ); } else if (!HttpUnitUtils.isJavaScriptURL( urlString )) { response = _client.createResponse( request, targetFrame ); } else { ScriptingHandler handler = request.getSourceScriptingHandler(); if (handler == null) handler = getCurrentPage().getScriptingHandler(); Object result = handler.evaluateExpression( urlString ); if (result != null) { response = new DefaultWebResponse( _client, targetFrame, request.getURL(), result.toString() ); } } if (response != null) _client.tellListeners( response ); return response; }