本文整理汇总了Java中com.gargoylesoftware.htmlunit.WebRequest.setRequestBody方法的典型用法代码示例。如果您正苦于以下问题:Java WebRequest.setRequestBody方法的具体用法?Java WebRequest.setRequestBody怎么用?Java WebRequest.setRequestBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.gargoylesoftware.htmlunit.WebRequest
的用法示例。
在下文中一共展示了WebRequest.setRequestBody方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTicketFieldValue
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
private void setTicketFieldValue(final GepardTestClass tc, final String ticket, final String fieldName, final String value) throws IOException {
String jiraSetFieldPage = getIssueFieldSetValueUrl(ticket);
WebRequest requestSettings = new WebRequest(new URL(jiraSetFieldPage), HttpMethod.PUT);
requestSettings.setAdditionalHeader("Content-type", "application/json");
requestSettings.setRequestBody("{ \"fields\": {\"" + fieldName + "\": \"" + value + "\"} }");
try {
UnexpectedPage infoPage = webClient.getPage(requestSettings);
if (infoPage.getWebResponse().getStatusCode() == HTTP_RESPONSE_OK) {
tc.logComment("Field: '" + fieldName + "' of Ticket: " + ticket + " was updated to value: '" + value + "' successfully.");
} else {
throw new SimpleGepardException("Ticket: " + ticket + " field: " + fieldName + " update failed, status code: " + infoPage.getWebResponse().getStatusCode());
}
} catch (FailingHttpStatusCodeException e) {
throw new SimpleGepardException("Ticket: " + ticket + " field: " + fieldName + " update failed.", e);
}
}
示例2: transferTicketToStatus
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
/**
* Transition a ticket to next status in its workflow.
* URL --> https://jira.xxxxxx.com/rest/api/2/issue/TEST-53/transitions?expand=transitions.fields
* POST data --> {"transition":{"id":91}}
* Returned HTTP response --> 204
*
* @param ticket is the specific ticket
* @param statusTransferId is the id of the transaction that should be used to transfer the ticket
* @param expectedStatusName is the name of the expected new status
* @param comment that will be attached to the ticket as comment of the transaction
* @return with the new status
*/
private String transferTicketToStatus(final GepardTestClass tc, final String ticket, final String statusTransferId, final String expectedStatusName, final String comment)
throws IOException, JSONException {
String updateString = "{ \"update\": { \"comment\": [ { \"add\": { \"body\": \"" + comment + "\" } } ] }, \"transition\": { \"id\": \"" + statusTransferId + "\" } }";
String oldStatus = detectActualStatus(ticket);
String newStatus;
String jiraSetFieldPage = getIssueSetTransitionsUrl(ticket);
WebRequest requestSettings = new WebRequest(new URL(jiraSetFieldPage), HttpMethod.POST);
requestSettings.setAdditionalHeader("Content-type", "application/json");
requestSettings.setRequestBody(updateString);
try {
UnexpectedPage infoPage = webClient.getPage(requestSettings);
if (infoPage.getWebResponse().getStatusCode() == HTTP_RESPONSE_OK) {
newStatus = detectActualStatus(ticket);
Assert.assertEquals("Transferring ticket: " + ticket + " to new status failed,", expectedStatusName, newStatus);
tc.logComment("Ticket: " + ticket + " was transferred from status: \"" + oldStatus + "\" to status: \"" + newStatus + "\" successfully.");
} else {
throw new SimpleGepardException("ERROR: Status update failed for ticket: " + ticket + ", Status code:" + infoPage.getWebResponse().getStatusCode());
}
} catch (FailingHttpStatusCodeException e) {
throw new SimpleGepardException("ERROR: Status update failed for ticket: " + ticket + ".", e);
}
return newStatus;
}
示例3: putCustomListsTest
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 2)
@OperateOnDeployment("ear")
@RunAsClient
public void putCustomListsTest(@ArquillianResource URL context) throws Exception {
WebClient webClient = new WebClient();
WebRequest requestSettings = new WebRequest(new URL(context + "rest/lists/2"), HttpMethod.PUT);
requestSettings.setAdditionalHeader("Content-Type", "application/json");
requestSettings.setAdditionalHeader("X-sinkit-token", TOKEN);
requestSettings.setRequestBody(
"[{\"dns_client\":\"10.10.10.10/32\"," +
"\"lists\":{\"seznam.cz\":\"W\"," +
"\"google.com\":\"B\"," +
"\"example.com\":\"L\"}" +
"}," +
"{\"dns_client\":\"fe80::3ea9:f4ff:fe81:c450/64\"," +
"\"lists\":{\"seznam.cz\":\"L\"," +
"\"google.com\":\"W\"," +
"\"example.com\":\"W\"}" +
"}]");
Page page = webClient.getPage(requestSettings);
assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
String responseBody = page.getWebResponse().getContentAsString();
LOGGER.info("putCustomListsTest Response:" + responseBody);
String expected = "6 CUSTOM LISTS ELEMENTS PROCESSED, 6 PRESENT";
assertTrue(responseBody.contains(expected), "Expected: " + expected + ", but got: " + responseBody);
}
示例4: postAllDNSClientSettingsTest
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test(enabled = true, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 1)
@OperateOnDeployment("ear")
@RunAsClient
public void postAllDNSClientSettingsTest(@ArquillianResource URL context) throws Exception {
InfinispanManager.getInfinispanManager().getRuleRemoteCache().clear();
WebClient webClient = new WebClient();
WebRequest requestSettings = new WebRequest(new URL(context + "rest/rules/all"), HttpMethod.POST);
requestSettings.setAdditionalHeader("Content-Type", "application/json");
requestSettings.setAdditionalHeader("X-sinkit-token", TOKEN);
requestSettings.setRequestBody(
"[{\"dns_client\":\"10.10.10.10/32\"," +
"\"settings\":{\"feed-3\":\"D\"," +
"\"feed2\":\"S\"," +
"\"test-feed1\":\"L\"}," +
"\"customer_id\":2," +
"\"customer_name\":\"yadayada-2\"}," +
"{\"dns_client\":\"10.10.10.11/32\"," +
"\"settings\":{\"feed-3\":\"D\"," +
"\"feed2\":\"S\"," +
"\"test-feed1\":\"L\"}," +
"\"customer_id\":2," +
"\"customer_name\":\"yadayada-2\"}," +
"{\"dns_client\":\"10.11.12.0/24\"," +
"\"settings\":{\"test-feed1\":\"L\"," +
"\"feed2\":\"S\"," +
"\"feed-3\":\"D\"}," +
"\"customer_id\":1," +
"\"customer_name\":\"test-yadayada\"}," +
"{\"dns_client\":\"10.11.30.30/32\"," +
"\"settings\":{\"test-feed1\":\"L\"," +
"\"feed2\":\"S\"," +
"\"feed-3\":\"D\"}," +
"\"customer_id\":1," +
"\"customer_name\":\"test-yadayada\"}]");
Page page = webClient.getPage(requestSettings);
assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
String responseBody = page.getWebResponse().getContentAsString();
LOGGER.info("Response:" + responseBody);
String expected = "4 RULES PROCESSED 4 PRESENT";
assertTrue(responseBody.contains(expected), "Expected " + expected + ", but got: " + responseBody);
}
示例5: receiveIoCTest
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 9)
@OperateOnDeployment("ear")
@RunAsClient
public void receiveIoCTest(@ArquillianResource URL context) throws Exception {
WebClient webClient = new WebClient();
WebRequest requestSettings = new WebRequest(new URL(context + "rest/blacklist/ioc/"), HttpMethod.POST);
requestSettings.setAdditionalHeader("Content-Type", "application/json");
requestSettings.setAdditionalHeader("X-sinkit-token", TOKEN);
String feed = "integrationTest";
String type = "phishing";
String fqdn = "phishing.ru";
requestSettings.setRequestBody(
"{" +
"\"feed\":{" +
"\"name\":\"" + feed + "\"," +
"\"url\":\"http://www.greatfeed.com/feed.txt\"" +
"}," +
"\"classification\":{" +
"\"type\": \"" + type + "\"," +
"\"taxonomy\": \"Fraud\"" +
"}," +
"\"raw\":\"aHR0cDovL2luZm9ybWF0aW9uLnVwZGF0ZS5teWFjY291bnQtc2VjdXJlLmNvbS85ODI0YTYxOGRlNTlmYjE2MTlmNTUzNTgwYWFmZjcxMS9mMWI2YTE2OTc2MDRiNmI2M2IwODBmODQ2N2FiNGZiNS8=\"," +
"\"source\":{" +
"\"fqdn\":\"" + fqdn + "\"," +
"\"bgp_prefix\":\"some_prefix\"," +
"\"asn\":\"123456\"," +
"\"asn_name\":\"some_name\"," +
"\"geolocation\":{" +
"\"cc\":\"RU\"," +
"\"city\":\"City\"," +
"\"latitude\":\"85.12645\"," +
"\"longitude\":\"-12.9788\"" +
"}" +
"}," +
"\"time\":{" +
"\"observation\":\"" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(Calendar.getInstance().getTime()) + "\"" +
"}," +
"\"protocol\":{" +
"\"application\":\"ssh\"" +
"}," +
"\"description\":{" +
" \"text\":\"description\"" +
"}" +
"}"
);
Page page = webClient.getPage(requestSettings);
assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
String responseBody = page.getWebResponse().getContentAsString();
LOGGER.info("Response:" + responseBody);
String expected = "\"feed\":{\"url\":\"http://www.greatfeed.com/feed.txt\",\"name\":\"" + feed + "\"},\"description\":{\"text\":\"description\"},\"classification\":{\"type\":\"" + type + "\",\"taxonomy\":\"Fraud\"},\"protocol\":{\"application\":\"ssh\"},\"raw\":\"aHR0cDovL2luZm9ybWF0aW9uLnVwZGF0ZS5teWFjY291bnQtc2VjdXJlLmNvbS85ODI0YTYxOGRlNTlmYjE2MTlmNTUzNTgwYWFmZjcxMS9mMWI2YTE2OTc2MDRiNmI2M2IwODBmODQ2N2FiNGZiNS8\\u003d\",\"source\":{\"id\":{\"value\":\"" + fqdn + "\",\"type\":\"fqdn\"},\"fqdn\":\"" + fqdn + "\",\"asn\":123456,\"asn_name\":\"some_name\",\"geolocation\":{\"cc\":\"RU\",\"city\":\"City\",\"latitude\":85.12645,\"longitude\":-12.9788},\"bgp_prefix\":\"some_prefix\"},\"time\":{\"observation\":\"";
assertTrue(responseBody.contains(expected), "Should have contained " + expected + ", but got: " + responseBody);
}
示例6: execute
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
/**
* Makes the REST call and saves the response.
*
* @see com.xceptance.xlt.api.actions.AbstractAction#execute()
*/
@Override
protected void execute() throws Exception
{
// Call it once for debugging and execution for better performance.
String url = restCall.getUrl();
// DEBUGGING - log URL, HTTP method, and HTTP headers
XltLogger.runTimeLogger.debug( "Start REST call..." );
XltLogger.runTimeLogger.debug( "# Request - URL:\t\t" + url );
XltLogger.runTimeLogger.debug( "# Request - HTTP method:\t" + restCall.getHttpMethod() );
XltLogger.runTimeLogger.debug( "# Request - HTTP headers:\t" + restCall.getHttpHeaders().toString() );
// Setup the request.
WebRequest request = new WebRequest( new URL( url ), restCall.getHttpMethod() );
request.setAdditionalHeaders( restCall.getHttpHeaders() );
// Set request body.
if ( restCall.hasRequestBody() )
{
// Call it once for debugging and execution for better performance.
String requestBody = restCall.getRequestBody();
// DEBUGGING - log request body
XltLogger.runTimeLogger.debug( "# Request - Body:\t" + requestBody );
request.setRequestBody( requestBody );
}
// Avoid caching of REST documents
request.setDocumentRequest();
// Make the call and store the response and previous action.
WebResponse response = getWebClient().loadWebResponse( request );
restCall.setRESTResponse( response );
restCall.setPreviousAction( this );
// Provide timer name to set the resulting page (in results browser)
setLightWeightPage(new LightWeightPageImpl(response, getTimerName(), (XltWebClient)getWebClient()));
// DEBUGGING - log response code, response HTTP headers, and response body
XltLogger.runTimeLogger.debug( "Getting response..." );
XltLogger.runTimeLogger.debug( "# Response - Status code:\t" + response.getStatusCode() );
XltLogger.runTimeLogger.debug( "# Response - HTTP header:\t" + response.getResponseHeaders().toString() );
XltLogger.runTimeLogger.debug( "# Response - Body:\t" + response.getContentAsString() );
}