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


Java WebResponse.getText方法代码示例

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


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

示例1: handleActivity

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
private WebResponse handleActivity(WebResponse resp) throws SAXException, IOException, InterruptedException {
// MockLearner.log.debug(resp.getText());

WebResponse nextResp = null;
WebForm[] forms = resp.getForms();
if ((forms != null) && (forms.length > 0)) {
    MockLearner.log.debug("There " + (forms.length == 1 ? "is " : "are ") + forms.length
	    + (forms.length == 1 ? " form in the page " : " forms in the page"));
    nextResp = handlePageWithForms(resp);
} else {
    nextResp = handlePageWithoutForms(resp);
}

String asText = nextResp == null ? null : nextResp.getText();
boolean isActivityFinished = (asText != null) && (asText.contains(MockLearner.ACTIVITY_FINISHED_FLAG)
	|| asText.contains(MockLearner.LESSON_FINISHED_FLAG)
	|| asText.contains(MockLearner.LOAD_TOOL_ACTIVITY_FLAG));

return isActivityFinished ? nextResp : handleActivity(nextResp);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:MockLearner.java

示例2: handleToolLeader

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
private WebResponse handleToolLeader(WebResponse resp) throws SAXException, IOException {
String asText = resp.getText();
Matcher m = MockLearner.LEADER_SHOW_DIALOG_PATTERN.matcher(asText);
if (!m.find()) {
    throw new TestHarnessException("Could not tell whether the user can become the leader");
}
if (Boolean.valueOf(m.group(1))) {
    m = MockLearner.LEADER_BECOME_PATTERN.matcher(asText);
    if (!m.find()) {
	throw new TestHarnessException("Could not \"become leader\" URL");
    }
    String becomeLeaderQueryOptions = m.group();
    String url = "/lams/tool/lalead11/learning.do?" + becomeLeaderQueryOptions;
    MockLearner.log.debug("Becoming a leader using link: " + url);
    new Call(wc, test, username + " becomes Leader", url).execute();
}
String finishURL = MockLearner.findURLInLocationHref(resp, MockLearner.LEADER_FINISH_SUBSTRING);
if (finishURL == null) {
    throw new TestHarnessException("Unable to finish the leader, no finish link found. " + asText);
}

MockLearner.log.debug("Ending leader using url " + finishURL);
return (WebResponse) new Call(wc, test, username + " finishes Leader", finishURL).execute();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:MockLearner.java

示例3: handleToolShareResources

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
private WebResponse handleToolShareResources(WebResponse resp, String initialRedirectLink)
    throws IOException, SAXException {
WebResponse nextResponse = (WebResponse) new Call(wc, test, username + " forwarded to Share Resources",
	initialRedirectLink).execute();
String asText = nextResponse.getText();
Matcher m = MockLearner.SHARE_RESOURCES_VIEW_ITEM_URL_PATTERH.matcher(asText);
if (!m.find()) {
    throw new TestHarnessException("View Item URL in Share Resources tool not found");
}
String viewItemURL = m.group(1);
m = MockLearner.SHARE_RESOURCES_VIEW_ITEM_PATTERN.matcher(asText);
while (m.find()) {
    new Call(wc, test, username + " views Share Resources item", viewItemURL + m.group(1)).execute();
    delay();
}

String finishURL = MockLearner.findURLInLocationHref(nextResponse, MockLearner.FINISH_SUBSTRING);
return (WebResponse) new Call(wc, test, username + " finishes Share Resources", finishURL).execute();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:MockLearner.java

示例4: w3cValidator

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
/**
	 * Check if the response is W3C valid XHTML file.
	 * 
	 * @param response
	 * @throws IOException
	 */
	private void w3cValidator(WebResponse response) throws IOException
	{

		XhtmlValidator validator = new XhtmlValidator();
		String docText = response.getText();
System.out.println(docText);
		if (!validator.isValid(new ByteArrayInputStream(docText.getBytes())))
			;
		String errors[] = validator.getErrors();
		for (String error : errors)
		{
			m_logger.warn(error);
		}
		assertTrue(validator.isValid(new ByteArrayInputStream(docText
				.getBytes())));

	}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:24,代码来源:W3cValidationTest.java

示例5: parseOutNextURL

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
private static String parseOutNextURL(WebResponse resp) throws SAXException, IOException {
String text = resp.getText();
String toolURL = null;
Matcher m = MockLearner.NEXT_URL_PATTERN.matcher(text);
if (m.find()) {
    toolURL = m.group(1);
}

if ((toolURL != null) && !toolURL.startsWith("/")) {
    toolURL = '/' + toolURL;
}

MockLearner.log.debug("Tool URL: " + toolURL);
return toolURL;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:MockLearner.java

示例6: handleToolNb

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
private void handleToolNb(WebResponse resp, WebForm form) throws IOException {
String asText = resp.getText();
if (asText.contains("submitForm('reflect')")) {
    form.setAttribute("action", form.getAction() + "?method=reflect");
} else {
    form.setAttribute("action", form.getAction() + "?method=finish");
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:MockLearner.java

示例7: testServletPojoInOut

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
@Test
public void testServletPojoInOut() throws Exception {
    String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users/lives", new ByteArrayInputStream(body.getBytes()), "application/json");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);

    assertEquals(200, response.getResponseCode());

    String out = response.getText();

    assertNotNull(out);
    assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:RestServletPojoInOutTest.java

示例8: testServletPojoGet

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
@Test
public void testServletPojoGet() throws Exception {
    
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users/lives");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);

    assertEquals(200, response.getResponseCode());

    String out = response.getText();

    assertNotNull(out);
    assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:RestServletPojoInOutTest.java

示例9: getService

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
public String getService(String path) throws Exception {
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + path);
    ServletUnitClient client = newClient();
    WebResponse response = client.getResponse(req);

    return response.getText();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:MultiServletConsumerTest.java

示例10: serviceTicketFromResponse

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
/**
 * Extract a serviceTicket from a CAS 1 ticket validation response.
 * @param webResponse the web application validation response
 * @return a String representing the ticket
 * @throws IOException on IO error reading response
 * @throws RuntimeException on some parse failures
 */
public static String serviceTicketFromResponse(final WebResponse webResponse) throws IOException {

    String serviceTicket;

    // now we need to extract the service ticket.

    // in a baseline CAS 2.x distribution return to the service is accomplished by
    // JavaScript redirect
    //
    // CAS 3 accomplishes this differently such that our client has already
    // followed the redirect to the service, so we'll find the service ticket
    // on the response URL.

    final String queryString = webResponse.getURL().getQuery();

    final int ticketIndex = queryString.indexOf("ticket=");

    if (ticketIndex == -1) {

        // the ticket wasn't in the response URL.
        // we're testing for CAS 2.x style JavaScript for redirection, as
        // recommended in appendix B of the CAS 2 protocol specification

        // parse the ticket out of the JavaScript

        final String response = webResponse.getText();

        final int declarationStartsAt = response.indexOf("window.location.href");
        // cut off the front of the response up to the beginning of the service URL
        final String responseAfterWindowLocHref = response.substring(declarationStartsAt
                + "window.location.href12".length());

        // The URL might be single or double quoted
        final int endDoubleQuoteIndex = responseAfterWindowLocHref.indexOf("\"");
        final int endSingleQuoteIndex = responseAfterWindowLocHref.indexOf("\'");

        // we will set this variable to be the index of the first ' or " character
        int endQuoteIndex = 0;
        if (endDoubleQuoteIndex == -1 && endSingleQuoteIndex == -1) {
            throw new RuntimeException("Failed parsing a service ticket from the response:" + response);
        } else if (endDoubleQuoteIndex > -1 && (endDoubleQuoteIndex < endSingleQuoteIndex || endSingleQuoteIndex == -1)) {
            endQuoteIndex = endDoubleQuoteIndex;
        } else {
            endQuoteIndex = endSingleQuoteIndex;
        }

        final int ticketEqualsIndex = responseAfterWindowLocHref.indexOf("ticket=");

        serviceTicket = responseAfterWindowLocHref.substring(ticketEqualsIndex + "ticket=".length(), endQuoteIndex);


    } else {
        // service ticket was found on query String, parse it from there

        // TODO Is this type of redirection compatible?
        // Does it address all the issues that CAS2 JavaScript redirection
        // was intended to address?

        serviceTicket = queryString.substring(ticketIndex + "ticket=".length(), queryString.length());

    }

    return serviceTicket;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:72,代码来源:LoginHelper.java

示例11: serviceTicketFromResponse

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
/**
 * Extract a serviceTicket from a CAS 1 ticket validation response.
 * @param webResponse the web application validation response
 * @return a String representing the ticket
 * @throws IOException on IO error reading response
 * @throws RuntimeException on some parse failures
 */
public static String serviceTicketFromResponse(final WebResponse webResponse) throws IOException {

    String serviceTicket;

    // now we need to extract the service ticket.

    // in a baseline CAS 2.x distribution return to the service is accomplished by
    // JavaScript redirect
    //
    // CAS 3 accomplishes this differently such that our client has already
    // followed the redirect to the service, so we'll find the service ticket
    // on the response URL.

    String queryString = webResponse.getURL().getQuery();

    int ticketIndex = queryString.indexOf("ticket=");

    if (ticketIndex == -1) {

        // the ticket wasn't in the response URL.
        // we're testing for CAS 2.x style JavaScript for redirection, as
        // recommended in appendix B of the CAS 2 protocol specification

        // parse the ticket out of the JavaScript

        String response = webResponse.getText();

        int declarationStartsAt = response.indexOf("window.location.href");
        // cut off the front of the response up to the beginning of the service URL
        String responseAfterWindowLocHref = response.substring(declarationStartsAt
                + "window.location.href12".length());

        // The URL might be single or double quoted
        final int endDoubleQuoteIndex = responseAfterWindowLocHref.indexOf("\"");
        final int endSingleQuoteIndex = responseAfterWindowLocHref.indexOf("\'");

        // we will set this variable to be the index of the first ' or " character
        int endQuoteIndex = 0;
        if (endDoubleQuoteIndex == -1 && endSingleQuoteIndex == -1) {
            throw new RuntimeException("Failed parsing a service ticket from the response:" + response);
        } else if (endDoubleQuoteIndex > -1 && (endDoubleQuoteIndex < endSingleQuoteIndex || endSingleQuoteIndex == -1)) {
            endQuoteIndex = endDoubleQuoteIndex;
        } else {
            endQuoteIndex = endSingleQuoteIndex;
        }

        int ticketEqualsIndex = responseAfterWindowLocHref.indexOf("ticket=");

        serviceTicket = responseAfterWindowLocHref.substring(ticketEqualsIndex + "ticket=".length(), endQuoteIndex);


    } else {
        // service ticket was found on query String, parse it from there

        // TODO Is this type of redirection compatible?
        // Does it address all the issues that CAS2 JavaScript redirection
        // was intended to address?

        serviceTicket = queryString.substring(ticketIndex + "ticket=".length(), queryString.length());

    }

    return serviceTicket;
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:72,代码来源:LoginHelper.java

示例12: create

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
/**
 * 
 * @param aRequest the web response
 */
public static HTTPResult create(WebResponse aResponse)
{
   if (aResponse == null)
      throw new IllegalArgumentException(
      "aResponse required in HTTPResult.create");
   
   try
   {
      HTTPResult result = new HTTPResult();
      
      result.url = aResponse.getURL();
      
     
      result.content = aResponse.getText();
      result.statusCode = aResponse.getResponseCode();
      
      String[] headerNames = aResponse.getHeaderFieldNames();         
      
      //build headers
      if(headerNames != null)
      {
         String headerName = null;
         result.headers = new HashMap<Object, Object>(headerNames.length);
         for (int i = 0; i < headerNames.length; i++)
         {
            headerName = headerNames[i];
            result.headers.put(headerName, aResponse.getHeaderField(headerName));
         }   
      }
      
      //build cookies
      String[] cookieNames = aResponse.getNewCookieNames();         
               
      if(cookieNames != null)
      {
         String cookieName = null;
         result.cookies = new HashMap<Object, Object>(cookieNames.length);
         for (int i = 0; i < cookieNames.length; i++)
         {
            cookieName = cookieNames[i];
            result.cookies.put(cookieName, aResponse.getNewCookieValue(cookieName));
         }   
      }
      
      return result;
   }
   catch (IOException e)
   {
      throw new RuntimeException(Debugger.stackTrace(e));
   }
}
 
开发者ID:nyla-solutions,项目名称:nyla,代码行数:56,代码来源:HTTPResult.java


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