当前位置: 首页>>代码示例>>Java>>正文


Java WebRequest类代码示例

本文整理汇总了Java中com.meterware.httpunit.WebRequest的典型用法代码示例。如果您正苦于以下问题:Java WebRequest类的具体用法?Java WebRequest怎么用?Java WebRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WebRequest类属于com.meterware.httpunit包,在下文中一共展示了WebRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ServletUnitHttpRequest

import com.meterware.httpunit.WebRequest; //导入依赖的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() );
    _messageBody = messageBody;
    _secure = request.getURL().getProtocol().equalsIgnoreCase( "https" );
    _contentType = (String) _headers.get( "Content-Type" );
    if (_headers.get( "Content-Length") == null) _headers.put( "Content-Length", Integer.toString( messageBody.length ) );

    _requestContext = new RequestContext( request.getURL() );
    if (_messageBody != null && (_contentType == null || _contentType.indexOf( "x-www-form-urlencoded" ) >= 0 )) {
        _requestContext.loadParameters( new String( _messageBody ) );
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:23,代码来源:ServletUnitHttpRequest.java

示例2: InvocationContextImpl

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
/**
 * Constructs a servlet invocation context for a specified servlet container,
 * request, and cookie headers.
 **/
InvocationContextImpl( ServletUnitClient client, ServletRunner runner, String target, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
    _client      = client;
    _application = runner.getApplication();
    _requestURL  = request.getURL();
    _target      = target;

    final ServletUnitHttpRequest suhr = new ServletUnitHttpRequest( _application.getServletRequest( _requestURL ), request, runner.getContext(),
                                                   clientHeaders, messageBody );
    _request = suhr;
    Cookie[] cookies = getCookies( clientHeaders );
    for (int i = 0; i < cookies.length; i++) suhr.addCookie( cookies[i] );

    if (_application.usesBasicAuthentication()) suhr.readBasicAuthentication();
    else if (_application.usesFormAuthentication()) suhr.readFormAuthentication();

    HttpSession session = _request.getSession( /* create */ false );
    if (session != null) ((ServletUnitHttpSession) session).access();
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:23,代码来源:InvocationContextImpl.java

示例3: testGetSessionForFirstTime

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
public void testGetSessionForFirstTime() throws MalformedURLException {
    WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
    ServletUnitContext context = new ServletUnitContext();
    assertEquals( "Initial number of sessions in context", 0, context.getSessionIDs().size() );

    ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
    assertNull( "New request should not have a request session ID", request.getRequestedSessionId() );
    assertNull( "New request should not have a session", request.getSession( /* create */ false ) );
    assertEquals( "Number of sessions in the context after request.getSession(false)", 0, context.getSessionIDs().size() );

    HttpSession session = request.getSession();
    assertNotNull( "No session created", session );
    assertTrue( "Session not marked as new", session.isNew() );
    assertEquals( "Number of sessions in context after request.getSession()", 1, context.getSessionIDs().size() );
    assertSame( "Session with ID", session, context.getSession( session.getId() ) );
    assertNull( "New request should still not have a request session ID", request.getRequestedSessionId() );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:18,代码来源:HttpServletRequestTest.java

示例4: testGetSessionWithBadCookie

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
/**
 * Verifies that a request with a bad session ID causes a new session to be generated only when explicitly requested.
 */
public void testGetSessionWithBadCookie() throws Exception {
    WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
    ServletUnitContext context = new ServletUnitContext();
    ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );

    HttpSession originalSession = context.newSession();
    String originalID = originalSession.getId();
    request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, originalID ) );
    request.getSession();

    String badID = originalID + "BAD";
    request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
    request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, badID ) );

    assertNull( "Unexpected session returned for bad cookie", request.getSession( false ) );
    assertNotNull( "Should have returned session when asked", request.getSession( true ));
    assertNotSame( "Created session", originalSession, request.getSession( true ) );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:22,代码来源:HttpServletRequestTest.java

示例5: testBindingModeWrong

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
@Test
public void testBindingModeWrong() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:input");
    mock.expectedMessageCount(0);

    // we bind to xml, but send in json, which is not possible
    String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users/new", new ByteArrayInputStream(body.getBytes()), "application/json");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);

    assertEquals(500, response.getResponseCode());

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:RestServletBindingModeXmlTest.java

