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.npower.dm.msm.tools.PackageCheckerImpl.java
public PackageMetaInfo getPackageMetaInfo(String url) throws DMException { HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); PackageMetaInfo metaInfo = new PackageMetaInfo(); metaInfo.setUrl(url);/*from w ww. j av a2s .c o m*/ try { // Execute the method. int statusCode = client.executeMethod(method); metaInfo.setServerStatus(statusCode); if (statusCode != HttpStatus.SC_OK) { // System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); Header mimeType = method.getResponseHeader("Content-Type"); if (mimeType != null) { metaInfo.setMimeType(mimeType.getValue()); } Header contentLength = method.getResponseHeader("Content-Length"); if (contentLength != null && StringUtils.isNotEmpty(contentLength.getValue())) { metaInfo.setSize(Integer.parseInt(contentLength.getValue())); } } catch (HttpException e) { metaInfo.setErrorMessage(e.getMessage()); } catch (IOException e) { metaInfo.setErrorMessage(e.getMessage()); } finally { // Release the connection. method.releaseConnection(); } return metaInfo; }
From source file:com.owncloud.android.lib.resources.users.StorePrivateKeyOperation.java
/** * @param client Client object//w w w . ja va 2s . c o m */ @Override protected RemoteOperationResult run(OwnCloudClient client) { PostMethod postMethod = null; RemoteOperationResult result; try { // remote request postMethod = new PostMethod(client.getBaseUri() + PRIVATE_KEY_URL + JSON_FORMAT); postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); postMethod.setParameter(PRIVATE_KEY, privateKey); 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 key = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA) .get(NODE_PRIVATE_KEY); result = new RemoteOperationResult(true, postMethod); ArrayList<Object> keys = new ArrayList<>(); keys.add(key); result.setData(keys); } else { result = new RemoteOperationResult(false, postMethod); client.exhaustResponse(postMethod.getResponseBodyAsStream()); } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Storing private key failed: " + result.getLogMessage(), result.getException()); } finally { if (postMethod != null) postMethod.releaseConnection(); } return result; }
From source file:davmail.exchange.TestExchangePropfindMethod.java
public void testGetFolder() throws IOException, DavException { ExchangeSession.Folder folder = session.getFolder("INBOX"); assertNotNull(folder);//w w w . j a va2s. com DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet(); // davPropertyNameSet.add(Field.getPropertyName("displayname")); //PropFindMethod propFindMethod = new PropFindMethod(URIUtil.encodePath(((DavExchangeSession)session).getFolderPath(folder.folderPath))); //session.httpClient.executeMethod(propFindMethod); //propFindMethod.getResponseBodyAsMultiStatus(); ExchangePropFindMethod exchangePropFindMethod = new ExchangePropFindMethod( URIUtil.encodePath(((DavExchangeSession) session).getFolderPath(folder.folderPath)), davPropertyNameSet, 0); //PropFindMethod propFindMethod = new PropFindMethod(URIUtil.encodePath(((DavExchangeSession)session).getFolderPath(folder.folderPath))); session.httpClient.executeMethod(exchangePropFindMethod); MultiStatusResponse response = exchangePropFindMethod.getResponse(); DavPropertySet properties = response.getProperties(HttpStatus.SC_OK); System.out.println(properties); }
From source file:eu.flatworld.worldexplorer.layer.bmng.BMNGHTTPProvider.java
@Override public void run() { while (true) { while (getQueueSize() != 0) { Tile tile = peekTile();/* www . j ava2s . c o m*/ synchronized (tile) { String s = String.format(BMNGLayer.HTTP_BASE, year, month, 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.utils.glide.HttpStreamFetcher.java
@Override public InputStream loadData(Priority priority) throws Exception { Account mAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext()); OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, MainApp.getAppContext()); OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, MainApp.getAppContext());//from w ww . ja v a 2s .com OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount); if (mClient != null && serverOCVersion != null) { if (serverOCVersion.supportsRemoteThumbnails()) { GetMethod get = null; try { get = new GetMethod(mURL); get.setRequestHeader("Cookie", "nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true"); get.setRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE); int status = mClient.executeMethod(get); if (status == HttpStatus.SC_OK) { return get.getResponseBodyAsStream(); } else { mClient.exhaustResponse(get.getResponseBodyAsStream()); } } catch (Exception e) { Log_OC.d(TAG, e.getMessage(), e); } } else { Log_OC.d(TAG, "Server too old"); } } return null; }
From source file:com.sdm.core.resource.RestResource.java
@Override public IBaseResponse getNamedQueries() { DefaultResponse response = this.validateCache(); // Cache validation if (response != null) { return response; }//from w w w . j ava2 s. co m try { T instance = getEntityClass().newInstance(); response = new DefaultResponse<>(instance.getQueries()); response.setCode(HttpStatus.SC_OK); response.setStatus(ResponseType.SUCCESS); // Set Cache Header Info response.setHeaders(this.buildCache()); return response; } catch (InstantiationException | IllegalAccessException e) { throw new WebApplicationException(e.getLocalizedMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.zimbra.cs.index.ElasticSearchIndexTest.java
@Override protected void cleanupForIndexStore() { String key = testAcct.getId(); String indexUrl = String.format("%s%s/", LC.zimbra_index_elasticsearch_url_base.value(), key); HttpMethod method = new DeleteMethod(indexUrl); try {/*from w ww.ja v a 2 s.c o m*/ ElasticSearchConnector connector = new ElasticSearchConnector(); int statusCode = connector.executeMethod(method); if (statusCode == HttpStatus.SC_OK) { boolean ok = connector.getBooleanAtJsonPath(new String[] { "ok" }, false); boolean acknowledged = connector.getBooleanAtJsonPath(new String[] { "acknowledged" }, false); if (!ok || !acknowledged) { ZimbraLog.index.debug("Delete index status ok=%b acknowledged=%b", ok, acknowledged); } } else { String error = connector.getStringAtJsonPath(new String[] { "error" }); if (error != null && error.startsWith("IndexMissingException")) { ZimbraLog.index.debug("Unable to delete index for key=%s. Index is missing", key); } else { ZimbraLog.index.error("Problem deleting index for key=%s error=%s", key, error); } } } catch (HttpException e) { ZimbraLog.index.error("Problem Deleting index with key=" + key, e); } catch (IOException e) { ZimbraLog.index.error("Problem Deleting index with key=" + key, e); } }
From source file:com.htmlhifive.tools.jslint.engine.download.AbstractDownloadEngineSupport.java
@Override public EngineInfo getEngineInfo(IProgressMonitor monitor) throws IOException { IProgressMonitor actualMonitor = monitor; if (monitor == null) { actualMonitor = new NullProgressMonitor(); }/*from ww w. j av a 2 s . c o m*/ actualMonitor.setTaskName(Messages.T0009.getText()); HttpClient client = createHttpClient(getEngineSourceUrl()); HttpMethod getMethod = new GetMethod(getEngineSourceUrl()); int result = client.executeMethod(getMethod); if (result != HttpStatus.SC_OK) { // TODO return null; } StringBuilder licenseSb = new StringBuilder(); StringBuilder rawSource = new StringBuilder(); Header header = getMethod.getResponseHeader("Content-Length"); int content = Integer.valueOf(header.getValue()); actualMonitor.beginTask(Messages.T0010.getText(), content); BufferedReader reader = new BufferedReader(new InputStreamReader(getMethod.getResponseBodyAsStream())); String temp = reader.readLine(); int progress = 0; while (!isEndLicenseLine(temp)) { progress += temp.length(); actualMonitor.subTask(Messages.T0011.format(progress, content)); actualMonitor.worked(temp.length()); rawSource.append(temp); temp = StringUtils.trim(temp); temp = StringUtils.substring(temp, 2); temp = StringUtils.trim(temp); licenseSb.append(temp); licenseSb.append(System.getProperty("line.separator")); rawSource.append(System.getProperty("line.separator")); temp = reader.readLine(); } EngineInfo info = new EngineInfo(); info.setLicenseStr(licenseSb.toString()); while ((temp = reader.readLine()) != null) { progress += temp.length(); actualMonitor.subTask(Messages.T0011.format(progress, content)); actualMonitor.worked(temp.length()); rawSource.append(temp); rawSource.append(System.getProperty("line.separator")); } info.setMainSource(rawSource.toString()); monitor.done(); return info; }
From source file:com.zimbra.cs.store.http.HttpStoreManager.java
@Override public String writeStreamToStore(InputStream in, long actualSize, Mailbox mbox) throws IOException, ServiceException { MessageDigest digest;/*from w w w. j a v a 2s . c o m*/ try { digest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw ServiceException.FAILURE("SHA-256 digest not found", e); } ByteUtil.PositionInputStream pin = new ByteUtil.PositionInputStream(new DigestInputStream(in, digest)); HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); PostMethod post = new PostMethod(getPostUrl(mbox)); try { HttpClientUtil.addInputStreamToHttpMethod(post, pin, actualSize, "application/octet-stream"); int statusCode = HttpClientUtil.executeMethod(client, post); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED || statusCode == HttpStatus.SC_NO_CONTENT) { return getLocator(post, ByteUtil.encodeFSSafeBase64(digest.digest()), pin.getPosition(), mbox); } else { throw ServiceException.FAILURE("error POSTing blob: " + post.getStatusText(), null); } } finally { post.releaseConnection(); } }
From source file:com.wafersystems.util.HttpUtil.java
/** * ??//from w w w . java 2s.c o m * * @param ip IP? * @param port ?? * @param hClient HttpClient * @param method HttpMethod * @param lastResult * * @return */ public static int checkRedirect(String ip, int port, HttpClient hClient, HttpMethod method, int lastResult) throws Exception { int result = HttpStatus.SC_OK; if ((lastResult == HttpStatus.SC_MOVED_TEMPORARILY) || (lastResult == HttpStatus.SC_MOVED_PERMANENTLY) || (lastResult == HttpStatus.SC_SEE_OTHER) || (lastResult == HttpStatus.SC_TEMPORARY_REDIRECT)) { //????URL? Header header = method.getResponseHeader("location"); if (header != null) { String newURI = header.getValue(); if (StrUtil.isEmptyStr(newURI)) newURI = "http://" + ip + ":" + port + "/"; //URL??IP?? if (!newURI.startsWith("http")) newURI = "http://" + ip + ":" + port + newURI; logger.warn("??" + newURI); method = new GetMethod(newURI); result = hClient.executeMethod(method); } } return result; }