List of usage examples for org.apache.commons.httpclient HttpStatus SC_OK
int SC_OK
To view the source code for org.apache.commons.httpclient HttpStatus SC_OK.
Click Source Link
From source file:com.hp.alm.ali.idea.services.AttachmentService.java
public Entity getAttachmentEntity(String name, EntityRef parent) { MyResultInfo result = new MyResultInfo(); int ret = restService.get(result, "{0}s/{1}/attachments/{2}?alt={3}", parent.type, parent.id, EntityQuery.encode(name), EntityQuery.encode("application/xml")); if (ret != HttpStatus.SC_OK) { errorService.showException(new RestException(result)); return null; }/*from www. j ava 2 s.c o m*/ EntityList list = EntityList.create(result.getBodyAsStream(), true); return list.get(0); }
From source file:net.sf.jaceko.mock.resource.BasicSetupResource.java
@POST @Path("/{operationId}/responses") @Consumes({ MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response addResponse(@Context HttpHeaders headers, @PathParam("serviceName") String serviceName, @PathParam("operationId") String operationId, @QueryParam("code") int customResponseCode, @QueryParam("delay") int delaySec, @QueryParam("headers") String headersToPrime, String customResponseBody) { Map<String, String> headersMap = parseHeadersToPrime(headersToPrime); mockSetupExecutor.addCustomResponse(serviceName, operationId, MockResponse.body(customResponseBody).code(customResponseCode).contentType(headers.getMediaType()) .delaySec(delaySec).headers(headersMap).build()); return Response.status(HttpStatus.SC_OK).build(); }
From source file:it.geosolutions.httpproxy.service.ProxyServiceDefaultTest.java
/** * Test IProxyService execute as HTTP GET *///w w w. j ava 2 s. co m @Test public void testExecuteGet() { try { // Generate mocked request and response MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "/proxy/"); mockRequest.addParameter("url", TEST_URL); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); // Call proxy execute proxy.execute(mockRequest, mockResponse); // Assert the response assertNotNull(mockResponse); assertEquals(mockResponse.getStatus(), HttpStatus.SC_OK); assertNotNull(mockResponse.getOutputStream()); assertNotNull(mockResponse.getContentType()); assertTrue(mockResponse.getContentType().contains("application/vnd.ogc.wms_xml")); LOGGER.info("Success proxy GET in '" + TEST_URL + "'"); LOGGER.info("************************ Response ************************"); LOGGER.info(mockResponse.getContentAsString()); LOGGER.info("********************** EoF Response **********************"); } catch (Exception e) { fail("Exception executing proxy-->\t" + e.getLocalizedMessage()); } }
From source file:com.nfl.dm.clubsites.cms.articles.categorization.OpenCalaisRESTPost.java
private Map<String, ArrayList<String>> doRequest(String input, PostMethod method) { ArrayList<String> person = new ArrayList<String>(); ArrayList<String> organization = new ArrayList<String>(); Map<String, ArrayList<String>> output = new HashMap<String, ArrayList<String>>(); try {//w w w.ja va 2s. co m int returnCode = client.executeMethod(method); if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) { System.err.println("The Post method is not implemented by this URI"); // still consume the response body method.getResponseBodyAsString(); } else if (returnCode == HttpStatus.SC_OK) { System.out.println("Post succeeded: " + input); JSONObject json = (JSONObject) JSONSerializer.toJSON(method.getResponseBodyAsString()); Iterator<?> keys = json.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (json.get(key) instanceof JSONObject && !key.equals("doc")) { JSONObject jsonElement = (JSONObject) json.get(key); if (jsonElement.get("_typeGroup").equals("entities")) { if (jsonElement.get("_type").equals("Person")) { person.add(jsonElement.get("name").toString()); } else if (jsonElement.get("_type").equals("Organization")) { organization.add(jsonElement.get("name").toString()); } } } } output.put("person", person); output.put("organization", organization); } else { System.err.println("Post failed: " + input); System.err.println("Got code: " + returnCode); System.err.println("response: " + method.getResponseBodyAsString()); } } catch (Exception e) { e.printStackTrace(); } finally { method.releaseConnection(); } return output; }
From source file:fr.aliasource.webmail.server.invitation.GetInvitationInfoProxyImpl.java
@SuppressWarnings("unchecked") @Override//from w ww. j a v a 2s .com protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { IAccount ac = (IAccount) req.getSession().getAttribute("account"); if (ac == null) { GWT.log("Account not found in session", null); resp.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } PostMethod pm = new PostMethod(backendUrl); if (req.getQueryString() != null) { pm.setQueryString(req.getQueryString()); } Map<String, String[]> params = req.getParameterMap(); for (String p : params.keySet()) { String[] val = params.get(p); pm.setParameter(p, val[0]); } synchronized (hc) { try { int ret = hc.executeMethod(pm); if (ret != HttpStatus.SC_OK) { log("method failed:\n" + pm.getStatusLine() + "\n" + pm.getResponseBodyAsString()); resp.setStatus(ret); } else { InputStream is = pm.getResponseBodyAsStream(); transfer(is, resp.getOutputStream(), false); } } catch (Exception e) { log("error occured on call proxyfication", e); } finally { pm.releaseConnection(); } } }
From source file:jenkins.plugins.elanceodesk.workplace.notifier.HttpWorker.java
public void run() { int tried = 0; boolean success = false; HttpClient client = getHttpClient(); client.getParams().setConnectionManagerTimeout(timeout); do {/*from w ww.j av a 2 s . c o m*/ tried++; RequestEntity requestEntity; try { requestEntity = new StringRequestEntity(data, "application/json", "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(logger); break; } logger.println(String.format("Posting data to webhook - %s. Already Tried %s times", url, tried)); PostMethod post = new PostMethod(url); try { post.setRequestEntity(requestEntity); int responseCode = client.executeMethod(post); if (responseCode != HttpStatus.SC_OK) { String response = post.getResponseBodyAsString(); logger.println(String.format( "Posting data to - %s may have failed. Webhook responded with status code - %s", url, responseCode)); logger.println(String.format("Message from webhook - %s", response)); } else { success = true; logger.println(String.format("Posting data to webhook - %s completed ", url)); } } catch (Exception e) { logger.println(String.format("Failed to post data to webhook - %s", url)); e.printStackTrace(logger); } finally { post.releaseConnection(); } } while (tried < retries && !success); }
From source file:com.dotcms.rest.SyncPollsResource.java
@POST @Path("/sync") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response publish(@FormDataParam("csvZip") InputStream csvZip, @FormDataParam("csvZip") FormDataContentDisposition fileDetail, @Context HttpServletRequest req) { try {// ww w .j a v a 2 s . c o m String csvPath = pAPI.loadProperty(PollsConstants.PLUGIN_ID, PollsConstants.PROP_GET_CSV_JOB_SRC_PATH); //Scompatto il file untar(csvZip, csvPath, fileDetail.getFileName()); return Response.status(HttpStatus.SC_OK).build(); } catch (DotDataException e) { Logger.error(SyncPollsResource.class, e.getMessage(), e); } return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build(); }
From source file:com.owncloud.android.files.StreamMediaFileOperation.java
protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result;/*from w ww . java2 s.c o m*/ PostMethod postMethod = null; try { postMethod = new PostMethod(client.getBaseUri() + STREAM_MEDIA_URL + JSON_FORMAT); postMethod.setParameter("fileId", fileID); // remote request postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { String response = postMethod.getResponseBodyAsString(); // Parse the response JSONObject respJSON = new JSONObject(response); String url = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString(NODE_URL); result = new RemoteOperationResult(true, postMethod); ArrayList<Object> urlArray = new ArrayList<>(); urlArray.add(url); result.setData(urlArray); } else { result = new RemoteOperationResult(false, postMethod); client.exhaustResponse(postMethod.getResponseBodyAsStream()); } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Get stream url for file with id " + fileID + " failed: " + result.getLogMessage(), result.getException()); } finally { if (postMethod != null) { postMethod.releaseConnection(); } } return result; }
From source file:it.geosolutions.geonetwork.op.GNMetadataGet.java
private static String gnGetMetadata(HTTPUtils connection, String baseURL, final Element gnRequest) throws GNServerException { String serviceURL = baseURL + "/srv/en/xml.metadata.get"; String resp = gnPost(connection, serviceURL, gnRequest); if (connection.getLastHttpStatus() != HttpStatus.SC_OK) throw new GNServerException("Error retrieving metadata in GeoNetwork"); return resp;/*from w ww. ja va 2s. c o m*/ }
From source file:com.prashsoft.javakiva.KivaUtil.java
public static Object getBeanResponse(String urlSuffix, String urlMethod, String urlParams) { Object bean = null;//w w w . j av a2s. c om String url = createKivaAPIUrl(urlSuffix, urlMethod, urlParams); // Create an instance of HttpClient. HttpClient client = new HttpClient(); // Create a method instance. GetMethod method = new GetMethod(url); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println(url + " :: Method failed! : " + method.getStatusLine()); return null; } // Read the response body. InputStream is = method.getResponseBodyAsStream(); BufferedReader in = new BufferedReader(new InputStreamReader(is)); String datastr = null; StringBuffer sb = new StringBuffer(); String inputLine; while ((inputLine = in.readLine()) != null) sb.append(inputLine); in.close(); is.close(); String response = sb.toString(); // Deal with the response. JSONObject jsonObject = JSONObject.fromObject(response); bean = JSONObject.toBean(jsonObject); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } catch (Exception e) { System.err.println("Fatal general error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } return bean; }