Java Code Examples for org.apache.http.StatusLine#toString()

The following examples show how to use org.apache.http.StatusLine#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpMessageHandler.java    From mr4c with Apache License 2.0 6 votes vote down vote up
public void handleMessage(Message msg) throws IOException {
	
	HttpPost post = new HttpPost(m_uri);
	post.setEntity(
		new StringEntity(
			msg.getContent(),
			ContentType.create(msg.getContentType())
		)
	);

	s_log.info("POSTing message to [{}]: [{}]", m_uri, msg);
	HttpResponse response = m_client.execute(post);
	StatusLine statusLine = response.getStatusLine();
	s_log.info("Status line: {}", statusLine);
	s_log.info("Content: {}", toString(response.getEntity()));
	if ( statusLine.getStatusCode()>=300 ) {
		throw new IOException(statusLine.toString());
	}

}
 
Example 2
Source File: CmisHttpSender.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public String extractResult(HttpResponseHandler responseHandler, IPipeLineSession session) throws SenderException, IOException {
	int responseCode = -1;
	try {
		StatusLine statusline = responseHandler.getStatusLine();
		responseCode = statusline.getStatusCode();

		InputStream responseStream = null;
		InputStream errorStream = null;
		Map<String, List<String>> headerFields = responseHandler.getHeaderFields();
		if (responseCode == 200 || responseCode == 201 || responseCode == 203 || responseCode == 206) {
			responseStream = responseHandler.getResponse();
		}
		else {
			errorStream = responseHandler.getResponse();
		}
		Response response = new Response(responseCode, statusline.toString(), headerFields, responseStream, errorStream);
		session.put("response", response);
	}
	catch(Exception e) {
		throw new CmisConnectionException(getUrl(), responseCode, e);
	}

	return "response";
}
 
Example 3
Source File: HttpAsyncDownloader.java    From JMCCC with MIT License 5 votes vote down vote up
@Override
protected void onResponseReceived(HttpResponse response) throws HttpException, IOException {
	StatusLine statusLine = response.getStatusLine();
	if (statusLine != null) {
		int statusCode = statusLine.getStatusCode();
		if (statusCode < 200 || statusCode > 299)
			// non-2xx response code
			throw new IllegalHttpResponseCodeException(statusLine.toString(), statusCode);
	}

	if (session == null) {
		boolean gzipOn = false;
		HttpEntity httpEntity = response.getEntity();
		if (httpEntity != null) {
			long contextLength = httpEntity.getContentLength();
			if (contextLength >= 0) {
				this.contextLength = contextLength;
			}

			Header contentEncodingHeader = httpEntity.getContentEncoding();
			if (contentEncodingHeader != null && "gzip".equals(contentEncodingHeader.getValue())) {
				gzipOn = true;
			}
		}

		session = contextLength > 0
				? task.createSession(contextLength)
				: task.createSession();

		if (gzipOn) {
			session = new GzipDownloadSession<>(session);
		}
	}
}
 
Example 4
Source File: ODataClientErrorException.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param statusLine request status info.
 */
public ODataClientErrorException(final StatusLine statusLine) {
  super(statusLine.toString());

  this.statusLine = statusLine;
  this.error = null;
}
 
Example 5
Source File: ODataClientErrorException.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param statusLine request status info.
 * @param error OData error to be wrapped.
 */
public ODataClientErrorException(final StatusLine statusLine, final ODataError error) {
  super(error == null ?
      statusLine.toString() :
      (error.getCode() == null || error.getCode().isEmpty() ? "" : "(" + error.getCode() + ") ")
          + error.getMessage() + " [" + statusLine.toString() + "]");

  this.statusLine = statusLine;
  this.error = error;
}
 
