/** * Resets all options to their default values. */ public static void reset() { _exceptionsOnErrorStatus = true; _parameterValuesValidated = true; _imagesTreatedAsAltText = false; _loggingHttpHeaders = false; _matchesIgnoreCase = true; _checkContentLength = false; _redirectDelay = 0; // TODO move this to ClientProperties _characterSet = HttpUnitUtils.DEFAULT_CHARACTER_SET; _contentType = DEFAULT_CONTENT_TYPE; _postIncludesCharset = false; _exceptionsThrownOnScriptError = true; _customAttributes = null; _javaScriptOptimizationLevel = -1; setScriptEngineClassName( DEFAULT_SCRIPT_ENGINE_FACTORY ); setScriptingEnabled( true ); }
public static ScriptingEngineFactory getScriptingEngine() { if (_scriptingEngine == null) { try { Class factoryClass = Class.forName( _scriptEngineClassName ); final ScriptingEngineFactory factory = (ScriptingEngineFactory) factoryClass.newInstance(); _scriptingEngine = factory.isEnabled() ? factory : NULL_SCRIPTING_ENGINE_FACTORY; _scriptingEngine.setThrowExceptionsOnError( _exceptionsThrownOnScriptError ); } catch (ClassNotFoundException e) { disableScripting( e, "Unable to find scripting engine factory class " ); } catch (InstantiationException e) { disableScripting( e, "Unable to instantiate scripting engine factory class " ); } catch (IllegalAccessException e) { disableScripting( e, "Unable to create scripting engine factory class " ); } } return _scriptingEngine; }
private String getMessageEncoding() { return _messageEncoding == null ? /* Fixing 1705925: HttpUnitUtils.DEFAULT_CHARACTER_SET */ HttpUnitOptions.getDefaultCharacterSet() : _messageEncoding; }
private void readContentTypeHeader() { String contentHeader = (_contentHeader != null) ? _contentHeader : getHeaderField( "Content-type" ); if (contentHeader == null) { _contentType = HttpUnitOptions.getDefaultContentType(); setCharacterSet( HttpUnitOptions.getDefaultCharacterSet() ); _contentHeader = _contentType + ";charset=" + _characterSet; } else { String[] parts = HttpUnitUtils.parseContentTypeHeader( contentHeader ); if (null != _client && null != _client.getClientProperties().getOverrideContextType()) { _contentType = _client.getClientProperties().getOverrideContextType(); } else { _contentType = parts[0]; } if (parts[1] != null) setCharacterSet( parts[1] ); } }
static ParameterHolder newParameterHolder( WebRequestSource requestSource ) { if (HttpUnitOptions.getParameterValuesValidated()) { return requestSource; } else { return new UncheckedParameterHolder( requestSource ); } }
/** * Return true if the first string equals the second. * Case sensitivity is according to the setting of HttpUnitOptions.matchesIgnoreCase */ static boolean matches( String string1, String string2 ) { if (HttpUnitOptions.getMatchesIgnoreCase()) { return string1.equalsIgnoreCase( string2 ); } else { return string1.equals( string2 ); } }
private static WebConversation createWebConversation() { HttpUnitOptions.setScriptingEnabled(false); return new WebConversation(); }
/** * Returns a web response built from a URL connection. Provided to allow * access to WebResponse parsing without using a WebClient. **/ public static WebResponse newResponse( URLConnection connection ) throws IOException { return new HttpWebResponse( null, FrameSelector.TOP_FRAME, connection.getURL(), connection, HttpUnitOptions.getExceptionsThrownOnErrorStatus() ); }
public boolean processElement( PreOrderTraversal traversal, Element node ) { String nodeName = node.getNodeName().toLowerCase(); if (nodeName.equals( "p" ) || nodeName.equals( "br" ) || nodeName.equalsIgnoreCase( "tr" )) { sb.append( "\n" ); } else if (nodeName.equals( "td" ) || nodeName.equalsIgnoreCase( "th" )) { sb.append( " | " ); } else if (nodeName.equals( "img" ) && HttpUnitOptions.getImagesTreatedAsAltText()) { sb.append( getNodeAttribute( node, "alt" ) ); } return true; } public void processTextNode( PreOrderTraversal traversal, Node textNode ) {
/** * Initiates JavaScript execution for the specified web response. */ public static void run( WebResponse response ) throws IllegalAccessException, InstantiationException, InvocationTargetException, ClassDefinitionException, NotAFunctionException, PropertyException, SAXException, JavaScriptException { Context context = Context.enter(); // suggest bug fix for large java scripts see // bug report [ 1216567 ] Exception for large javascripts // by Grzegorz Lukasik // and context.setOptimizationLevel(HttpUnitOptions.getJavaScriptOptimizationLevel()); Scriptable scope = context.initStandardObjects( null ); initHTMLObjects( scope ); Window w = (Window) context.newObject( scope, "Window" ); w.initialize( null, response.getScriptableObject() ); }
/** * initialize the given form control from a Webform and a HTMLControl * @param form * @param control */ protected FormControl( WebForm form, HTMLControl control ) { super( control ); _control = control; _form = form; supportAttribute( "tabindex" ); supportAttribute( "disabled" ); // Add all custom attributes Set customAttributes = HttpUnitOptions.getCustomAttributes(); if(customAttributes != null) { for(Iterator iter = customAttributes.iterator(); iter.hasNext(); ) { supportAttribute((String)iter.next()); } } }
private void readContentTypeHeader() { String contentHeader = (_contentHeader != null) ? _contentHeader : getHeaderField( "Content-type" ); if (contentHeader == null) { _contentType = HttpUnitOptions.getDefaultContentType(); setCharacterSet( HttpUnitOptions.getDefaultCharacterSet() ); _contentHeader = _contentType + ";charset=" + _characterSet; } else { String[] parts = HttpUnitUtils.parseContentTypeHeader( contentHeader ); if (null != _client && null != _client.getClientProperties().getOverrideContextType()) { _contentType = _client.getClientProperties().getOverrideContextType(); } else { _contentType = parts[0]; } if (parts[1] != null) setCharacterSet( parts[1] ); } }
static ParameterHolder newParameterHolder( WebRequestSource requestSource ) { if (HttpUnitOptions.getParameterValuesValidated()) { return requestSource; } else { return new UncheckedParameterHolder( requestSource ); } }
/** * Return true if the first string equals the second. * Case sensitivity is according to the setting of HttpUnitOptions.matchesIgnoreCase */ static boolean matches( String string1, String string2 ) { if (HttpUnitOptions.getMatchesIgnoreCase()) { return string1.equalsIgnoreCase( string2 ); } else { return string1.equals( string2 ); } }
private JavaNet(WebConversation wc) { super(null); this.wc = wc; // disable scripting support HttpUnitOptions.setScriptingEnabled(false); // java.net security certificate cause a problem. So avoid it by disabling certificate validation. SSLTrustAllManager.install(); // we need this to work around the broken cookies in java.net CookieProperties.setDomainMatchingStrict(false); // IssueZilla always have a DTD but for a restricted access project, it fails to resolve. // so just stop looking at DTD altogether. try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false); wc.setDocumentBuilderFactory(dbf); } catch (ParserConfigurationException e) { throw new Error(e); } }
/** * Returns a web response built from a URL connection. Provided to allow * access to WebResponse parsing without using a WebClient. **/ public static WebResponse newResponse( URLConnection connection ) throws IOException { return new HttpWebResponse( null, FrameSelector.TOP_FRAME, connection.getURL(), connection, HttpUnitOptions.getExceptionsThrownOnErrorStatus() ); }
public boolean processElement( PreOrderTraversal traversal, Element node ) { String nodeName = node.getNodeName().toLowerCase(); if (nodeName.equals( "p" ) || nodeName.equals( "br" ) || nodeName.equalsIgnoreCase( "tr" )) { sb.append( "\n" ); } else if (nodeName.equals( "td" ) || nodeName.equalsIgnoreCase( "th" )) { sb.append( " | " ); } else if (nodeName.equals( "img" ) && HttpUnitOptions.getImagesTreatedAsAltText()) { sb.append( getNodeAttribute( node, "alt" ) ); } return true; } public void processTextNode( PreOrderTraversal traversal, Node textNode ) {
/** * Initiates JavaScript execution for the specified web response. */ public static void run( WebResponse response ) throws IllegalAccessException, InstantiationException, InvocationTargetException, ClassDefinitionException, NotAFunctionException, PropertyException, SAXException, JavaScriptException { Context context = Context.enter(); // suggest bug fix for large java scripts see // bug report [ 1216567 ] Exception for large javascripts // by Grzegorz Lukasik // and context.setOptimizationLevel(HttpUnitOptions.getJavaScriptOptimizationLevel()); Scriptable scope = context.initStandardObjects( null ); initHTMLObjects( scope ); Window w = (Window) context.newObject( scope, "Window" ); w.initialize( null, response.getScriptableObject() ); }
/** * initialize the given form control from a Webform and a HTMLControl * @param form * @param control */ protected FormControl( WebForm form, HTMLControl control ) { super( control ); _control = control; _form = form; supportAttribute( "tabindex" ); supportAttribute( "disabled" ); // Add all custom attributes Set customAttributes = HttpUnitOptions.getCustomAttributes(); if(customAttributes != null) { for(Iterator iter = customAttributes.iterator(); iter.hasNext(); ) { supportAttribute((String)iter.next()); } } }
/** * Resets all options to their default values. */ public static void reset() { _exceptionsOnErrorStatus = true; _parameterValuesValidated = true; _imagesTreatedAsAltText = false; _loggingHttpHeaders = false; _matchesIgnoreCase = true; _checkContentLength = false; _redirectDelay = 0; // TODO move this to ClientProperties _characterSet = HttpUnitUtils.DEFAULT_CHARACTER_SET; _contentType = DEFAULT_CONTENT_TYPE; _postIncludesCharset = false; _exceptionsThrownOnScriptError = true; _customAttributes = null; _javaScriptOptimizationLevel = -1; setScriptEngineClassName( DEFAULT_SCRIPT_ENGINE_FACTORY ); setScriptingEnabled( true ); }