public String execute() throws ResponseException { return request.execute(); }
private void makeRequestExpectingUnauthorized(Request request) throws Exception { request.execute(new ResponseHandler() { public void handle(Response response) throws ResponseException { assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatusCode()); assertTrue(response.getResponseBodyAsString().contains("This resource requires WebSudo")); } }); }
public void execute(final ResponseHandler responseHandler) throws ResponseException { request.execute(responseHandler); }
public void execute(final ResponseHandler responseHandler) throws ResponseException { request.execute(responseHandler); }
public String execute() throws ResponseException { return request.execute(); }
/** * Makes a non-OAuth request and expects a specific text. * * @param request request * @param expectedText expected text */ public static void makeRequestExpectingText(Request request, final String expectedText) throws Exception { request.execute(new ResponseHandler() { public void handle(Response response) throws ResponseException { assertEquals(HttpServletResponse.SC_OK, response.getStatusCode()); assertEquals(expectedText, response.getResponseBodyAsString()); } }); }
@Override public String execute() throws ResponseException { marshallEntity(); return delegateRequest.execute(); }
protected String get(URI uri) throws ResponseException { Request request = createRequestWithBasicAuthentication(uri); return request.execute(); }
private Iterable<EntityReference> getEntities(final ApplicationLinkRequestFactory requestFactory) throws CredentialsRequiredException, ResponseException { final Request req = requestFactory.createRequest(Request.MethodType.GET, RestUtil.REST_APPLINKS_URL + EntityResource.CONTEXT); final List<EntityReference> entities = new ArrayList<EntityReference>(); req.execute(new ResponseHandler<Response>() { public void handle(final Response response) throws ResponseException { if (response.getStatusCode() == 200) { Iterables.addAll(entities, response.getEntity(ReferenceEntityList.class).getEntities(typeAccessor)); } else { throw new ResponseException(String.format("Failed to retrieve entity list, received %s response: %s", response.getStatusCode(), response.getStatusText())); } } }); return entities; }
@Test public void assert200() throws ResponseException { URI uri = UriBuilder.fromUri(applicationProperties.getBaseUrl()).path("prettyurls").path("helloworld").build(); Request request = requestFactory.createRequest(Request.MethodType.GET, uri.toString()); request.execute(new ResponseHandler() { @Override public void handle(Response response) throws ResponseException { assertEquals(200, response.getStatusCode()); } }); }
@Test public void assert404() throws ResponseException { URI uri = UriBuilder.fromUri(applicationProperties.getBaseUrl()).path("prettyurls").path("path-that-does-not-exist").build(); Request request = requestFactory.createRequest(Request.MethodType.GET, uri.toString()); request.execute(new ResponseHandler() { @Override public void handle(Response response) throws ResponseException { assertEquals(404, response.getStatusCode()); } }); }
/** * 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(); }
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; } } }
public void execute(Map transientVars, Map args, PropertySet propertySet) throws WorkflowException { Issue issue = (Issue) transientVars.get("issue"); String projectKey = issue.getProjectObject().getKey(); ApplicationLink crucible = appLinksManager.getLinkedApplication(Application.CRUCIBLE.name(), projectKey); Request<?> request = requestFactory.createRequest(Request.MethodType.POST, crucible.getUrl() + CREATE_REVIEW_PATH + "?key=" + crucible.getRemoteKey() + "&issueKey=" + issue.getKey()); request.addTrustedTokenAuthentication(); try { request.execute(); } catch (ResponseException re) { log.error("Error creating code review on Crucible", re); } } }
private boolean isRpcUrlValid(final URI url, final URI rpcUrl, final String username, final String password) throws ResponseException { // We send the rpcUrl parameter in a query parameter. For pre-3.4 versions of the REST resource, we also // send it in the path. // TODO If we know the server is using applinks 3.4, the rpcUrl path parameter can be empty String pathUrl = getUrlFor(URIUtil.uncheckedConcatenate(url, RestUtil.REST_APPLINKS_URL), AuthenticationResource.class).rpcUrlIsReachable(internalHostApplication.getId().get(), rpcUrl, null).toString(); String urlWithQuery = pathUrl + "?url=" + URIUtil.utf8Encode(rpcUrl); final Request request = requestFactory.createRequest(Request.MethodType.GET, urlWithQuery); request.addBasicAuthentication(url.getHost(), username, password); final Holder<Boolean> rpcUrlValid = new Holder<Boolean>(false); request.execute(new ResponseHandler<Response>() { public void handle(final Response restResponse) throws ResponseException { if (restResponse.isSuccessful()) { rpcUrlValid.set(true); } } }); return rpcUrlValid.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(); } }
@Test public void testCanSendMultipartPostRequest() 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.POST, "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(); } }
@Override protected String doExecute() throws Exception { if (!hasAdministratePermissionOnProject(key)) { return SECURITY_BREACH; } ApplicationLink appLink = appLinksManager.getLinkedApplication(Application.CRUCIBLE.name(), key); Request<?> request = requestFactory.createRequest(Request.MethodType.PUT, getRestResource(appLink)); request.addTrustedTokenAuthentication(themeProperties.getSystemAdministrator()); request.setRequestBody(XStreamUtils.toXML(projectConfig)); try { request.execute(); } catch (ResponseException re) { addErrorMessage(re.getMessage()); log.error("Error putting crucible project config", re); return INPUT; } return getRedirect("CrucibleProject!ListProjects.jspa?message=crucible.admin.info.updated"); }
@Test public void testExecuteUnauthenticatedRequest() throws Exception { Server server = new Server(0); ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(HelloServlet.class, "/*"); server.setHandler(handler); try { // start jetty. server.start(); // now, make a request. Request<?, ?> request = requestFactory.createRequest(Request.MethodType.GET, "http://localhost:" + getActivePort(server)); request.execute(new ResponseHandler() { public void handle(final Response response) throws ResponseException { passed = response.getResponseBodyAsString().contains(MESSAGE); } }); assertTrue("Should be able to get result from http", passed); } finally { server.stop(); } }
public String doSynchronize() { final ApplicationLink localLink = appLinksManager.getLinkedApplication(app, getKey()); final String restUrl = localLink.getUrl() + "/plugins/servlet/applinks/projectlinks"; final Request<?> request = requestFactory.createRequest(Request.MethodType.POST, restUrl + "?key=" + localLink.getRemoteKey() + "&application=JIRA"); final ApplicationLink remoteLink = new DefaultApplicationLink("jira", getKey(), null, null); request.setRequestBody(XStreamUtils.toXML(remoteLink)); request.addTrustedTokenAuthentication(); try { request.execute(); } catch (final ResponseException re) { return getRedirect("ViewProject.jspa?message=editprojectlinks.error.synchronize&pid=" + getPid()); } return getRedirect("ViewProject.jspa?message=editprojectlinks.result.synchronized&pid=" + getPid()); }