Java源码示例:com.meterware.httpunit.HttpException

示例1
/**
 * Here we expect an errorCode other than 200, and look for it checking for
 * text is omitted as it doesnt work. It would never work on java1.3, but
 * one may have expected java1.4+ to have access to the error stream in
 * responses. Clearly not.
 *
 * @param request
 * @param errorCode
 * @param errorText optional text string to search for
 * @throws MalformedURLException
 * @throws IOException
 * @throws SAXException
 */
protected void expectErrorCode(WebRequest request, int errorCode, String errorText)
    throws MalformedURLException, IOException, SAXException {
    String failureText = "Expected error " + errorCode + " from " + request.getURL();

    try {
        newClient().getResponse(request);
        fail(errorText + " -got success instead");
    } catch (HttpException e) {
        assertEquals(failureText, errorCode, e.getResponseCode());
        /*
         * checking for text omitted as it doesnt work. if(errorText!=null) {
         * assertTrue( "Failed to find "+errorText+" in "+
         * e.getResponseMessage(), e.getMessage().indexOf(errorText)>=0); }
         */
    }
}
 
示例2
public void testFrontPage() throws Exception
{
	if (enabled)
	{
		WebResponse resp = null;
		try
		{
			for (String seed : seedURLs)
			{
				log.info("Testing Seed URL "+seed);
				WebRequest req = new GetMethodWebRequest(BASE_URL + seed);
				resp = wc.getResponse(req);
				clickAll(resp, 0, 10);
			}

		}
		catch (HttpException hex)
		{
			log.error("Failed with ", hex);
			fail(hex.getMessage());
		}
	}
	else
	{
		log.info("Tests Disabled, please start tomcat with sdata installed");
	}
}
 
示例3
public void testFrontPage() throws Exception
{
	if (enabled)
	{
		WebResponse resp = null;
		try
		{
			for (String seed : seedURLs)
			{
				log.info("Testing Seed URL "+seed);
				WebRequest req = new GetMethodWebRequest(BASE_URL + seed);
				resp = wc.getResponse(req);
				clickAll(resp, 0, 10);
			}

		}
		catch (HttpException hex)
		{
			log.error("Failed with ", hex);
			fail(hex.getMessage());
		}
	}
	else
	{
		log.info("Tests Disabled, please start tomcat with sdata installed");
	}
}
 
示例4
public void testUnauthenthorized() throws IOException, SAXException {
    // Trying to access the application
    WebRequest req =
            new GetMethodWebRequest("http://localhost:8080/esigate-app-casified-aggregator/aggregated1/block.jsp");
    try {
        webConversation.getResponse(req);
        fail("We should get a 401 Unauthorized");
    } catch (HttpException e) {
        assertEquals("We should get a 401 Unauthorized", HttpServletResponse.SC_UNAUTHORIZED, e.getResponseCode());

    }
}
 
示例5
/**
 * @param resp
 * @param i
 * @param maxDepth
	 * @throws SAXException 
	 * @throws IOException 
 */
private void processLinks(WebResponse resp, int i, int maxDepth) throws SAXException, IOException
{
	char[] p = new char[i];
	for (int j = 0; j < i; j++)
	{
		p[j] = ' ';
	}
	String pad = new String(p);
	WebLink[] links = resp.getLinks();
	for (WebLink link : links)
	{
		String url = link.getURLString();
		if (visited.get(url) == null)
		{
			visited.put(url, url);
			if (isLocal(url))
			{
				log.info("Getting " + pad + link.getURLString());
				WebResponse response = null;
				try
				{

					response = link.click();
				}
				catch (HttpException ex)
				{
					log.warn("Failed to get Link " + url + " code:"
							+ ex.getResponseCode() + " cause:"
							+ ex.getResponseMessage());
				}
				catch (ConnectException cex)
				{
					log.error("Failed to get Connection to "+url);
				}
				if (response != null)
				{
					clickAll(response, i, maxDepth);
				}

			}
			else
			{
				log.info("Ignoring External URL " + url);
			}
		}
	}
}
 
示例6
/**
 * @param resp
 * @param i
 * @param maxDepth
	 * @throws SAXException 
	 * @throws IOException 
 */
private void processLinks(WebResponse resp, int i, int maxDepth) throws SAXException, IOException
{
	char[] p = new char[i];
	for (int j = 0; j < i; j++)
	{
		p[j] = ' ';
	}
	String pad = new String(p);
	WebLink[] links = resp.getLinks();
	for (WebLink link : links)
	{
		String url = link.getURLString();
		if (visited.get(url) == null)
		{
			visited.put(url, url);
			if (isLocal(url))
			{
				log.info("Getting " + pad + link.getURLString());
				WebResponse response = null;
				try
				{

					response = link.click();
				}
				catch (HttpException ex)
				{
					log.warn("Failed to get Link " + url + " code:"
							+ ex.getResponseCode() + " cause:"
							+ ex.getResponseMessage());
				}
				catch (ConnectException cex)
				{
					log.error("Failed to get Connection to "+url);
				}
				if (response != null)
				{
					clickAll(response, i, maxDepth);
				}

			}
			else
			{
				log.info("Ignoring External URL " + url);
			}
		}
	}
}