/** * @see HttpConnectionManager#getConnection(HostConfiguration, long) * * @deprecated Use #getConnectionWithTimeout(HostConfiguration, long) */ public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException { LOG.trace("enter HttpConnectionManager.getConnection(HostConfiguration, long)"); try { return getConnectionWithTimeout(hostConfiguration, timeout); } catch(ConnectionPoolTimeoutException e) { throw new HttpException(e.getMessage()); } }
throw new HttpException("Status-Line '" + statusLine + "' does not start with HTTP"); throw new HttpException("Status-Line '" + statusLine + "' is not valid");
protected HttpException buildHttpException(Exception e) { String message = "Unable to get event " + getName() + " subject: " + subject + " at " + permanentUrl + ": " + e.getMessage(); LOGGER.warn(message); return new HttpException(message); }
/** * Get Multistatus responses. * * @return responses * @throws HttpException on error */ public MultiStatusResponse[] getResponses() throws HttpException { if (responses == null) { throw new HttpException(getStatusLine().toString()); } return responses.toArray(new MultiStatusResponse[responses.size()]); }
/** * Get single Multistatus response. * * @return response * @throws HttpException on error */ public MultiStatusResponse getResponse() throws HttpException { if (responses == null || responses.size() != 1) { throw new HttpException(getStatusLine().toString()); } return responses.get(0); }
/** * @see HttpConnectionManager#getConnection(HostConfiguration, long) * * @deprecated Use #getConnectionWithTimeout(HostConfiguration, long) */ public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException { LOG.trace("enter HttpConnectionManager.getConnection(HostConfiguration, long)"); try { return getConnectionWithTimeout(hostConfiguration, timeout); } catch(ConnectionPoolTimeoutException e) { throw new HttpException(e.getMessage()); } }
/** * @see HttpConnectionManager#getConnection(HostConfiguration, long) * * @deprecated Use #getConnectionWithTimeout(HostConfiguration, long) */ public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException { LOG.trace("enter HttpConnectionManager.getConnection(HostConfiguration, long)"); try { return getConnectionWithTimeout(hostConfiguration, timeout); } catch(ConnectionPoolTimeoutException e) { throw new HttpException(e.getMessage()); } }
/** * @see HttpConnectionManager#getConnection(HostConfiguration, long) * * @deprecated Use #getConnectionWithTimeout(HostConfiguration, long) */ public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException { LOG.trace("enter HttpConnectionManager.getConnection(HostConfiguration, long)"); try { return getConnectionWithTimeout(hostConfiguration, timeout); } catch(ConnectionPoolTimeoutException e) { throw new HttpException(e.getMessage()); } }
/** * @see HttpConnectionManager#getConnection(HostConfiguration, long) * * @deprecated Use #getConnectionWithTimeout(HostConfiguration, long) */ public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException { LOG.trace("enter HttpConnectionManager.getConnection(HostConfiguration, long)"); try { return getConnectionWithTimeout(hostConfiguration, timeout); } catch(ConnectionPoolTimeoutException e) { throw new HttpException(e.getMessage()); } }
/** * @see HttpConnectionManager#getConnection(HostConfiguration, long) * * @deprecated Use #getConnectionWithTimeout(HostConfiguration, long) */ public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException { LOG.trace("enter HttpConnectionManager.getConnection(HostConfiguration, long)"); try { return getConnectionWithTimeout(hostConfiguration, timeout); } catch(ConnectionPoolTimeoutException e) { throw new HttpException(e.getMessage()); } }
/** * 用于get、post、put、delete请求,请求、接收参数都为对象 * @param method 请求方式 * @param urlStr 请求RUL * @param params 请求参数对象 * @param responseType 返回数据类型 * @param resultBeanClass 返回数据对象 * @return Object * @throws Exception 抛出异常 */ public static Object requestMethod(String method, String urlStr, Object params, String responseType, Class<?> resultBeanClass) throws Exception{ if(HttpUtil.POST.equals(method.toUpperCase())){ return requestPost(urlStr, params, responseType, resultBeanClass); } else if(HttpUtil.GET.equals(method.toUpperCase())){ return requestGet(urlStr, params, responseType, resultBeanClass); } else if(HttpUtil.PUT.equals(method.toUpperCase())){ return requestPut(urlStr, params, responseType, resultBeanClass); } else if(HttpUtil.DELETE.equals(method.toUpperCase())){ return requestDelete(urlStr, params, responseType, resultBeanClass); } else { throw new HttpException("mothod is error!"); } }
protected String[] multipartPost(LinkedList<Part> parts, String URL, int expectedSC) throws IOException { log.debug("Request POST: " + URL); parts.add(new StringPart("token", token)); PostMethod postRequest = new PostMethod(URL); MultipartRequestEntity multipartRequest = new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), postRequest.getParams()); postRequest.setRequestEntity(multipartRequest); int result = httpClient.executeMethod(postRequest); if (result != expectedSC) { String fname = File.createTempFile("error_", ".html").getAbsolutePath(); notifier.notifyAbout("Saving server error response to: " + fname); FileOutputStream fos = new FileOutputStream(fname); FileChannel resultFile = fos.getChannel(); resultFile.write(ByteBuffer.wrap(IOUtils.toByteArray(postRequest.getResponseBodyAsStream()))); resultFile.close(); throw new HttpException("Request returned not " + expectedSC + " status code: " + result); } byte[] bytes = IOUtils.toByteArray(postRequest.getResponseBodyAsStream()); if (bytes == null) { bytes = new byte[0]; } String response = new String(bytes); return response.trim().split(";"); } }
throw new HttpException( String.format("Execute ethod failed: [%s]", String.valueOf(get.getStatusLine())) );
public void logout(String token) { HttpClient httpClient = new HttpClient(); PostMethod post = new PostMethod(LOG_ENDPOINT); LOG.log(Level.INFO, "Logging out: token: [" + token + "]: REST url: [" + LOG_ENDPOINT + "]"); NameValuePair[] data = { new NameValuePair("subjectid", token) }; post.setRequestBody(data); try { httpClient.executeMethod(post); if (post.getStatusCode() != HttpStatus.SC_OK) { throw new HttpException(post.getStatusLine().toString()); } } catch (HttpException e) { // TODO Auto-generated catch block LOG.log(Level.SEVERE, e.getMessage()); } catch (IOException e) { // TODO Auto-generated catch block LOG.log(Level.SEVERE, e.getMessage()); } finally { post.releaseConnection(); } }
public void logout(String token) { HttpClient httpClient = new HttpClient(); PostMethod post = new PostMethod(LOG_ENDPOINT); LOG.log(Level.INFO, "Logging out: token: [" + token + "]: REST url: [" + LOG_ENDPOINT + "]"); NameValuePair[] data = { new NameValuePair("subjectid", token) }; post.setRequestBody(data); try { httpClient.executeMethod(post); if (post.getStatusCode() != HttpStatus.SC_OK) { throw new HttpException(post.getStatusLine().toString()); } } catch (HttpException e) { // TODO Auto-generated catch block LOG.log(Level.SEVERE, e.getMessage()); } catch (IOException e) { // TODO Auto-generated catch block LOG.log(Level.SEVERE, e.getMessage()); } finally { post.releaseConnection(); } }
return new HttpServerErrorException(message.toString()); } else { return new HttpException(message.toString());
public String authenticate(String username, String password) { HttpClient httpClient = new HttpClient(); PostMethod post = new PostMethod(AUTH_ENDPOINT); String response; String ssoToken = null; NameValuePair[] data = { new NameValuePair("username", username), new NameValuePair("password", password), new NameValuePair("uri", "realm/lmmp") }; post.setRequestBody(data); try { httpClient.executeMethod(post); if (post.getStatusCode() != HttpStatus.SC_OK) { throw new HttpException(post.getStatusLine().toString()); } response = post.getResponseBodyAsString().trim(); ssoToken = response.substring(9); } catch (Exception e) { LOG.log(Level.SEVERE, e.getMessage()); } finally { post.releaseConnection(); } return ssoToken; }
public String authenticate(String username, String password) { HttpClient httpClient = new HttpClient(); PostMethod post = new PostMethod(AUTH_ENDPOINT); String response; String ssoToken = null; NameValuePair[] data = { new NameValuePair("username", username), new NameValuePair("password", password), new NameValuePair("uri", "realm/lmmp") }; post.setRequestBody(data); try { httpClient.executeMethod(post); if (post.getStatusCode() != HttpStatus.SC_OK) { throw new HttpException(post.getStatusLine().toString()); } response = post.getResponseBodyAsString().trim(); ssoToken = response.substring(9); } catch (Exception e) { LOG.log(Level.SEVERE, e.getMessage()); } finally { post.releaseConnection(); } return ssoToken; }
@Override public Version getBundleVersion(String bundleSymbolicName) throws OsgiClientException { GetMethod method = new GetMethod(repositoryInfo.getUrl() + "system/console/bundles.json"); HttpClient client = getHttpClient(); try { int result = client.executeMethod(method); if (result != HttpStatus.SC_OK) { throw new HttpException("Got status code " + result + " for call to " + method.getURI()); } JSONObject object = new JSONObject(method.getResponseBodyAsString()); JSONArray bundleData = object.getJSONArray("data"); for (int i = 0; i < bundleData.length(); i++) { JSONObject bundle = bundleData.getJSONObject(i); String remotebundleSymbolicName = bundle.getString("symbolicName"); Version bundleVersion = new Version(bundle.getString("version")); if (bundleSymbolicName.equals(remotebundleSymbolicName)) { return bundleVersion; } } return null; } catch (HttpException e) { throw new OsgiClientException(e); } catch (IOException e) { throw new OsgiClientException(e); } catch (JSONException e) { throw new OsgiClientException(e); } finally { method.releaseConnection(); } }
HttpException ex = new HttpException(); ex.setReasonCode(status); throw ex;