本文整理汇总了Java中com.meterware.httpunit.HttpUnitUtils类的典型用法代码示例。如果您正苦于以下问题:Java HttpUnitUtils类的具体用法?Java HttpUnitUtils怎么用?Java HttpUnitUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpUnitUtils类属于com.meterware.httpunit包,在下文中一共展示了HttpUnitUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: autoLoadServlets
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
void autoLoadServlets() {
ArrayList autoLoadable = new ArrayList();
if (_defaultMapping != null && _defaultMapping.getConfiguration().isLoadOnStartup()) autoLoadable.add( _defaultMapping.getConfiguration() );
collectAutoLoadableServlets( autoLoadable, _exactMatches );
collectAutoLoadableServlets( autoLoadable, _extensions );
collectAutoLoadableServlets( autoLoadable, _urlTree );
if (autoLoadable.isEmpty()) return;
Collections.sort( autoLoadable, new Comparator() {
public int compare( Object o1, Object o2 ) {
ServletConfiguration sc1 = (ServletConfiguration) o1;
ServletConfiguration sc2 = (ServletConfiguration) o2;
return (sc1.getLoadOrder() <= sc2.getLoadOrder()) ? -1 : +1;
}
});
for (Iterator iterator = autoLoadable.iterator(); iterator.hasNext();) {
ServletConfiguration servletConfiguration = (ServletConfiguration) iterator.next();
try {
servletConfiguration.getServlet();
} catch (Exception e) {
HttpUnitUtils.handleException(e);
throw new RuntimeException( "Unable to autoload servlet: " + servletConfiguration.getClassName() + ": " + e );
}
}
}
示例2: testSomeFailuresXMLFormat
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
public void testSomeFailuresXMLFormat() throws Exception {
ServletUnitClient client = newClient();
WebResponse wr = client.getResponse( "http://localhost/JUnit?format=xml&test=" + FailingTests.class.getName() );
assertEquals( "Content type", "text/xml", wr.getContentType() );
DocumentBuilder builder = HttpUnitUtils.newParser();
Document document = builder.parse( wr.getInputStream() );
Element element = document.getDocumentElement();
assertEquals( "document element name", "testsuite", element.getNodeName() );
assertEquals( "number of tests", "3", element.getAttribute( "tests" ) );
assertEquals( "number of failures", "2", element.getAttribute( "failures" ) );
assertEquals( "number of errors", "0", element.getAttribute( "errors" ) );
NodeList nl = element.getElementsByTagName( "testcase" );
verifyElementWithNameHasFailureNode( "testAddition", nl, /* failed */ "failure", true );
verifyElementWithNameHasFailureNode( "testSubtraction", nl, /* failed */ "failure", true );
verifyElementWithNameHasFailureNode( "testMultiplication", nl, /* failed */ "failure", false );
}
示例3: testSomeErrorsXMLFormat
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
public void testSomeErrorsXMLFormat() throws Exception {
ServletUnitClient client = newClient();
WebResponse wr = client.getResponse( "http://localhost/JUnit?format=xml&test=" + ErrorTests.class.getName() );
assertEquals( "Content type", "text/xml", wr.getContentType() );
DocumentBuilder builder = HttpUnitUtils.newParser();
Document document = builder.parse( wr.getInputStream() );
Element element = document.getDocumentElement();
assertEquals( "document element name", "testsuite", element.getNodeName() );
assertEquals( "number of tests", "2", element.getAttribute( "tests" ) );
assertEquals( "number of failures", "0", element.getAttribute( "failures" ) );
assertEquals( "number of errors", "1", element.getAttribute( "errors" ) );
NodeList nl = element.getElementsByTagName( "testcase" );
verifyElementWithNameHasFailureNode( "testAddition", nl, /* failed */ "error", true );
verifyElementWithNameHasFailureNode( "testMultiplication", nl, /* failed */ "error", false );
}
示例4: ServletUnitHttpRequest
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
/**
* Constructs a ServletUnitHttpRequest from a WebRequest object.
**/
ServletUnitHttpRequest( ServletMetaData servletRequest, WebRequest request, ServletUnitContext context, Dictionary clientHeaders, byte[] messageBody ) throws MalformedURLException {
if (context == null) throw new IllegalArgumentException( "Context must not be null" );
_servletRequest = servletRequest;
_request = request;
_context = context;
_headers = new WebClient.HeaderDictionary();
_headers.addEntries( clientHeaders );
_headers.addEntries( request.getHeaders() );
setCookiesFromHeader( _headers );
_messageBody = messageBody;
_protocol=request.getURL().getProtocol().toLowerCase();
_secure = _protocol.endsWith("s" );
_requestContext = new RequestContext( request.getURL() );
String contentTypeHeader = (String) _headers.get( "Content-Type" );
if (contentTypeHeader != null) {
String[] res = HttpUnitUtils.parseContentTypeHeader( contentTypeHeader );
_contentType = res[0];
_charset = res[1];
_requestContext.setMessageEncoding( _charset );
}
if (_headers.get( "Content-Length") == null) _headers.put( "Content-Length", Integer.toString( messageBody.length ) );
boolean setBody=
// pre [ 1509117 ] getContentType()
// _messageBody != null && (_contentType == null || _contentType.indexOf( "x-www-form-urlencoded" ) >= 0 );
// patch version:
_messageBody != null && (contentTypeHeader == null || contentTypeHeader.indexOf( "x-www-form-urlencoded" ) >= 0 );
if (setBody) {
_requestContext.setMessageBody( _messageBody );
}
}
示例5: ServletRunner
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
/**
* Constructor which expects an input stream containing the web.xml for the application.
* @param webXML
* @param contextPath
* @throws IOException
* @throws SAXException
*/
public ServletRunner( InputStream webXML, String contextPath ) throws IOException, SAXException {
InputSource inputSource=new InputSource( webXML );
Document doc=HttpUnitUtils.parse(inputSource);
try {
_application = new WebApplication( doc, contextPath );
completeInitialization( contextPath );
} catch (java.net.MalformedURLException mue) {
throw mue;
}
}
示例6: loadParameters
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
/**
* This method employs a state machine to parse a parameter query string.
* The transition rules are as follows:
* State \ text '=' '&'
* initial: have_name - initial
* have_name: - have_equals initial
* have_equals: have_value - initial
* have_value: - initial initial
* actions occur on the following transitions:
* initial -> have_name: save token as name
* have_equals -> initial: record parameter with null value
* have_value -> initial: record parameter with value
**/
void loadParameters( String queryString ) {
if (queryString.length() == 0) return;
StringTokenizer st = new StringTokenizer( queryString, "&=", /* return tokens */ true );
int state = STATE_INITIAL;
String name = null;
String value = null;
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (token.equals( "&" )) {
state = STATE_INITIAL;
if (name != null && value != null) addParameter( name, value );
name = value = null;
} else if (token.equals( "=" )) {
if (state == STATE_HAVE_NAME) {
state = STATE_HAVE_EQUALS;
} else if (state == STATE_HAVE_VALUE) {
state = STATE_INITIAL;
}
} else if (state == STATE_INITIAL) {
name = HttpUnitUtils.decode( token, getMessageEncoding() );
value = "";
state = STATE_HAVE_NAME;
} else {
value = HttpUnitUtils.decode( token, getMessageEncoding() );
state = STATE_HAVE_VALUE;
}
}
if (name != null && value != null) addParameter( name, value );
}
示例7: handleScriptException
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
/**
* handle Exceptions
* @param e - the exception to handle
* @param badScript - the script that caused the problem
*/
static public void handleScriptException( Exception e, String badScript ) {
final String errorMessage = badScript + " failed: " + e;
if (!(e instanceof EcmaError) && !(e instanceof EvaluatorException)) {
HttpUnitUtils.handleException(e);
throw new RuntimeException( errorMessage );
} else if (JavaScript.isThrowExceptionsOnError()) {
HttpUnitUtils.handleException(e);
throw new ScriptException( errorMessage );
} else {
_errorMessages.add( errorMessage );
}
}
示例8: getMessage
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
public String getMessage() {
StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE);
sb.append( "May not set parameter '" ).append( _parameterName ).append( "' to '" );
sb.append( _badValue ).append( "'. Value must be one of: { " );
for (int i = 0; i < _allowedValues.length; i++) {
if (i != 0) sb.append( ", " );
sb.append( "'"+ _allowedValues[i] +"'" );
}
sb.append( " }" );
return sb.toString();
}
示例9: readParameters
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
private Hashtable readParameters( String content ) {
Hashtable parameters = new Hashtable();
if (content == null || content.trim().length() == 0) return parameters;
StringTokenizer st = new StringTokenizer( content, "&=" );
while (st.hasMoreTokens()) {
String name = st.nextToken();
if (st.hasMoreTokens()) {
addParameter( parameters, HttpUnitUtils.decode( name ), HttpUnitUtils.decode( st.nextToken() ) );
}
}
return parameters;
}
示例10: setContentType
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
/**
* Sets the content type of the response the server sends to
* the client. The content type may include the type of character
* encoding used, for example, <code>text/html; charset=ISO-8859-4</code>.
*
* <p>You can only use this method once, and you should call it
* before you obtain a <code>PrintWriter</code> or
* {@link ServletOutputStream} object to return a response.
**/
public void setContentType( String type ) {
String[] typeAndEncoding = HttpUnitUtils.parseContentTypeHeader( type );
_contentType = typeAndEncoding[0];
if (typeAndEncoding[1] != null) _encoding = typeAndEncoding[1];
if (_encoding.equalsIgnoreCase( HttpUnitUtils.DEFAULT_CHARACTER_SET )) {
setHeader( "Content-Type", type );
} else {
setHeader( "Content-Type", _contentType + "; charset=" + _encoding );
}
}
示例11: loadParameters
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
/**
* This method employs a state machine to parse a parameter query string.
* The transition rules are as follows:
* State \ text '=' '&'
* initial: have_name - initial
* have_name: - have_equals initial
* have_equals: have_value - initial
* have_value: - initial initial
* actions occur on the following transitions:
* initial -> have_name: save token as name
* have_equals -> initial: record parameter with null value
* have_value -> initial: record parameter with value
**/
void loadParameters( String queryString ) {
if (queryString.length() == 0) return;
StringTokenizer st = new StringTokenizer( queryString, "&=", /* return tokens */ true );
int state = STATE_INITIAL;
String name = null;
String value = null;
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (token.equals( "&" )) {
state = STATE_INITIAL;
if (name != null && value != null) addParameter( name, value );
name = value = null;
} else if (token.equals( "=" )) {
if (state == STATE_HAVE_NAME) {
state = STATE_HAVE_EQUALS;
} else if (state == STATE_HAVE_VALUE) {
state = STATE_INITIAL;
}
} else if (state == STATE_INITIAL) {
name = HttpUnitUtils.decode( token );
value = "";
state = STATE_HAVE_NAME;
} else {
value = HttpUnitUtils.decode( token );
state = STATE_HAVE_VALUE;
}
}
if (name != null && value != null) addParameter( name, value );
}
示例12: getCharacterSet
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
String getCharacterSet() {
return HttpUnitUtils.stripQuotes( _characterSet );
}
示例13: ServletRunner
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
/**
* Constructor which expects an input stream containing the web.xml for the application.
**/
public ServletRunner( InputStream webXML, String contextPath ) throws IOException, SAXException {
_application = new WebApplication( HttpUnitUtils.newParser().parse( new InputSource( webXML ) ), contextPath );
completeInitialization( contextPath );
}
示例14: setContentType
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
/**
* Sets the content type of the response the server sends to
* the client. The content type may include the type of character
* encoding used, for example, <code>text/html; charset=ISO-8859-4</code>.
*
* <p>You can only use this method once, and you should call it
* before you obtain a <code>PrintWriter</code> or
* {@link ServletOutputStream} object to return a response.
**/
public void setContentType( String type ) {
String[] typeAndEncoding = HttpUnitUtils.parseContentTypeHeader( type );
_contentType = typeAndEncoding[0];
if (typeAndEncoding[1] != null) _encoding = typeAndEncoding[1];
}
示例15: getCharacterEncoding
import com.meterware.httpunit.HttpUnitUtils; //导入依赖的package包/类
/**
* Returns the name of the character set encoding used for
* the MIME body sent by this response.
**/
public String getCharacterEncoding() {
return _encoding == null ? HttpUnitUtils.DEFAULT_CHARACTER_SET : _encoding;
}