List of usage examples for org.apache.http.client.fluent Request Get
public static Request Get(final String uri)
From source file:org.apache.james.jmap.methods.integration.cucumber.DownloadStepdefs.java
@When("^\"([^\"]*)\" downloads \"([^\"]*)\" with an invalid authentication token$") public void getDownloadWithUnknownToken(String username, String attachmentId) throws Exception { String blobId = blobIdByAttachmentId.get(attachmentId); response = Request.Get(mainStepdefs.baseUri().setPath("/download/" + blobId) .addParameter("access_token", INVALID_ATTACHMENT_TOKEN).build()).execute().returnResponse(); }
From source file:com.helger.peppol.bdxrclient.BDXRClientReadOnly.java
/** * Returns a service group. A service group references to the service * metadata. This is a specification compliant method. * * @param aServiceGroupID/*from www . j av a 2 s .co m*/ * The service group id corresponding to the service group which one * wants to get. * @return The service group. Never <code>null</code>. * @throws SMPClientException * in case something goes wrong * @throws SMPClientUnauthorizedException * A HTTP Forbidden was received, should not happen. * @throws SMPClientNotFoundException * The service group id did not exist. * @throws SMPClientBadRequestException * The request was not well formed. * @see #getServiceGroupOrNull(IParticipantIdentifier) */ @Nonnull public ServiceGroupType getServiceGroup(@Nonnull final IParticipantIdentifier aServiceGroupID) throws SMPClientException { ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID"); try { final Request aRequest = Request .Get(m_sSMPHost + IdentifierHelper.getIdentifierURIPercentEncoded(aServiceGroupID)); return executeRequest(aRequest) .handleResponse(SMPHttpResponseHandlerUnsigned.create(new BDXRMarshallerServiceGroupType())); } catch (final Exception ex) { throw getConvertedException(ex); } }
From source file:com.twosigma.beaker.NamespaceClient.java
public List<String> getEvaluators() throws ClientProtocolException, IOException { String args = "session=" + URLEncoder.encode(this.session, "ISO-8859-1"); String reply = Request.Get(ctrlUrlBase + "/getEvaluators?" + args).addHeader("Authorization", auth) .execute().returnContent().asString(); return objectMapper.get().readValue(reply, new TypeReference<List<String>>() { });/*from www. j av a 2 s .c o m*/ }
From source file:photosharing.api.conx.FileDefinition.java
/** * gets the user file metadata results//from w w w .j a va 2s . c o m * * Payload * {"uid":"20971118","thumbnail": * ".\/api\/file?action=thumbnail&pid=7fdedc74-a9f4-46f1-acde-39bef9975847&lid=2597409c-b292-4059-bb4f-3c92c90f5c2e", * "like":true,"lid":"2597409c-b292-4059-bb4f-3c92c90f5c2e","pid":"7fdedc74-a9f4-46f1-acde-39bef9975847","photographer":"ASIC * ASIC","title":"Test32ab.jpeg","tags":["abcd","photojava"]} * * @param request * @param response */ public void getFileMetadata(String bearer, HttpServletRequest request, HttpServletResponse response) { String library = request.getParameter("lid"); String file = request.getParameter("pid"); if (library == null || library.isEmpty() || file == null || file.isEmpty()) { logger.warning("library or file is null"); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } else { // sets the content type - application/json response.setContentType(ContentType.APPLICATION_JSON.getMimeType()); String apiUrl = getFileMetadata(file, library); logger.info(apiUrl); Request get = Request.Get(apiUrl); get.addHeader("Authorization", "Bearer " + bearer); try { Executor exec = ExecutorUtil.getExecutor(); Response apiResponse = exec.execute(get); HttpResponse hr = apiResponse.returnResponse(); /** * Check the status codes */ int code = hr.getStatusLine().getStatusCode(); // Session is no longer valid or access token is expired if (code == HttpStatus.SC_FORBIDDEN) { response.sendRedirect("./api/logout"); } // User is not authorized else if (code == HttpStatus.SC_UNAUTHORIZED) { response.setStatus(HttpStatus.SC_UNAUTHORIZED); } // Default to SC_OK (200) else if (code == HttpStatus.SC_OK) { response.setStatus(HttpStatus.SC_OK); InputStream in = hr.getEntity().getContent(); String jsonString = org.apache.wink.json4j.utils.XML.toJson(in); // Logging out the JSON Object logger.info(jsonString); JSONObject result = new JSONObject(jsonString); JSONObject entry = result.getJSONObject("entry"); logger.info(entry.toString()); JSONObject author = entry.getJSONObject("author"); String photographer = author.getString("name"); String uid = author.getString("userid"); String date = entry.getString("published"); String title = entry.getJSONObject("title").getString("content"); String lid = entry.getString("libraryId"); String pid = entry.getString("uuid"); String thumbnail = "./api/file?action=thumbnail&pid=" + pid + "&lid=" + lid; JSONObject res = new JSONObject(createPhoto(lid, pid, title, uid, photographer, thumbnail)); JSONArray links = entry.getJSONArray("link"); @SuppressWarnings("rawtypes") Iterator iter = links.iterator(); while (iter.hasNext()) { JSONObject obj = (JSONObject) iter.next(); String rel = obj.getString("rel"); if (rel != null && rel.compareTo("recommendation") == 0) { res.put("like", true); } } JSONArray categories = entry.getJSONArray("category"); iter = categories.iterator(); JSONArray tags = new JSONArray(); while (iter.hasNext()) { JSONObject obj = (JSONObject) iter.next(); if (!obj.has("scheme")) { tags.put(obj.getString("term")); } } res.put("tags", tags); res.put("published", date); // Flush the Object to the Stream with content type response.setHeader("Content-Type", "application/json"); PrintWriter out = response.getWriter(); out.println(res.toString()); out.flush(); } } catch (IOException e) { response.setHeader("X-Application-Error", e.getClass().getName()); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); logger.severe("Issue with read userlibrary " + e.toString()); } catch (JSONException e) { response.setHeader("X-Application-Error", e.getClass().getName()); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); logger.severe("Issue with read userlibrary " + e.toString()); e.printStackTrace(); } catch (SAXException e) { response.setHeader("X-Application-Error", e.getClass().getName()); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); logger.severe("Issue with read userlibrary " + e.toString()); } } }
From source file:com.helger.peppol.smpclient.SMPClientReadOnly.java
/** * Gets a list of references to the CompleteServiceGroup's owned by the * specified userId. This is a non-specification compliant method. * * @param sUserID/*from w ww . j a v a 2 s . c o m*/ * The username for which to retrieve service groups. * @param aCredentials * The user name and password to use as credentials. * @return A list of references to complete service groups and never * <code>null</code>. * @throws SMPClientException * in case something goes wrong * @throws SMPClientUnauthorizedException * The username or password was not correct. * @throws SMPClientNotFoundException * The userId did not exist. * @throws SMPClientBadRequestException * The request was not well formed. * @see #getServiceGroupReferenceListOrNull(String, * BasicAuthClientCredentials) */ @Nonnull public ServiceGroupReferenceListType getServiceGroupReferenceList(@Nonnull final String sUserID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException { ValueEnforcer.notNull(sUserID, "UserID"); ValueEnforcer.notNull(aCredentials, "Credentials"); try { final Request aRequest = Request .Get(m_sSMPHost + "list/" + BusdoxURLHelper.createPercentEncodedURL(sUserID)) .addHeader(CHTTPHeader.AUTHORIZATION, aCredentials.getRequestValue()); return executeRequest(aRequest).handleResponse( SMPHttpResponseHandlerUnsigned.create(new SMPMarshallerServiceGroupReferenceListType())); } catch (final Exception ex) { throw getConvertedException(ex); } }
From source file:de.elomagic.maven.http.HTTPMojo.java
private Request createRequestMethod() throws Exception { switch (method) { case DELETE:/* w w w .j a va 2 s. com*/ return Request.Delete(url.toURI()); case GET: return Request.Get(url.toURI()); case HEAD: return Request.Head(url.toURI()); case POST: return Request.Post(url.toURI()); case PUT: return Request.Put(url.toURI()); } throw new Exception("Unsupported HTTP method \"" + method + "\"."); }
From source file:org.apache.james.jmap.methods.integration.cucumber.DownloadStepdefs.java
@When("^\"([^\"]*)\" downloads \"([^\"]*)\" without blobId parameter$") public void getDownloadWithoutBlobId(String username, String attachmentId) throws Throwable { String blobId = blobIdByAttachmentId.get(attachmentId); URIBuilder uriBuilder = mainStepdefs.baseUri().setPath("/download/"); trustForBlobId(blobId, username); AttachmentAccessTokenKey key = new AttachmentAccessTokenKey(username, blobId); uriBuilder.addParameter("access_token", attachmentAccessTokens.get(key).serialize()); response = Request.Get(uriBuilder.build()).execute().returnResponse(); }
From source file:com.softinstigate.restheart.integrationtest.SecurityIT.java
@Test public void testGetAsPowerUser() throws Exception { // *** GET root Response resp = user1Executor.execute(Request.Get(rootUri)); check("check get root as user1", resp, HttpStatus.SC_UNAUTHORIZED); // *** GET db resp = user1Executor.execute(Request.Get(dbUri)); check("check get db as user1", resp, HttpStatus.SC_OK); // *** GET coll1 resp = user1Executor.execute(Request.Get(collection1Uri)); check("check get coll1 as user1", resp, HttpStatus.SC_OK); // *** GET doc1 resp = user1Executor.execute(Request.Get(document1Uri)); check("check get doc1 as user1", resp, HttpStatus.SC_OK); // *** GET coll2 resp = user1Executor.execute(Request.Get(collection2Uri)); check("check get coll2 as user1", resp, HttpStatus.SC_OK); // *** GET doc2 resp = user1Executor.execute(Request.Get(document2Uri)); check("check get doc2 as user1", resp, HttpStatus.SC_OK); }
From source file:org.restheart.test.integration.SecurityIT.java
@Test public void testGetAsPowerUser() throws Exception { // *** GET root Response resp = user1Executor.execute(Request.Get(rootUri)); check("check get root as user1", resp, HttpStatus.SC_FORBIDDEN); // *** GET db resp = user1Executor.execute(Request.Get(dbUri)); check("check get db as user1", resp, HttpStatus.SC_OK); // *** GET coll1 resp = user1Executor.execute(Request.Get(collection1Uri)); check("check get coll1 as user1", resp, HttpStatus.SC_OK); // *** GET doc1 resp = user1Executor.execute(Request.Get(document1Uri)); check("check get doc1 as user1", resp, HttpStatus.SC_OK); // *** GET coll2 resp = user1Executor.execute(Request.Get(collection2Uri)); check("check get coll2 as user1", resp, HttpStatus.SC_OK); // *** GET doc2 resp = user1Executor.execute(Request.Get(document2Uri)); check("check get doc2 as user1", resp, HttpStatus.SC_OK); }
From source file:com.twosigma.beaker.NamespaceClient.java
public List<BeakerCodeCell> getCodeCells(String filter) throws ClientProtocolException, IOException { String args = "session=" + URLEncoder.encode(this.session, "ISO-8859-1") + (filter != null ? "&filter=" + URLEncoder.encode(filter, "ISO-8859-1") : ""); String reply = Request.Get(ctrlUrlBase + "/getCodeCells?" + args).addHeader("Authorization", auth).execute() .returnContent().asString(); BeakerCodeCellList ll = objectMapper.get().readValue(reply, BeakerCodeCellList.class); return ll.theList; }