com.meterware.httpunit.WebRequest.getURLString()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(14.3k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中com.meterware.httpunit.WebRequest.getURLString()方法的一些代码示例,展示了WebRequest.getURLString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebRequest.getURLString()方法的具体详情如下:
包路径:com.meterware.httpunit.WebRequest
类名称:WebRequest
方法名:getURLString

WebRequest.getURLString介绍

暂无

代码示例

代码示例来源:origin: httpunit/httpunit

/**
 * 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 );
  }
}

代码示例来源:origin: javanettasks/httpunit

/**
 * 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 );
  }
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

/**
 * 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 );
  }
}

代码示例来源:origin: javanettasks/httpunit

/**
 * 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() );
  }
}

代码示例来源:origin: httpunit/httpunit

/**
 * 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() );
  }
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

/**
 * 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() );
  }
}

代码示例来源:origin: javanettasks/httpunit

public String toString() {
  return getMethod() + " request for (" + getURLBase() + ") " + getURLString();
}

代码示例来源:origin: httpunit/httpunit

public String toString() {
  return getMethod() + " request for (" + getURLBase() + ") " + getURLString();
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

public String toString() {
  return getMethod() + " request for (" + getURLBase() + ") " + getURLString();
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

/**
 * 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 );
  }
}

代码示例来源:origin: httpunit/httpunit

/**
 * 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 );
  }
}

代码示例来源:origin: javanettasks/httpunit

/**
 * 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 );
  }
}

代码示例来源:origin: httpunit/httpunit

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 );
        }
      }
    }
  }
}

代码示例来源:origin: javanettasks/httpunit

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 );
        }
      }
    }
  }
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

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 );
        }
      }
    }
  }
}

代码示例来源:origin: javanettasks/httpunit

/**
 * 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;
}

代码示例来源:origin: httpunit/httpunit

/**
 * 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;
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

/**
 * 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;
}

相关文章