@Test public void buildRequestContentLength() { String content = "some content that has length"; webRequest.setHttpMethod(HttpMethod.POST); webRequest.setRequestBody(content); MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext); assertThat(actualRequest.getContentLength(), equalTo(content.length())); }
@Test public void buildRequestReader() throws Exception { String expectedBody = "request body"; webRequest.setHttpMethod(HttpMethod.POST); webRequest.setRequestBody(expectedBody); MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext); assertThat(IOUtils.toString(actualRequest.getReader()), equalTo(expectedBody)); }
@Test @SuppressWarnings("deprecation") public void buildRequestInputStream() throws Exception { String content = "some content that has length"; webRequest.setHttpMethod(HttpMethod.POST); webRequest.setRequestBody(content); MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext); assertThat(IOUtils.toString(actualRequest.getInputStream()), equalTo(content)); }
String url = "http://cpdocket.cp.cuyahogacounty.us/Search.aspx"; String EventTarget = "ctl00$SheetContentPlaceHolder$rbCivilForeclosure"; String world = "ctl00$SheetContentPlaceHolder$UpdatePanel1|ctl00$SheetContentPlaceHolder$rbCivilForeclosure"; String Viewstate = page2.getElementById("__VIEWSTATE").getAttribute("value"); String EventValidation = page2.getElementById("__EVENTVALIDATION").getAttribute("value"); WebRequest req1 = new WebRequest(new URL(url)); req1.setHttpMethod(HttpMethod.POST); req1.setAdditionalHeader("Origin", "http://cpdocket.cp.cuyahogacounty.us"); req1.setAdditionalHeader("Referer", "http://cpdocket.cp.cuyahogacounty.us/Search.aspx"); req1.setAdditionalHeader("X-Requested-With", "XMLHttpRequest"); String txtview1 = "ctl00$ScriptManager1=" + URLEncoder.encode(world) + "&__EVENTTARGET=" + URLEncoder.encode(EventTarget) + "&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=" + URLEncoder.encode(Viewstate) + "&__EVENTVALIDATION=" + URLEncoder.encode(EventValidation) + "&ctl00$SheetContentPlaceHolder$rbSearches=forcl&__ASYNCPOST=true&"; //System.out.println("this is text view =============== " + txtview1); req1.setRequestBody(txtview1); req1.setAdditionalHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); String re=client.getPage(req1).getWebResponse().getContentAsString(); System.out.println("========== " + re);
/** * Prepares the WebRequest that will be sent. * @param content the content to send */ private void prepareRequest(final Object content) { if (content != null && (HttpMethod.POST == webRequest_.getHttpMethod() || HttpMethod.PUT == webRequest_.getHttpMethod() || HttpMethod.PATCH == webRequest_.getHttpMethod()) && content != Undefined.instance) { if (content instanceof FormData) { ((FormData) content).fillRequest(webRequest_); } else { final String body = Context.toString(content); if (!body.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("Setting request body to: " + body); } webRequest_.setRequestBody(body); } } } }
/** * Prepares the WebRequest that will be sent. * @param content the content to send */ private void prepareRequest(final Object content) { if (content != null && (HttpMethod.POST == webRequest_.getHttpMethod() || HttpMethod.PUT == webRequest_.getHttpMethod() || HttpMethod.PATCH == webRequest_.getHttpMethod()) && content != Undefined.instance) { if (content instanceof FormData) { ((FormData) content).fillRequest(webRequest_); } else { final String body = Context.toString(content); if (!body.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("Setting request body to: " + body); } webRequest_.setRequestBody(body); } } } }
/** * Prepares the WebRequest that will be sent. * @param content the content to send */ private void prepareRequest(final Object content) { if (content != null && content != Undefined.instance) { if (!"".equals(content) && HttpMethod.GET == webRequest_.getHttpMethod()) { webRequest_.setHttpMethod(HttpMethod.POST); } if (HttpMethod.POST == webRequest_.getHttpMethod() || HttpMethod.PUT == webRequest_.getHttpMethod() || HttpMethod.PATCH == webRequest_.getHttpMethod()) { if (content instanceof FormData) { ((FormData) content).fillRequest(webRequest_); } else { final String body = Context.toString(content); if (!body.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("Setting request body to: " + body); } webRequest_.setRequestBody(body); } } } } }
/** * Prepares the WebRequest that will be sent. * @param content the content to send */ private void prepareRequest(final Object content) { if (content != null && content != Undefined.instance) { if (!"".equals(content) && HttpMethod.GET == webRequest_.getHttpMethod()) { webRequest_.setHttpMethod(HttpMethod.POST); } if (HttpMethod.POST == webRequest_.getHttpMethod() || HttpMethod.PUT == webRequest_.getHttpMethod() || HttpMethod.PATCH == webRequest_.getHttpMethod()) { if (content instanceof FormData) { ((FormData) content).fillRequest(webRequest_); } else { final String body = Context.toString(content); if (!body.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("Setting request body to: " + body); } webRequest_.setRequestBody(body); } } } } }
public void post() throws Exception { URL url = new URL("YOURURL"); WebRequest requestSettings = new WebRequest(url, HttpMethod.POST); requestSettings.setAdditionalHeader("Accept", "*/*"); requestSettings.setAdditionalHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); requestSettings.setAdditionalHeader("Referer", "REFURLHERE"); requestSettings.setAdditionalHeader("Accept-Language", "en-US,en;q=0.8"); requestSettings.setAdditionalHeader("Accept-Encoding", "gzip,deflate,sdch"); requestSettings.setAdditionalHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3"); requestSettings.setAdditionalHeader("X-Requested-With", "XMLHttpRequest"); requestSettings.setAdditionalHeader("Cache-Control", "no-cache"); requestSettings.setAdditionalHeader("Pragma", "no-cache"); requestSettings.setAdditionalHeader("Origin", "https://YOURHOST"); requestSettings.setRequestBody("REQUESTBODY"); Page redirectPage = webClient.getPage(requestSettings); }
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); } }
pingRequest.setAdditionalHeader(HttpHeader.PING_FROM, page.getUrl().toExternalForm()); pingRequest.setAdditionalHeader(HttpHeader.PING_TO, url.toExternalForm()); pingRequest.setRequestBody("PING"); page.getWebClient().loadWebResponse(pingRequest);
pingRequest.setAdditionalHeader(HttpHeader.PING_FROM, page.getUrl().toExternalForm()); pingRequest.setAdditionalHeader(HttpHeader.PING_TO, url.toExternalForm()); pingRequest.setRequestBody("PING"); page.getWebClient().loadWebResponse(pingRequest);
WebRequest requestSettings = new WebRequest(new URL(jiraSetFieldPage), HttpMethod.POST); requestSettings.setAdditionalHeader("Content-type", "application/json"); requestSettings.setRequestBody(updateString); try { UnexpectedPage infoPage = webClient.getPage(requestSettings);
private FreeStyleBuild sendCommitTriggerMultipleSvnLocations(FreeStyleProject p, boolean includeRevision) throws Exception { String repoUUID = "71c3de6d-444a-0410-be80-ed276b4c234a"; WebClient wc = r.createWebClient(); WebRequest wr = new WebRequest(new URL(r.getURL() + "subversion/" + repoUUID + "/notifyCommit"), HttpMethod.POST); wr.setRequestBody("A trunk/hudson/test-projects/trivial-ant/build.xml\n" + "M trunk/hudson/test-projects/trivial-maven/src/main/"); wr.setAdditionalHeader("Content-Type", "text/plain;charset=UTF-8"); if (includeRevision) { wr.setAdditionalHeader("X-Hudson-Subversion-Revision", "18075"); } WebConnection conn = wc.getWebConnection(); WebResponse resp = conn.getResponse(wr); assertTrue(r.isGoodHttpStatus(resp.getStatusCode())); Thread.sleep(1000); r.waitUntilNoActivity(); FreeStyleBuild b = p.getLastBuild(); assertNotNull(b); r.assertBuildStatus(Result.SUCCESS,b); return b; }
private FreeStyleBuild sendCommitTrigger(FreeStyleProject p, boolean includeRevision) throws Exception { String repoUUID = "71c3de6d-444a-0410-be80-ed276b4c234a"; WebClient wc = r.createWebClient(); WebRequest wr = new WebRequest(new URL(r.getURL() + "subversion/" + repoUUID + "/notifyCommit"), HttpMethod.POST); wr.setRequestBody("A trunk/hudson/test-projects/trivial-ant/build.xml"); wr.setAdditionalHeader("Content-Type", "text/plain;charset=UTF-8"); if (includeRevision) { wr.setAdditionalHeader("X-Hudson-Subversion-Revision", "13000"); } WebConnection conn = wc.getWebConnection(); WebResponse resp = conn.getResponse(wr); assertTrue(r.isGoodHttpStatus(resp.getStatusCode())); Thread.sleep(1000); r.waitUntilNoActivity(); FreeStyleBuild b = p.getLastBuild(); assertNotNull(b); r.assertBuildStatus(Result.SUCCESS,b); return b; }
/** * Tests that configuring an existing project via jenkins http rest doesn't produce duplicated triggers * and that the trigger is configured for the new project pattern. * * @throws Exception if so */ @Test @LocalData public void testReconfigureUsingRestApi() throws Exception { assertNrOfEventListeners(0); TopLevelItem testProj = j.jenkins.getItem("testProj"); String gerritProjectPattern = "someotherproject"; XmlPage xmlPage = loadConfigXmlViaHttp(testProj); Document document = xmlPage.getXmlDocument(); String xml = changeConfigXml(gerritProjectPattern, document); URL url = UrlUtils.toUrlUnsafe(j.getURL().toExternalForm() + testProj.getUrl() + "config.xml"); WebRequest request = new WebRequest(url, HttpMethod.POST); request.setRequestBody(xml); j.jenkins.setCrumbIssuer(null); Page page = j.createWebClient().getPage(request); j.assertGoodStatus(page); assertNrOfEventListeners(0); assertEventListenerWithSomeOtherProjectSet(gerritProjectPattern); }