List of usage examples for java.net HttpURLConnection HTTP_ACCEPTED
int HTTP_ACCEPTED
To view the source code for java.net HttpURLConnection HTTP_ACCEPTED.
Click Source Link
From source file:org.apache.maven.wagon.providers.http.LightweightHttpWagon.java
protected void finishPutTransfer(Resource resource, InputStream input, OutputStream output) throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException { try {/* www . j a v a2s. c o m*/ int statusCode = putConnection.getResponseCode(); switch (statusCode) { // Success Codes case HttpURLConnection.HTTP_OK: // 200 case HttpURLConnection.HTTP_CREATED: // 201 case HttpURLConnection.HTTP_ACCEPTED: // 202 case HttpURLConnection.HTTP_NO_CONTENT: // 204 break; case HttpURLConnection.HTTP_FORBIDDEN: throw new AuthorizationException("Access denied to: " + buildUrl(resource.getName())); case HttpURLConnection.HTTP_NOT_FOUND: throw new ResourceDoesNotExistException( "File: " + buildUrl(resource.getName()) + " does not exist"); // add more entries here default: throw new TransferFailedException("Failed to transfer file: " + buildUrl(resource.getName()) + ". Return code is: " + statusCode); } } catch (IOException e) { fireTransferError(resource, e, TransferEvent.REQUEST_PUT); throw new TransferFailedException("Error transferring file: " + e.getMessage(), e); } }
From source file:de.ub0r.android.websms.connector.gmx.ConnectorGMX.java
@Override protected void parseResponseCode(final Context context, final HttpResponse response) { final int resp = response.getStatusLine().getStatusCode(); switch (resp) { case HttpURLConnection.HTTP_OK: return;/*from w w w . j av a2 s . com*/ case HttpURLConnection.HTTP_ACCEPTED: return; case HttpURLConnection.HTTP_FORBIDDEN: throw new WebSMSException(context, R.string.error_pw); default: super.parseResponseCode(context, response); break; } }
From source file:com.flurry.proguard.UploadProGuardMapping.java
/** * Upload the archive to Flurry/*www. jav a2 s . c om*/ * * @param file the archive to send * @param projectId the project's id * @param uploadId the the upload's id * @param token the Flurry auth token */ private static void sendToUploadService(File file, String projectId, String uploadId, String token) { String uploadServiceUrl = String.format("%s/upload/%s/%s", UPLOAD_BASE, projectId, uploadId); List<Header> requestHeaders = getUploadServiceHeaders(file.length(), token); HttpPost postRequest = new HttpPost(uploadServiceUrl); postRequest.setEntity(new FileEntity(file)); HttpResponse response = executeHttpRequest(postRequest, requestHeaders); expectStatus(response, HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED); }
From source file:it.geosolutions.figis.requester.HTTPUtils.java
/** * Send an HTTP request (PUT or POST) to a server. * <BR>Basic auth is used if both username and pw are not null. * <P>//from ww w .j a va 2 s .c o m * Only <UL> * <LI>200: OK</LI> * <LI>201: ACCEPTED</LI> * <LI>202: CREATED</LI> * </UL> are accepted as successful codes; in these cases the response string will be returned. * * @return the HTTP response or <TT>null</TT> on errors. */ private static String send(final EntityEnclosingMethod httpMethod, String url, RequestEntity requestEntity, String username, String pw) { try { HttpClient client = new HttpClient(); setAuth(client, url, username, pw); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); if (requestEntity != null) { httpMethod.setRequestEntity(requestEntity); } int status = client.executeMethod(httpMethod); switch (status) { case HttpURLConnection.HTTP_OK: case HttpURLConnection.HTTP_CREATED: case HttpURLConnection.HTTP_ACCEPTED: String response = IOUtils.toString(httpMethod.getResponseBodyAsStream()); if (LOGGER.isInfoEnabled()) { LOGGER.info("HTTP " + httpMethod.getStatusText() + ": " + response); } return response; default: LOGGER.warn("Bad response: code[" + status + "]" + " msg[" + httpMethod.getStatusText() + "]" + " url[" + url + "]" + " method[" + httpMethod.getClass().getSimpleName() + "]: " + IOUtils.toString(httpMethod.getResponseBodyAsStream())); return null; } } catch (ConnectException e) { LOGGER.error("Couldn't connect to [" + url + "]", e); return null; } catch (IOException e) { LOGGER.error("Error talking to " + url + " : " + e.getLocalizedMessage(), e); return null; } finally { if (httpMethod != null) { httpMethod.releaseConnection(); } } }
From source file:com.flurry.proguard.UploadMapping.java
/** * Upload the archive to Flurry//from w w w . java 2s. co m * * @param file the archive to send * @param projectId the project's id * @param uploadId the the upload's id * @param token the Flurry auth token */ private static void sendToUploadService(File file, String projectId, String uploadId, String token) throws IOException { String uploadServiceUrl = String.format("%s/upload/%s/%s", UPLOAD_BASE, projectId, uploadId); List<Header> requestHeaders = getUploadServiceHeaders(file.length(), token); HttpPost postRequest = new HttpPost(uploadServiceUrl); postRequest.setEntity(new FileEntity(file)); try (CloseableHttpResponse response = executeHttpRequest(postRequest, requestHeaders)) { expectStatus(response, HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED); } finally { postRequest.releaseConnection(); } }
From source file:it.geosolutions.geoserver.rest.HTTPUtils.java
/** * Send an HTTP request (PUT or POST) to a server. <BR> * Basic auth is used if both username and pw are not null. * <P>/*from w w w. ja v a2 s . c o m*/ * Only * <UL> * <LI>200: OK</LI> * <LI>201: ACCEPTED</LI> * <LI>202: CREATED</LI> * </UL> * are accepted as successful codes; in these cases the response string will * be returned. * * @return the HTTP response or <TT>null</TT> on errors. */ private static String send(final EntityEnclosingMethod httpMethod, String url, RequestEntity requestEntity, String username, String pw) { HttpClient client = new HttpClient(); HttpConnectionManager connectionManager = client.getHttpConnectionManager(); try { setAuth(client, url, username, pw); connectionManager.getParams().setConnectionTimeout(5000); if (requestEntity != null) httpMethod.setRequestEntity(requestEntity); int status = client.executeMethod(httpMethod); switch (status) { case HttpURLConnection.HTTP_OK: case HttpURLConnection.HTTP_CREATED: case HttpURLConnection.HTTP_ACCEPTED: String response = IOUtils.toString(httpMethod.getResponseBodyAsStream()); // LOGGER.info("================= POST " + url); if (LOGGER.isInfoEnabled()) LOGGER.info("HTTP " + httpMethod.getStatusText() + ": " + response); return response; default: LOGGER.warn("Bad response: code[" + status + "]" + " msg[" + httpMethod.getStatusText() + "]" + " url[" + url + "]" + " method[" + httpMethod.getClass().getSimpleName() + "]: " + IOUtils.toString(httpMethod.getResponseBodyAsStream())); return null; } } catch (ConnectException e) { LOGGER.info("Couldn't connect to [" + url + "]"); return null; } catch (IOException e) { LOGGER.error("Error talking to " + url + " : " + e.getLocalizedMessage()); return null; } finally { if (httpMethod != null) httpMethod.releaseConnection(); connectionManager.closeIdleConnections(0); } }
From source file:org.geosdi.geoplatform.publish.HttpUtilsLocal.java
/** * Send an HTTP request (PUT or POST) to a server. * <BR>Basic auth is used if both username and pw are not null. * <P>/*from w ww .ja v a 2 s . c o m*/ * Only <UL> * <LI>200: OK</LI> * <LI>201: ACCEPTED</LI> * <LI>202: CREATED</LI> * </UL> are accepted as successful codes; in these cases the response string will be returned. * * @return the HTTP response or <TT>null</TT> on errors. */ private static String send(final EntityEnclosingMethod httpMethod, String url, RequestEntity requestEntity, String username, String pw) { try { HttpClient client = new HttpClient(); setAuth(client, url, username, pw); // httpMethod = new PutMethod(url); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); if (requestEntity != null) { httpMethod.setRequestEntity(requestEntity); } int status = client.executeMethod(httpMethod); switch (status) { case HttpURLConnection.HTTP_OK: case HttpURLConnection.HTTP_CREATED: case HttpURLConnection.HTTP_ACCEPTED: String response = IOUtils.toString(httpMethod.getResponseBodyAsStream()); // LOGGER.info("================= POST " + url); LOGGER.info("HTTP " + httpMethod.getStatusText() + ": " + response); return response; default: LOGGER.warn("Bad response: code[" + status + "]" + " msg[" + httpMethod.getStatusText() + "]" + " url[" + url + "]" + " method[" + httpMethod.getClass().getSimpleName() + "]: " + IOUtils.toString(httpMethod.getResponseBodyAsStream())); return null; } } catch (ConnectException e) { LOGGER.info("Couldn't connect to [" + url + "]"); return null; } catch (IOException e) { LOGGER.error("Error talking to " + url + " : " + e.getLocalizedMessage()); return null; } finally { if (httpMethod != null) { httpMethod.releaseConnection(); } } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitTest.java
protected ServerStatus waitForTask(WebResponse response, String userName, String userPassword) throws JSONException, IOException, SAXException { if (response.getResponseCode() == HttpURLConnection.HTTP_ACCEPTED) { String text = response.getText(); JSONObject taskDescription = new JSONObject(text); String location = taskDescription.getString(ProtocolConstants.KEY_LOCATION); JSONObject taskResponse = waitForTaskCompletionObject(location, userName, userPassword); ServerStatus status = ServerStatus.fromJSON(taskResponse.getString("Result")); return status; }/*from ww w.j a va 2 s .c o m*/ try { return ServerStatus.fromJSON(response.getText()); } catch (Exception e) { JSONObject jsonData = null; try { jsonData = new JSONObject(response.getText()); } catch (Exception e1) { //ignore } return new ServerStatus( response.getResponseCode() == HttpURLConnection.HTTP_OK ? IStatus.OK : IStatus.ERROR, response.getResponseCode(), response.getText(), jsonData, null); } }
From source file:it.geosolutions.geonetwork.util.HTTPUtils.java
/** * Send an HTTP request (PUT or POST) to a server. * <BR>Basic auth is used if both username and pw are not null. * <P>/*ww w .j av a2s .c o m*/ * Only <UL> * <LI>200: OK</LI> * <LI>201: ACCEPTED</LI> * <LI>202: CREATED</LI> * </UL> are accepted as successful codes; in these cases the response string will be returned. * * @return the HTTP response or <TT>null</TT> on errors. */ protected String send(final EntityEnclosingMethod httpMethod, String url, RequestEntity requestEntity) { try { setAuth(client, url, username, pw); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); if (requestEntity != null) httpMethod.setRequestEntity(requestEntity); lastHttpStatus = client.executeMethod(httpMethod); switch (lastHttpStatus) { case HttpURLConnection.HTTP_OK: case HttpURLConnection.HTTP_CREATED: case HttpURLConnection.HTTP_ACCEPTED: if (LOGGER.isDebugEnabled()) LOGGER.debug("HTTP " + httpMethod.getStatusText() + " <-- " + url); if (ignoreResponseContentOnSuccess) return ""; String response = IOUtils.toString(httpMethod.getResponseBodyAsStream()); return response; default: String badresponse = IOUtils.toString(httpMethod.getResponseBodyAsStream()); String message = getGeoNetworkErrorMessage(badresponse); LOGGER.warn("Bad response: " + lastHttpStatus + " " + httpMethod.getStatusText() + " -- " + httpMethod.getName() + " " + url + " : " + message); if (LOGGER.isDebugEnabled()) LOGGER.debug("GeoNetwork response:\n" + badresponse); return null; } } catch (ConnectException e) { LOGGER.info("Couldn't connect to [" + url + "]"); return null; } catch (IOException e) { LOGGER.error("Error talking to " + url + " : " + e.getLocalizedMessage()); return null; } finally { if (httpMethod != null) httpMethod.releaseConnection(); } }
From source file:org.eclipse.mylyn.internal.gerrit.core.client.GerritHttpClient.java
public <T> T execute(Request<T> request, boolean authenticateIfNeeded, IProgressMonitor monitor) throws IOException, GerritException { String openIdProvider = getOpenIdProvider(); hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor); for (int attempt = 0; attempt < 2; attempt++) { if (authenticateIfNeeded) { // force authentication if (needsAuthentication()) { AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY); if (openIdProvider != null || credentials != null) { authenticate(openIdProvider, monitor); }/*from ww w .java 2 s .c o m*/ } if (!obtainedXsrfKey) { updateXsrfKey(monitor); } } HttpMethodBase method = request.createMethod(); if (obtainedXsrfKey) { // required to authenticate against Gerrit 2.6+ REST endpoints // harmless in previous versions method.setRequestHeader(X_GERRIT_AUTHORITY, xsrfKey); } try { // Execute the method. WebUtil.execute(httpClient, hostConfiguration, method, monitor); } catch (IOException e) { WebUtil.releaseConnection(method, monitor); throw e; } catch (RuntimeException e) { WebUtil.releaseConnection(method, monitor); throw e; } int code = method.getStatusCode(); if (code == HttpURLConnection.HTTP_OK || code == HttpURLConnection.HTTP_ACCEPTED || code == HttpURLConnection.HTTP_CREATED) { try { return request.process(method); } finally { WebUtil.releaseConnection(method, monitor); } } else if (code == HttpURLConnection.HTTP_NO_CONTENT) { try { return null; } finally { WebUtil.releaseConnection(method, monitor); } } else { try { request.handleError(method); } finally { WebUtil.releaseConnection(method, monitor); } if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) { // login or re-authenticate due to an expired session authenticate(openIdProvider, monitor); } else { throw new GerritHttpException(code); } } } throw new GerritLoginException(); }