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:it.geosolutions.geonetwork.op.GNMetadataSearch.java
private static String gnSearchMetadata(HTTPUtils connection, String baseURL, final Element gnRequest) throws GNServerException { String serviceURL = baseURL + "/srv/en/xml.search"; String resp = gnPost(connection, serviceURL, gnRequest); if (connection.getLastHttpStatus() != HttpStatus.SC_OK) throw new GNServerException("Error searching metadata in GeoNetwork"); return resp;/*from w w w.j a v a 2s.co m*/ }
From source file:com.calclab.emite.j2se.services.HttpConnector.java
private Runnable createResponseAction(final String xml, final ConnectorCallback callback, final String id, final int status, final String response) { final Runnable runnable = new Runnable() { public void run() { if (status == HttpStatus.SC_OK) { System.out.println("RECEIVED: " + response); Logger.debug("Connector [{0}] receive: {1}", id, response); callback.onResponseReceived(status, response); } else { Logger.debug("Connector [{0}] bad status: {1}", id, status); callback.onError(xml, new Exception("bad http status " + status)); }/* w w w . ja v a 2s. c o m*/ } }; return runnable; }
From source file:com.twitter.tokyo.kucho.SeatingList.java
String loadJSON(String url) throws IOException { HttpClient client = new HttpClient(); HttpMethod getMethod = new GetMethod(url); int statusCode = client.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { throw new IOException("Server returned " + statusCode); }/*from ww w . j a v a2 s . c o m*/ return getMethod.getResponseBodyAsString(); }
From source file:com.owncloud.android.lib.resources.files.GetMetadataOperation.java
/** * @param client Client object//w w w . j a va2 s. co m */ @Override protected RemoteOperationResult run(OwnCloudClient client) { GetMethod getMethod = null; RemoteOperationResult result; try { // remote request getMethod = new GetMethod(client.getBaseUri() + METADATA_URL + fileId + JSON_FORMAT); getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { String response = getMethod.getResponseBodyAsString(); // Parse the response JSONObject respJSON = new JSONObject(response); String metadata = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA) .get(NODE_META_DATA); result = new RemoteOperationResult(true, getMethod); ArrayList<Object> metadataArray = new ArrayList<>(); metadataArray.add(metadata); result.setData(metadataArray); } else { result = new RemoteOperationResult(false, getMethod); client.exhaustResponse(getMethod.getResponseBodyAsStream()); } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Fetching of metadata for folder " + fileId + " failed: " + result.getLogMessage(), result.getException()); } finally { if (getMethod != null) getMethod.releaseConnection(); } return result; }
From source file:com.bbva.arq.devops.ae.mirrorgate.jenkins.plugin.service.DefaultMirrorGateServiceTest.java
@Test public void testSuccessfulPublishBuildDataTest() throws IOException { when(htppClient.executeMethod(any(PostMethod.class))).thenReturn(HttpStatus.SC_OK); MirrorGateResponse response = service.publishBuildData(makeBuildRequest()); assertEquals(HttpStatus.SC_OK, response.getResponseCode()); }
From source file:eu.flatworld.worldexplorer.layer.nltl7.NLTL7HTTPProvider.java
@Override public void run() { while (true) { while (getQueueSize() != 0) { Tile tile = peekTile();/*from ww w .jav a 2 s . c om*/ synchronized (tile) { String s = String.format(NLTL7Layer.HTTP_BASE, tile.getL(), tile.getX(), tile.getY()); LogX.log(Level.FINER, s); GetMethod gm = new GetMethod(s); gm.setRequestHeader("User-Agent", WorldExplorer.USER_AGENT); try { int response = client.executeMethod(gm); LogX.log(Level.FINEST, NAME + " " + response + " " + s); if (response == HttpStatus.SC_OK) { InputStream is = gm.getResponseBodyAsStream(); BufferedImage bi = ImageIO.read(is); is.close(); if (bi != null) { tile.setImage(bi); } } } catch (Exception ex) { LogX.log(Level.FINER, "", ex); } finally { gm.releaseConnection(); } LogX.log(Level.FINEST, NAME + " dequeueing: " + tile); unqueueTile(tile); } firePropertyChange(P_DATAREADY, null, tile); Thread.yield(); } firePropertyChange(P_IDLE, false, true); try { Thread.sleep(QUEUE_SLEEP_TIME); } catch (Exception ex) { } ; } }
From source file:com.owncloud.android.operations.ExistenceCheckOperation.java
@Override protected RemoteOperationResult run(WebdavClient client) { if (!isOnline()) { return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); }/*from ww w.j a v a2s. c o m*/ RemoteOperationResult result = null; HeadMethod head = null; try { head = new HeadMethod(client.getBaseUri() + WebdavUtils.encodePath(mPath)); int status = client.executeMethod(head, TIMEOUT, TIMEOUT); client.exhaustResponse(head.getResponseBodyAsStream()); boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent); result = new RemoteOperationResult(success, status, head.getResponseHeaders()); Log_OC.d(TAG, "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success ? "(FAIL)" : "")); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException()); } finally { if (head != null) head.releaseConnection(); } return result; }
From source file:de.softwareforge.pgpsigner.util.HKPSender.java
public boolean uploadKey(final byte[] armoredKey) { PostMethod post = new PostMethod(UPLOAD_URL); try {/*from w w w. ja v a 2 s . c om*/ NameValuePair keyText = new NameValuePair("keytext", new String(armoredKey, "ISO-8859-1")); post.setRequestBody(new NameValuePair[] { keyText }); post.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); int statusCode = httpClient.executeMethod(post); if (statusCode != HttpStatus.SC_OK) { return false; } InputStream responseStream = post.getResponseBodyAsStream(); InputStreamReader isr = null; BufferedReader br = null; StringBuffer response = new StringBuffer(); try { isr = new InputStreamReader(responseStream); br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { response.append(line); } } finally { IOUtils.closeQuietly(br); IOUtils.closeQuietly(isr); IOUtils.closeQuietly(responseStream); } } catch (RuntimeException re) { throw re; } catch (Exception e) { return false; } finally { post.releaseConnection(); } return true; }
From source file:es.carebear.rightmanagement.client.user.AddAllowedUserId.java
public void AddUser(String authName, String target, String rigthTarget, String rightMask) throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/allowed/" + target); postMethod.addParameter("authName", authName); postMethod.addParameter("rigthTarget", rigthTarget); postMethod.addParameter("rightMask", rightMask); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_OK: break;/* ww w .ja v a 2s . co m*/ case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); case HttpStatus.SC_FORBIDDEN: throw new ForbiddenException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:com.endpoint.lg.director.bridge.MasterApi.java
private StandardJsonNavigator sendRequest(String path) { String url = masterUrl + "/" + path; log.info("Hitting url: " + url); GetMethod method = new GetMethod(url); StandardJsonNavigator responseJson = null; try {//ww w . jav a 2s . c om // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. String responseBody = new String(method.getResponseBody()); log.info(responseBody); responseJson = new StandardJsonNavigator(jsonMapper.parseObject(responseBody)); } 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(); } finally { // Release the connection. method.releaseConnection(); } return responseJson; }