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:au.edu.usq.fascinator.harvester.fedora.restclient.FedoraRestClient.java
public ResultType findObjects(FindObjectsType type, String queryOrTermsOrToken, int maxResults, String[] fields) throws IOException { ResultType result = null;/*from w ww. j a v a2s. c om*/ try { StringBuilder uri = new StringBuilder(getBaseUrl()); uri.append("/search?"); uri.append(type); uri.append("="); uri.append(URLEncoder.encode(queryOrTermsOrToken, "UTF-8")); if (!type.equals(FindObjectsType.SESSION_TOKEN) && maxResults != -1) { uri.append("&maxResults="); uri.append(maxResults); } uri.append("&xml=true&pid=true"); if (fields != null) { for (String field : fields) { uri.append("&"); uri.append(field); uri.append("=true"); } } log.info("***** URI: " + uri.toString()); GetMethod method = new GetMethod(uri.toString()); int status = executeMethod(method); if (status == HttpStatus.SC_OK) { JAXBContext jc = JAXBContext.newInstance(ResultType.class); Unmarshaller um = jc.createUnmarshaller(); InputStream in = method.getResponseBodyAsStream(); result = (ResultType) um.unmarshal(in); in.close(); } method.releaseConnection(); } catch (JAXBException jaxbe) { log.error("Failed parsing result", jaxbe); } return result; }
From source file:com.zimbra.cs.store.triton.TritonIncomingOutputStream.java
private void sendHttpData() throws IOException { HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); PostMethod post;/*from w w w .j a v a2s .c o m*/ boolean started = false; if (uploadUrl.isInitialized()) { started = true; post = new PostMethod(baseUrl + uploadUrl); } else { post = new PostMethod(baseUrl + "/blob"); } try { ZimbraLog.store.info("posting to %s", post.getURI()); HttpClientUtil.addInputStreamToHttpMethod(post, new ByteArrayInputStream(baos.toByteArray()), baos.size(), "application/octet-stream"); post.addRequestHeader(TritonHeaders.CONTENT_LENGTH, baos.size() + ""); post.addRequestHeader(TritonHeaders.HASH_TYPE, hashType.toString()); post.addRequestHeader("Content-Range", "bytes " + written.longValue() + "-" + (written.longValue() + baos.size() - 1) + "/*"); if (serverToken.getToken() != null) { post.addRequestHeader(TritonHeaders.SERVER_TOKEN, serverToken.getToken()); } int statusCode = HttpClientUtil.executeMethod(client, post); if (statusCode == HttpStatus.SC_OK) { handleResponse(post); } else if (!started && statusCode == HttpStatus.SC_SEE_OTHER) { started = true; uploadUrl.setUploadUrl(post.getResponseHeader(TritonHeaders.LOCATION).getValue()); handleResponse(post); } else { throw new IOException("Unable to append, bad response code " + statusCode); } } finally { post.releaseConnection(); } baos = new ByteArrayOutputStream(LC.triton_upload_buffer_size.intValue()); }
From source file:net.sf.sail.webapp.dao.sds.impl.HttpRestSdsOfferingDaoTest.java
/** * Test method for//from w w w .j a v a 2 s . c om * {@link net.sf.sail.webapp.dao.sds.impl.HttpRestSdsOfferingDao#getList()}. */ @SuppressWarnings("unchecked") @Test //Comment out this test by adding @Ignore if it takes too long for you (only works in junit4) @Ignore public void testGetList() throws Exception { // To test, we will retrieve the offering list through 2 methods, via // DAO and httpunit. Compare the lists and make sure that they're // equivalent. // *Note* there is a small chance that between the 2 retrievals, a new // offering may be inserted into the SDS and cause this test to break. // *Note that I (LAW) haven't bothered to check the curnitmaps for this // test, // although they are retrieved by getList. GetById is probably // sufficient. List<SdsOffering> actualSet = new ArrayList(); try { actualSet = this.sdsOfferingDao.getList(); } catch (CurnitMapNotFoundException e) { System.out.println("CurnitMapNotFoundException caught and ignored"); fail("decided to fail now rather than later"); } WebResponse webResponse = makeHttpRestGetRequest("/offering"); assertEquals(HttpStatus.SC_OK, webResponse.getResponseCode()); Document doc = createDocumentFromResponse(webResponse); List<Element> nodeList = XPath.newInstance("/offerings/offering/id").selectNodes(doc); assertEquals(nodeList.size(), actualSet.size()); List<Integer> offeringIdList = new ArrayList<Integer>(nodeList.size()); for (Element element : nodeList) { offeringIdList.add(new Integer(element.getText())); } assertEquals(offeringIdList.size(), actualSet.size()); for (SdsOffering offering : actualSet) { offeringIdList.contains(offering.getSdsObjectId()); } }
From source file:it.unibz.instasearch.jobs.CheckUpdatesJob.java
private boolean checkForUpdates(IProgressMonitor monitor) throws HttpException, IOException, URISyntaxException { updateAvailable = false;//from w w w.j a va 2 s .c o m String versionCheckUrl = InstaSearchPlugin.getUpdateLocation(); String v = InstaSearchPlugin.getVersion(); HttpClient httpClient = new HttpClient(); configureProxy(httpClient, versionCheckUrl); GetMethod getMethod = new GetMethod(versionCheckUrl + "?v=" + v); int statusCode = httpClient.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) return updateAvailable; String response = getMethod.getResponseBodyAsString(); getMethod.releaseConnection(); if ("y".equals(response)) updateAvailable = true; return updateAvailable; }
From source file:com.apatar.flickr.function.UploadPhotoFlickrTable.java
public List<KeyInsensitiveMap> execute(FlickrNode node, Hashtable<String, Object> values, String strApi, String strSecret) throws IOException, XmlRpcException { byte[] photo = (byte[]) values.get("photo"); int size = values.size() + 2; values.remove("photo"); File newFile = ApplicationData.createFile("flicr", photo); PostMethod post = new PostMethod("http://api.flickr.com/services/upload"); Part[] parts = new Part[size]; parts[0] = new FilePart("photo", newFile); parts[1] = new StringPart("api_key", strApi); int i = 2;/*from ww w . j ava 2 s . c o m*/ for (String key : values.keySet()) parts[i++] = new StringPart(key, values.get(key).toString()); values.put("api_key", strApi); parts[i] = new StringPart("api_sig", FlickrUtils.Sign(values, strApi, strSecret)); post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(post); if (status != HttpStatus.SC_OK) { JOptionPane.showMessageDialog(ApatarUiMain.MAIN_FRAME, "Upload failed, response=" + HttpStatus.getStatusText(status)); return null; } else { InputStream is = post.getResponseBodyAsStream(); try { return createKeyInsensitiveMapFromElement(FlickrUtils.getRootElementFromInputStream(is)); } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:com.zimbra.cs.store.http.HttpStoreManager.java
@Override public boolean deleteFromStore(String locator, Mailbox mbox) throws IOException { HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); DeleteMethod delete = new DeleteMethod(getDeleteUrl(mbox, locator)); try {/* w ww .jav a2 s. c om*/ int statusCode = HttpClientUtil.executeMethod(client, delete); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NO_CONTENT) { return true; } else if (statusCode == HttpStatus.SC_NOT_FOUND) { return false; } else { throw new IOException("unexpected return code during blob DELETE: " + delete.getStatusText()); } } finally { delete.releaseConnection(); } }
From source file:com.braindrainpain.docker.DockerRegistry.java
/** * Checks the connection to the registry */// ww w .j av a2 s . c o m public void checkConnection() { LOG.debug("Checking: '" + url + "'"); HttpClient client = getHttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(false); try { int returnCode = client.executeMethod(method); if (returnCode != HttpStatus.SC_OK) { LOG.error("Not ok from: '" + url + "'"); throw new RuntimeException("Not ok from: '" + url + "'"); } } catch (IOException e) { LOG.error("Error connecting to: '" + url + "'"); throw new RuntimeException("Error connecting to: '" + url + "'"); } }
From source file:com.thoughtworks.go.server.service.PipelinePauseServiceTest.java
@Test public void shouldPausePipeline() throws Exception { setUpValidPipelineWithAuth();//from w w w .j a v a2s .c o m HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); pipelinePauseService.pause(VALID_PIPELINE, "cause", VALID_USER, result); verify(pipelineDao).pause(VALID_PIPELINE, "cause", VALID_USER.getUsername().toString()); assertThat(result.isSuccessful(), is(true)); assertThat(result.httpCode(), is(HttpStatus.SC_OK)); }
From source file:function.GettingPhotos.java
public String getUserId(String username) throws IOException, JSONException { setRequest(getData().getRequestMethod() + getData().getMethodFindByUsername() + "&api_key=" + getData().getKey() + "&username=" + username + "&format=json"); System.out.println("GET userid request: " + getRequest()); setMethod(new GetMethod(getRequest())); setStatusCode(getClient().executeMethod(getMethod())); if (getStatusCode() != HttpStatus.SC_OK) { System.err.println("Method failed: " + getMethod().getStatusLine()); }/*w ww .j ava2 s . c o m*/ setRstream(null); setRstream(getMethod().getResponseBodyAsStream()); String jstr = toString(getRstream()); jstr = jstr.substring("jsonFlickrApi(".length(), jstr.length() - 1); JSONObject jobj = new JSONObject(jstr); JSONObject user = jobj.getJSONObject("user"); return (String) user.get("id"); }
From source file:it.eng.spagobi.engines.talend.client.SpagoBITalendEngineClient.java
public static String getEngineComplianceVersion(String url) throws EngineUnavailableException, ServiceInvocationFailedException { String version;//ww w.j a v a2 s .c o m HttpClient client; PostMethod method; NameValuePair[] nameValuePairs; version = null; client = new HttpClient(); method = new PostMethod(url); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); nameValuePairs = new NameValuePair[] { new NameValuePair("infoType", "complianceVersion") }; //$NON-NLS-1$ //$NON-NLS-2$ method.setRequestBody(nameValuePairs); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { throw new ServiceInvocationFailedException( Messages.getString("SpagoBITalendEngineClient.serviceFailed"), //$NON-NLS-1$ method.getStatusLine().toString(), method.getResponseBodyAsString()); } else { version = method.getResponseBodyAsString(); } } catch (HttpException e) { throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient.5", e.getMessage())); //$NON-NLS-1$ } catch (IOException e) { throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient.6", e.getMessage())); //$NON-NLS-1$ } finally { // Release the connection. method.releaseConnection(); } return version; }