示例6: testDeleteAllSubnets

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
public void testDeleteAllSubnets() throws InstantiationException, IllegalAccessException, 
ClassNotFoundException, SQLException, IOException, SAXException
{
	TestUtils theTestUtils = new TestUtils();		
	WebResponse response = loadUrl (theTestUtils);
	WebForm configurationForm = response.getFormWithID("config");
	
	int numSubnets = Integer.parseInt(configurationForm.getParameterValue("numSubnets"));
	String aux = "?";
	for (int i = 1; i <= numSubnets; i++)
		aux += "delSubnet"+i+"=delSubnet"+i+"&";
	aux +="numSubnets="+numSubnets;			
	WebRequest request = new GetMethodWebRequest(theTestUtils.getUrlPmgraph() + "configure.jsp"+aux);
    response = m_conversation.getResponse(request);
	
	configurationForm = response.getFormWithID("config");
	int newNumSubnets = Integer.parseInt(configurationForm.getParameterValue("numSubnets"));
	assertEquals(numSubnets, newNumSubnets);		
    HTMLElement result = response.getElementWithID("unsuccessResult");
    String resultString = result.getNode().getFirstChild().getNextSibling().getFirstChild().getNodeValue();
    assertTrue(resultString.equals("You can't delete all the subnets"));
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:23,代码来源:TestMultiSubnets.java

示例7: testSimpleConnection

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
/**
 * Test the simple case of connecting, retrieving and disconnecting
 */
public void testSimpleConnection() throws IOException, SAXException, InterruptedException {
	// Initialise container
	final Map<String, String> args = new HashMap<String, String>();
	args.put("webroot", HttpConnectorTest.WEBROOT);
	args.put("prefix", "/examples");
	args.put("httpPort", "10003");
	args.put("ajp13Port", "-1");
	args.put("controlPort", "-1");
	args.put("debug", "8");
	args.put("logThrowingLineNo", "true");
	final Launcher winstone = new Launcher(args);
	winstone.launch();
	// Check for a simple connection
	final WebConversation wc = new WebConversation();
	final WebRequest wreq = new GetMethodWebRequest("http://localhost:10003/examples/CountRequestsServlet");
	final WebResponse wresp = wc.getResponse(wreq);
	final InputStream content = wresp.getInputStream();
	Assert.assertTrue("Loading CountRequestsServlet", content.available() > 0);
	content.close();
	winstone.shutdown();
	Thread.sleep(500);
}
 
开发者ID:geronimo-iia,项目名称:winstone,代码行数:26,代码来源:HttpConnectorTest.java

示例8: testWriteAfterServlet

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
/**
 * Test the keep alive case
 */
public void testWriteAfterServlet() throws IOException, InterruptedException, SAXException {
	// Initialise container
	final Map<String, String> args = new HashMap<String, String>();
	args.put("webroot", HttpConnectorTest.WEBROOT);
	args.put("prefix", "/examples");
	args.put("httpPort", "10005");
	args.put("ajp13Port", "-1");
	args.put("controlPort", "-1");
	args.put("debug", "8");
	args.put("logThrowingLineNo", "true");
	final Launcher winstone = new Launcher(args);
	winstone.launch();
	// Check for a simple connection
	final WebConversation wc = new WebConversation();
	final WebRequest wreq = new GetMethodWebRequest("http://localhost:10005/examples/TestWriteAfterServlet");
	final WebResponse wresp1 = wc.getResponse(wreq);
	logger.info("Output: " + wresp1.getText());
	Assert.assertTrue(wresp1.getText().endsWith("Hello"));
	winstone.shutdown();
	Thread.sleep(500);
}
 
开发者ID:geronimo-iia,项目名称:winstone,代码行数:25,代码来源:HttpConnectorTest.java

示例9: setUp

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
@Override
protected void setUp() throws Exception
{
	try
	{
		wc = new WebConversation();
		WebRequest req = new GetMethodWebRequest(TEST_URL);
		WebResponse resp = wc.getResponse(req);
		DataInputStream inputStream = new DataInputStream(resp.getInputStream());
		buffer = new byte[resp.getContentLength()];
		inputStream.readFully(buffer);
		visited = new HashMap<String, String>();
	}
	catch (Exception notfound)
	{
		enabled = false;
	}
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:19,代码来源:AnonPortalTest.java

示例10: setUp

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();

    //Prepare the environment..
    ProxymaFacade proxyma = new ProxymaFacade();
    ProxymaContext context = proxyma.createNewContext("default", "/", "src/test/resources/test-config.xml", "/tmp/");
    ServletRunner sr = new ServletRunner();
    sr.registerServlet( "myServlet", TestServlet.class.getName() );
    ServletUnitClient sc = sr.newClient();
    WebRequest wreq   = new GetMethodWebRequest( "http://test.meterware.com/myServlet?a=1&b=2" );
    wreq.setParameter( "color", "red" );
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    request = ic.getRequest();
    response = ic.getResponse();
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:18,代码来源:URLRewriteEngineTest.java

示例11: doTest

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
/**
 * Decorated object based on a pageContext attribute
 * @param jspName jsp name, with full path
 * @throws Exception any axception thrown during test.
 */
@Override
@Test
public void doTest() throws Exception
{
    WebRequest request = new GetMethodWebRequest(getJspUrl(getJspName()));

    WebResponse response = runner.getResponse(request);

    if (log.isDebugEnabled())
    {
        log.debug(response.getText());
    }

    WebTable[] tables = response.getTables();
    Assert.assertEquals("Wrong number of tables.", 1, tables.length);

    Assert.assertEquals("Wrong (undecorated?) value", "pageContext: html ant", tables[0].getCellAsText(1, 0));

}
 
开发者ID:webbfontaine,项目名称:displaytag,代码行数:25,代码来源:Displ139Test.java

示例12: doTest

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
/**
 * Verifies that the generated page contains the pagination links with the inupt parameter. Tests #917200 ("{}" in
 * parameters).
 * @param jspName jsp name, with full path
 * @throws Exception any axception thrown during test.
 */
@Override
@Test
public void doTest() throws Exception
{

    WebRequest request = new GetMethodWebRequest(getJspUrl(getJspName()));

    WebResponse response = null;

    try
    {
        response = runner.getResponse(request);
        Assert.fail("Should have thrown an exception, missing size attribute");
    }
    catch (Throwable t)
    {
    }

    if (log.isDebugEnabled() && response != null)
    {
        log.debug("RESPONSE: " + response.getText());
    }
}
 
开发者ID:webbfontaine,项目名称:displaytag,代码行数:30,代码来源:PartialListMissingSizeTest.java

示例13: setUp

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();

    //Prepare the environment..
    ProxymaFacade proxyma = new ProxymaFacade();
    ProxymaContext context = proxyma.createNewContext("default", "/", "src/test/resources/test-config.xml", "/tmp/");
    ServletRunner sr = new ServletRunner();
    sr.registerServlet( "myServlet", TestServlet.class.getName() );
    ServletUnitClient sc = sr.newClient();
    WebRequest wreq   = new GetMethodWebRequest( "http://test.meterware.com/myServlet" );
    wreq.setParameter( "color", "red" );
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    request = ic.getRequest();
    response = ic.getResponse();
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:18,代码来源:HtmlUrlRewriteTransformerTest.java

示例14: setUp

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();

    //Prepare the environment..
    ProxymaFacade proxyma = new ProxymaFacade();
    ProxymaContext context = proxyma.createNewContext("default", "/", "src/test/resources/test-config.xml", "/tmp/");
    ServletRunner sr = new ServletRunner();
    sr.registerServlet( "myServlet/library.js", TestServlet.class.getName() );
    ServletUnitClient sc = sr.newClient();
    WebRequest wreq   = new GetMethodWebRequest( "http://test.meterware.com/myServlet/library.js" );
    wreq.setParameter( "color", "red" );
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    request = ic.getRequest();
    response = ic.getResponse();
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:18,代码来源:JSRewriteTransformerTest.java

示例15: setUp

import com.meterware.httpunit.WebRequest; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();

    //Prepare the environment..
    ProxymaFacade proxyma = new ProxymaFacade();
    ProxymaContext context = proxyma.createNewContext("default", "/", "src/test/resources/test-config.xml", "/tmp/");
    ServletRunner sr = new ServletRunner();
    sr.registerServlet( "myServlet", TestServlet.class.getName() );
    ServletUnitClient sc = sr.newClient();
    WebRequest wreq   = new GetMethodWebRequest( "http://test.meterware.com/myServlet?a=1&b=2" );
    wreq.setParameter( "color", "red" );
    wreq.setHeaderField("Cookie", "rewritten=value1");
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    request = ic.getRequest();
    response = ic.getResponse();
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:19,代码来源:HttpRedirectsRewriteTransformerTest.java


注:本文中的com.meterware.httpunit.WebRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。