Example 6
Source File: DatasetUtils.java    From datasync with MIT License 5 votes vote down vote up
private static <T> T getDatasetInfoReflective(UserPreferences userPrefs, String viewId, final Class<T> typ) throws URISyntaxException, IOException, HttpException {
    String justDomain = getDomainWithoutScheme(userPrefs);
    URI absolutePath = new URIBuilder()
        .setScheme("https")
        .setHost(justDomain)
        .setPath("/api/views/" + viewId)
        .build();

    ResponseHandler<T> handler = new ResponseHandler<T>() {
        @Override
        public T handleResponse(
            final HttpResponse response) throws ClientProtocolException, IOException {
            StatusLine statusLine = response.getStatusLine();
            int status = statusLine.getStatusCode();
            if (status >= 200 && status < 300) {
                HttpEntity entity = response.getEntity();
                return entity != null ? mapper.readValue(entity.getContent(), typ) : null;
            } else {
                throw new ClientProtocolException(statusLine.toString());
            }
        }
    };

    HttpUtility util = new HttpUtility(userPrefs, true);
    T datasetInfo = util.get(absolutePath, "application/json", handler);
    util.close();
    return datasetInfo;
}
 
Example 7
Source File: GoogleApacheHttpResponse.java    From PYX-Reloaded with Apache License 2.0 4 votes vote down vote up
@Override
public String getStatusLine() {
    StatusLine statusLine = response.getStatusLine();
    return statusLine == null ? null : statusLine.toString();
}
 
Example 8
Source File: ApacheHttpResponse.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
@Override
public String getStatusLine() {
  StatusLine statusLine = response.getStatusLine();
  return statusLine == null ? null : statusLine.toString();
}
 
Example 9
Source File: ApacheHttpResponse.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
@Override
public String getStatusLine() {
  StatusLine statusLine = response.getStatusLine();
  return statusLine == null ? null : statusLine.toString();
}
 
Example 10
Source File: HttpRequestFailed.java    From document-viewer with GNU General Public License v3.0 4 votes vote down vote up
public HttpRequestFailed(final StatusLine statusLine) {
    super(statusLine.toString());
    this.code = statusLine.getStatusCode();
    this.reason = statusLine.getReasonPhrase();
}
 
Example 11
Source File: DatasetUtils.java    From datasync with MIT License 4 votes vote down vote up
public static List<List<String>> getDatasetSample(UserPreferences userPrefs, Dataset dataset, int rowsToSample) throws URISyntaxException, IOException, HttpException {
    String justDomain = getDomainWithoutScheme(userPrefs);
    URI absolutePath = new URIBuilder()
        .setScheme("https")
        .setHost(justDomain)
        .setPath("/resource/" + dataset.getId() + ".csv")
        .addParameter("$limit",""+rowsToSample)
        .build();

    ResponseHandler<String> handler = new ResponseHandler<String>() {
        @Override
        public String handleResponse(
            final HttpResponse response) throws ClientProtocolException, IOException {
            StatusLine statusLine = response.getStatusLine();
            int status = statusLine.getStatusCode();
            if (status >= 200 && status < 300) {
                HttpEntity entity = response.getEntity();
                return entity != null ? EntityUtils.toString(entity) : null;
            } else {
                throw new ClientProtocolException(statusLine.toString());
            }
        }
    };

    HttpUtility util = new HttpUtility(userPrefs, true);
    String sample = util.get(absolutePath, "application/csv", handler);
    util.close();

    CSVReader reader = new CSVReader(new StringReader(sample));

    List<List<String>> results = new ArrayList<>();

    Set<String> expectedFieldNames = new HashSet<String>();
    for(Column c : dataset.getColumns()) {
        expectedFieldNames.add(c.getFieldName());
    }
    String[] row = reader.readNext();
    boolean[] keep = new boolean[row.length];
    for(int i = 0; i != row.length; ++i) {
        keep[i] = expectedFieldNames.contains(row[i]);
    }
    results.add(filter(keep, row));

    while((row = reader.readNext()) != null) {
        results.add(filter(keep, row));
    }

    return results;
}
 
Example 12
Source File: ODataServerErrorException.java    From olingo-odata4 with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param statusLine request status info.
 */
public ODataServerErrorException(final StatusLine statusLine) {
  super(statusLine.toString());
}