/** * Get the HTTP response code from the request. * <p> * Roughly the same as <code>c.getResponseCode()</code> but the * ConnectException is translated to be more understandable. * * @param c * connection the code should be obtained from. * @return r HTTP status code, usually 200 to indicate success. See * {@link org.eclipse.jgit.transport.http.HttpConnection} for other * defined constants. * @throws java.io.IOException * communications error prevented obtaining the response code. * @since 3.3 */ public static int response(HttpConnection c) throws IOException { try { return c.getResponseCode(); } catch (ConnectException ce) { final URL url = c.getURL(); final String host = (url == null) ? "<null>" : url.getHost(); //$NON-NLS-1$ // The standard J2SE error message is not very useful. // if ("Connection timed out: connect".equals(ce.getMessage())) //$NON-NLS-1$ throw new ConnectException(MessageFormat.format(JGitText.get().connectionTimeOut, host)); throw new ConnectException(ce.getMessage() + " " + host); //$NON-NLS-1$ } }
private Map<String, LfsPointer> requestBatchUpload(HttpConnection api, Set<LfsPointer> toPush) throws IOException { LfsPointer[] res = toPush.toArray(new LfsPointer[0]); Map<String, LfsPointer> oidStr2ptr = new HashMap<>(); for (LfsPointer p : res) { oidStr2ptr.put(p.getOid().name(), p); } Gson gson = Protocol.gson(); api.getOutputStream().write( gson.toJson(toRequest(OPERATION_UPLOAD, res)).getBytes(UTF_8)); int responseCode = api.getResponseCode(); if (responseCode != HTTP_OK) { throw new IOException( MessageFormat.format(LfsText.get().serverFailure, api.getURL(), Integer.valueOf(responseCode))); } return oidStr2ptr; }
/** * Get the HTTP response code from the request. * <p> * Roughly the same as <code>c.getResponseCode()</code> but the * ConnectException is translated to be more understandable. * * @param c * connection the code should be obtained from. * @return r HTTP status code, usually 200 to indicate success. See * {@link HttpConnection} for other defined constants. * @throws IOException * communications error prevented obtaining the response code. * @since 3.3 */ public static int response(final HttpConnection c) throws IOException { try { return c.getResponseCode(); } catch (ConnectException ce) { final URL url = c.getURL(); final String host = (url == null) ? "<null>" : url.getHost(); //$NON-NLS-1$ // The standard J2SE error message is not very useful. // if ("Connection timed out: connect".equals(ce.getMessage())) //$NON-NLS-1$ throw new ConnectException(MessageFormat.format(JGitText.get().connectionTimeOut, host)); throw new ConnectException(ce.getMessage() + " " + host); //$NON-NLS-1$ } }
/** * Get the HTTP response code from the request. * <p> * Roughly the same as <code>c.getResponseCode()</code> but the * ConnectException is translated to be more understandable. * * @param c * connection the code should be obtained from. * @return r HTTP status code, usually 200 to indicate success. See * {@link org.eclipse.jgit.transport.http.HttpConnection} for other * defined constants. * @throws java.io.IOException * communications error prevented obtaining the response code. * @since 3.3 */ public static int response(HttpConnection c) throws IOException { try { return c.getResponseCode(); } catch (ConnectException ce) { final URL url = c.getURL(); final String host = (url == null) ? "<null>" : url.getHost(); //$NON-NLS-1$ // The standard J2SE error message is not very useful. // if ("Connection timed out: connect".equals(ce.getMessage())) //$NON-NLS-1$ throw new ConnectException(MessageFormat.format(JGitText.get().connectionTimeOut, host)); throw new ConnectException(ce.getMessage() + " " + host); //$NON-NLS-1$ } }
private void uploadFile(Protocol.ObjectInfo o, Protocol.Action uploadAction, Path path) throws IOException, CorruptMediaFile { HttpConnection contentServer = LfsConnectionFactory .getLfsContentConnection(getRepository(), uploadAction, METHOD_PUT); contentServer.setDoOutput(true); try (OutputStream out = contentServer .getOutputStream()) { long size = Files.copy(path, out); if (size != o.size) { throw new CorruptMediaFile(path, o.size, size); } } int responseCode = contentServer.getResponseCode(); if (responseCode != HTTP_OK) { throw new IOException(MessageFormat.format( LfsText.get().serverFailure, contentServer.getURL(), Integer.valueOf(responseCode))); } } }
.toRequest(Protocol.OPERATION_DOWNLOAD, res)) .getBytes(UTF_8)); int responseCode = lfsServerConn.getResponseCode(); if (responseCode != HttpConnection.HTTP_OK) { throw new IOException( HttpSupport.METHOD_GET); responseCode = contentServerConn.getResponseCode(); if (responseCode != HttpConnection.HTTP_OK) { throw new IOException(
int status = conn.getResponseCode(); if (status == SC_OK) { String contentLengthHeader = conn
int status = conn.getResponseCode(); if (status == SC_OK) { String contentLengthHeader = conn