public String execute() throws ResponseException { return request.execute(); }
@Override public ApplicationStatus getStatus(URI url) { try { LOGGER.debug("Querying " + url + " for its online status."); final Request<Request<?, Response>, Response> request = requestFactory.createRequest(Request.MethodType.GET, url.toString()); request.setConnectionTimeout(CONNECTION_TIMEOUT).setSoTimeout(CONNECTION_TIMEOUT); return request.executeAndReturn(new ReturningResponseHandler<Response, ApplicationStatus>() { @Override public ApplicationStatus handle(final Response response) throws ResponseException { return response.isSuccessful() || (response.getStatusCode() == HttpStatus.SC_FORBIDDEN) || (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) ? ApplicationStatus.AVAILABLE : ApplicationStatus.UNAVAILABLE; } }); } catch (ResponseException re) { return ApplicationStatus.UNAVAILABLE; } }
public JerseyRequest addBasicAuthentication(String hostname, String username, String password) { delegateRequest.addBasicAuthentication(hostname, username, password); return this; }
private static Request<?, ?> createDefaultRequest(RequestFactoryAdapter requestFactoryAdapter, MethodType methodType, String url) throws CredentialsRequiredException { return requestFactoryAdapter.createRequest(methodType, url) .setFollowRedirects(true) .addHeader(OVERRIDE_HEADER_NAME, OVERRIDE_HEADER_VALUE); }
@Override protected String doExecute() throws Exception { String crucibleUrl = getCrucibleUrl(); if (crucibleUrl == null) { return SUCCESS; } Request<?> request = requestFactory.createRequest(Request.MethodType.PUT, crucibleUrl + CRUCIBLE_METRICS_REST_ENDPOINT); request.addTrustedTokenAuthentication(themeProperties.getSystemAdministrator()); request.setRequestBody(metrics); try { metrics = request.execute(); } catch (ResponseException re) { addErrorMessage(getText("crucible.admin.error.response")); log.error("Error communicating with Crucible", re); } return getRedirect("EditMetrics!Default.jspa?message=crucible.admin.info.metrics.updated"); }
request.addRequestParameters("url", baseUrl + JIRA_NOTIFICIATION_URL); request.addTrustedTokenAuthentication(); try request.execute();
@Override public String doDefault() throws Exception { String crucibleUrl = getCrucibleUrl(); if (crucibleUrl == null) { return SUCCESS; } Request<?> request = requestFactory.createRequest(Request.MethodType.GET, crucibleUrl + CRUCIBLE_METRICS_REST_ENDPOINT); request.addTrustedTokenAuthentication(themeProperties.getSystemAdministrator()); try { metrics = request.execute(); } catch (ResponseException re) { addErrorMessage(getText("crucible.admin.error.response")); log.error("Error communicating with Crucible", re); } return SUCCESS; }
.setConnectionTimeout(CONNECTION_TIMEOUT) .setSoTimeout(CONNECTION_TIMEOUT) .setFollowRedirects(false) .execute(new ResponseHandler()
request.addBasicAuthentication("", getFisheyeAdminPassword()); request.execute(responseHandler);
public Iterable<ExternalActivityItem> getItems(ApplicationLink appLink, ExternalActivityItemSearchParams params) throws Exception { final String uri = remoteStreamsFeedUriBuilder.buildUri(appLink, params).toASCIIString(); try { final Request<?, ?> request = appLink.createAuthenticatedRequestFactory().createRequest(Request.MethodType.GET, uri); request.setConnectionTimeout(CONNECTION_TIMEOUT); request.setSoTimeout(SO_TIMEOUT); return itemFactory.getItems(request.execute()); } catch (Exception e) { log.warn("Cannot fetch remote feed from: " + uri); throw e; } } }
private TokenAndSecret requestToken(String url, Request signedRequest) throws ResponseException { final com.atlassian.sal.api.net.Request tokenRequest = requestFactory.createRequest(com.atlassian.sal.api.net.Request.MethodType.POST, url); tokenRequest.addRequestParameters(parameterToStringArray(signedRequest.getParameters())); tokenRequest.setFollowRedirects(false); tokenRequest.execute(responseHandler); final Map<String, String> oAuthParameterMap = oauthParametersHolder.get();
@Test public void testCanSendMultipartPutRequest() throws Exception { Server server = new Server(0); ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(SetFilesServlet.class, "/*"); server.setHandler(handler); try { // start jetty. server.start(); // now, make a request. Request<?, ?> request = requestFactory.createRequest(Request.MethodType.PUT, "http://localhost:" + getActivePort(server)); request.setFiles(Collections.singletonList(new RequestFilePart(testFile, "testFile"))); request.execute(new ResponseHandler() { public void handle(final Response response) throws ResponseException { assertTrue(response.isSuccessful()); } }); } finally { server.stop(); } }
request.setRequestBody(data, "text/xml"); if (log.isDebugEnabled()) try request.execute();
/** * Fetches consumer information from a remote applinked application, assuming it is running the OAuth plugin. * * @param applicationLink link to fetch the information from * @return Consumer object representing the linked application * @throws ResponseException if the fetch fails for any reason */ @Nonnull public static Consumer fetchConsumerInformation(@Nonnull ApplicationLink applicationLink) throws ResponseException { final Request<?, ?> request = Anonymous.createAnonymousRequest(applicationLink, Request.MethodType.GET, Uris.uncheckedConcatenate(applicationLink.getRpcUrl(), CONSUMER_INFO_PATH).toString()); request.setHeader("Accept", "application/xml"); final ConsumerInformationResponseHandler handler = new ConsumerInformationResponseHandler(); request.execute(handler); return handler.getConsumer(); }
try { final Request<Request<?, Response>, Response> request = requestFactory.createRequest(action, autoConfigUrl.toString()); request.addHeader(XsrfProtectedServlet.OVERRIDE_HEADER_NAME, XsrfProtectedServlet.OVERRIDE_HEADER_VALUE); request.execute(new ResponseHandler<Response>() { public void handle(final Response response) throws ResponseException { if (response.isSuccessful()) {
public <R> R execute(final ApplicationLinkResponseHandler<R> applicationLinkResponseHandler) throws ResponseException { return (R) request.executeAndReturn(applicationLinkResponseHandler); }
public void execute(final CtkTestResults results) throws ResponseException { results.assertTrue("RequestFactory must be injectable", requestFactory != null); Request<?, ?> request = requestFactory.createRequest(Request.MethodType.GET, "http://google.com"); request.execute(new ResponseHandler() { public void handle(final Response response) throws ResponseException { passed = response.getResponseBodyAsString().contains("Google"); } }); results.assertTrue("Should be able to call http://google.com and get result that contains 'google'", passed); request = requestFactory.createRequest(Request.MethodType.GET, "http://demo.jira.com"); request.addSeraphAuthentication("admin", "admin"); request.execute(new ResponseHandler() { public void handle(final Response response) throws ResponseException { passed = response.getResponseBodyAsString().contains("Joe Administrator"); } }); results.assertTrueOrWarn("Should be able to call http://demo.jira.com and log in using seraph authentication", passed); } }
request.setHeader("X-Atlassian-Token", "no-check"); request.setHeader("X-Forwarded-For", xForward != null ? xForward : req.getRemoteAddr()); if (ctHeader != null) request.setHeader("Content-Type", ctHeader); params.add(req.getParameter(name)); request.addRequestParameters((String[]) params.toArray(new String[params.size()])); request.setRequestBody(str);