本文整理汇总了Java中com.gargoylesoftware.htmlunit.WebRequest.setAdditionalHeader方法的典型用法代码示例。如果您正苦于以下问题:Java WebRequest.setAdditionalHeader方法的具体用法?Java WebRequest.setAdditionalHeader怎么用?Java WebRequest.setAdditionalHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.gargoylesoftware.htmlunit.WebRequest
的用法示例。
在下文中一共展示了WebRequest.setAdditionalHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFormHeaderOk
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
/**
* Checks that CSRF validation works if token sent as header instead of
* form field.
*
* @throws Exception an error occurs or validation fails.
*/
@Test
public void testFormHeaderOk() throws Exception {
HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf");
// Check response and CSRF header
WebResponse res = page1.getWebResponse();
assertEquals(Response.Status.OK.getStatusCode(), res.getStatusCode());
assertNotNull(res.getResponseHeaderValue(CSRF_HEADER));
WebRequest req = new WebRequest(new URL(webUrl + "resources/csrf"));
req.setHttpMethod(HttpMethod.POST);
req.setAdditionalHeader(CSRF_HEADER, res.getResponseHeaderValue(CSRF_HEADER));
res = webClient.loadWebResponse(req);
assertEquals(Response.Status.OK.getStatusCode(), res.getStatusCode());
}
示例2: 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);
}
}
示例3: collectIssues
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
/**
* Get a Jira query result in a map form.
*
* @param query is the jira query
* @return with the map of JIRA_ID - ticketInfo in JSONObject pairs as result of a Jira query.
* @throws IOException in case of problem
* @throws JSONException in case of problem
*/
public ConcurrentHashMap<String, JSONObject> collectIssues(final String query) throws IOException, JSONException {
String jqlURL = getListOfIssuesByQueryUrl(query);
WebRequest requestSettings = new WebRequest(new URL(jqlURL), HttpMethod.GET);
requestSettings.setAdditionalHeader("Content-type", "application/json");
UnexpectedPage infoPage = webClient.getPage(requestSettings);
if (infoPage.getWebResponse().getStatusCode() == HTTP_RESPONSE_OK) {
String ticketList = infoPage.getWebResponse().getContentAsString();
JSONObject obj = new JSONObject(ticketList);
String maxResults = obj.getString("maxResults");
String total = obj.getString("total");
if (Integer.valueOf(maxResults) < Integer.valueOf(total)) {
throw new SimpleGepardException("ERROR: Too many issues belong to given query (" + total + "), please change the query to shorten the result list.");
}
JSONArray array = obj.getJSONArray("issues");
ConcurrentHashMap<String, JSONObject> map = new ConcurrentHashMap<>();
for (int i = 0; i < array.length(); i++) {
JSONObject o = (JSONObject) array.get(i);
map.put(o.getString("key"), o);
}
return map;
}
throw new SimpleGepardException("ERROR: Cannot fetch Issue list from JIRA, status code:" + infoPage.getWebResponse().getStatusCode());
}
示例4: 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;
}
示例5: 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);
}
示例6: getIoCTest
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 6)
@OperateOnDeployment("ear")
@RunAsClient
public void getIoCTest(@ArquillianResource URL context) throws Exception {
WebClient webClient = new WebClient();
WebRequest requestSettings = new WebRequest(new URL(context + "rest/blacklist/record/seznam.cz"), HttpMethod.GET);
requestSettings.setAdditionalHeader("Content-Type", "application/json");
requestSettings.setAdditionalHeader("X-sinkit-token", TOKEN);
Page page = webClient.getPage(requestSettings);
assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
String responseBody = page.getWebResponse().getContentAsString();
LOGGER.info("getIoCTest Response:" + responseBody);
String expected = "\"black_listed_domain_or_i_p\":\"aed14ad7ed6c543f818a4cfe89cb8f20\""; // md5 of seznam.cz
assertTrue(responseBody.contains(expected), "IoC response should have contained " + expected + ", but got:" + responseBody);
expected = "\"sources\":{\"feed2\":{\"a\":\"blacklist\",\"b\":\"myDocumentId\"}}";
assertTrue(responseBody.contains(expected), "IoC should have contained " + expected + ", but got: " + responseBody);
}
示例7: iocInCacheTest
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 11)
@OperateOnDeployment("ear")
@RunAsClient
public void iocInCacheTest(@ArquillianResource URL context) throws Exception {
WebClient webClient = new WebClient();
WebRequest requestSettings = new WebRequest(new URL(context + "rest/blacklist/record/phishing.ru"), HttpMethod.GET);
requestSettings.setAdditionalHeader("Content-Type", "application/json");
requestSettings.setAdditionalHeader("X-sinkit-token", TOKEN);
Page page = webClient.getPage(requestSettings);
assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
String responseBody = page.getWebResponse().getContentAsString();
LOGGER.info("iocInCacheTest Response:" + responseBody);
String expected = "\"black_listed_domain_or_i_p\":\"926dab5157943daed27851a34f30b701\""; // md5 of phishing.ru
assertTrue(responseBody.contains(expected), "IoC response should have contained " + expected + ", but got:" + responseBody);
expected = "\"sources\":{\"integrationTest\":{\"a\":\"phishing\",\"b\":\"";
assertTrue(responseBody.contains(expected), "IoC should have contained " + expected + ", but got: " + responseBody);
}
示例8: getHtmlPageHtmlUnit
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
/**
* HtmlUnit을 이용한 HTML 코드 파싱.
* @param eachArchiveAddress 실제 만화가 담긴 아카이브 주소
* @return 성공 시 html 코드를 리턴
*/
private String getHtmlPageHtmlUnit(String eachArchiveAddress) throws Exception {
/* 필수! 로그 메세지 출력 안함 -> HtmlUnit 이용시 Verbose한 로그들이 너무 많아서 다 끔 */
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
System.out.print("일반 연결 시도중 ... ");
WebClient webClient = new WebClient();
webClient.getOptions().setRedirectEnabled(true);
WebRequest req = new WebRequest(new URL(eachArchiveAddress));
req.setHttpMethod(HttpMethod.POST);
req.setAdditionalHeader("User-Agent", UserAgent.getUserAgent());
req.setAdditionalHeader("Accept-Encoding", "gzip"); //20171126 gzip 추가
req.getRequestParameters().add(new NameValuePair("pass", PASSWORD)); //비밀번호 post 방식 전송
HtmlPage page = webClient.getPage(req);
//Html코드를 포함한 페이지 소스코드가 담길 스트링
String pageSource = page.asXml();
/** 여기도 페이지 파싱 실패 시 검증하는 코드 들어가야 됨 **/
webClient.close();
System.out.println("성공");
return pageSource;
}
示例9: language1
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test
public void language1() throws Exception {
final WebRequest wrq = new WebRequest(new URL(webUrl + "resources/language1"), ACCEPT_HEADER);
wrq.setAdditionalHeader("Accept-Language", ACCEPT_LANGUAGE);
final WebResponse wr = webClient.loadWebResponse(wrq);
assertEquals(Response.Status.OK.getStatusCode(), wr.getStatusCode());
assertEquals(MediaType.APPLICATION_XHTML_XML, wr.getContentType());
assertEquals("es", wr.getResponseHeaderValue("Content-Language"));
}
示例10: language2
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test
public void language2() throws Exception {
final WebRequest wrq = new WebRequest(new URL(webUrl + "resources/language2"), ACCEPT_HEADER);
wrq.setAdditionalHeader("Accept-Language", ACCEPT_LANGUAGE);
final WebResponse wr = webClient.loadWebResponse(wrq);
assertEquals(Response.Status.OK.getStatusCode(), wr.getStatusCode());
assertEquals(MediaType.APPLICATION_XHTML_XML, wr.getContentType());
assertEquals("es", wr.getResponseHeaderValue("Content-Language"));
}
示例11: locale1
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test
public void locale1() throws Exception {
final WebRequest wrq = new WebRequest(new URL(webUrl + "resources/locale1"), ACCEPT_HEADER);
wrq.setAdditionalHeader("Accept-Language", ACCEPT_LANGUAGE);
final WebResponse wr = webClient.loadWebResponse(wrq);
assertEquals(Response.Status.OK.getStatusCode(), wr.getStatusCode());
assertEquals(MediaType.APPLICATION_XHTML_XML, wr.getContentType());
assertEquals("en-GB", wr.getResponseHeaderValue("Content-Language"));
}
示例12: locale2
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test
public void locale2() throws Exception {
final WebRequest wrq = new WebRequest(new URL(webUrl + "resources/locale2"), ACCEPT_HEADER);
wrq.setAdditionalHeader("Accept-Language", ACCEPT_LANGUAGE);
final WebResponse wr = webClient.loadWebResponse(wrq);
assertEquals(Response.Status.OK.getStatusCode(), wr.getStatusCode());
assertEquals(MediaType.APPLICATION_XHTML_XML, wr.getContentType());
assertEquals("en-GB", wr.getResponseHeaderValue("Content-Language"));
}
示例13: detectWorkflow
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
/**
* Detect the actual workflow possibilities of the ticket, from its actual status.
*
* @param ticket is the id
* @return with String representation of the list of possibilities, in form of statusTransferId;newStatusName strings
* @throws IOException in case of problem
* @throws JSONException in case of problem
*/
public String detectWorkflow(final String ticket) throws IOException, JSONException {
String jqlURL;
//first detect status
String ticketFields = getTicketFields(ticket);
JSONObject fieldObj = new JSONObject(ticketFields);
fieldObj = fieldObj.getJSONObject("fields");
fieldObj = fieldObj.getJSONObject("status");
String status = "@" + fieldObj.get("name").toString();
//then collect possible transactions
jqlURL = getIssueTransitionsUrl(ticket);
WebRequest requestSettings = new WebRequest(new URL(jqlURL), HttpMethod.GET);
requestSettings.setAdditionalHeader("Content-type", "application/json");
UnexpectedPage infoPage = webClient.getPage(requestSettings);
if (infoPage.getWebResponse().getStatusCode() == HTTP_RESPONSE_OK) {
String ticketList = infoPage.getWebResponse().getContentAsString();
JSONObject obj = new JSONObject(ticketList);
JSONArray array = obj.getJSONArray("transitions");
List<String> toList = new ArrayList<>();
toList.add(status);
for (int i = 0; i < array.length(); i++) {
JSONObject o = (JSONObject) array.get(i);
JSONObject o2 = o.getJSONObject("to");
String toPossibility = o2.get("name").toString();
String toPossibilityID = o.get("id").toString(); //it is the transition id not the status id
toList.add(toPossibilityID + ";" + toPossibility);
}
return toList.toString();
}
throw new SimpleGepardException("ERROR: Cannot fetch Issue transition possibilities from JIRA, for ticket: "
+ ticket + ", Status code:" + infoPage.getWebResponse().getStatusCode());
}
示例14: getStatsTest
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 4)
@OperateOnDeployment("ear")
@RunAsClient
public void getStatsTest(@ArquillianResource URL context) throws Exception {
WebClient webClient = new WebClient();
WebRequest requestSettings = new WebRequest(new URL(context + "rest/stats"), HttpMethod.GET);
requestSettings.setAdditionalHeader("Content-Type", "application/json");
requestSettings.setAdditionalHeader("X-sinkit-token", TOKEN);
Page page = webClient.getPage(requestSettings);
assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
String responseBody = page.getWebResponse().getContentAsString();
LOGGER.info("getStatsTest Response:" + responseBody);
String expected = "{\"rule\":4,\"ioc\":1}";
assertTrue(responseBody.contains(expected), "Expected: " + expected + ". got: " + responseBody);
}
示例15: getIoCsTest
import com.gargoylesoftware.htmlunit.WebRequest; //导入方法依赖的package包/类
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 5)
@OperateOnDeployment("ear")
@RunAsClient
public void getIoCsTest(@ArquillianResource URL context) throws Exception {
WebClient webClient = new WebClient();
WebRequest requestSettings = new WebRequest(new URL(context + "rest/blacklist/records"), HttpMethod.GET);
requestSettings.setAdditionalHeader("Content-Type", "application/json");
requestSettings.setAdditionalHeader("X-sinkit-token", TOKEN);
Page page = webClient.getPage(requestSettings);
assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
String responseBody = page.getWebResponse().getContentAsString();
LOGGER.info("getIoCsTest Response:" + responseBody);
String expected = "[\"aed14ad7ed6c543f818a4cfe89cb8f20\"]"; // md5 of seznam.cz
assertTrue(responseBody.contains(expected), "Expected " + expected + ", but got: " + responseBody);
}