org.frameworkset.spi.remote.http.StringResponseHandler Maven / Gradle / Ivy
package org.frameworkset.spi.remote.http;
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;
public class StringResponseHandler implements ResponseHandler {
public StringResponseHandler() {
// TODO Auto-generated constructor stub
}
@Override
public String handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else {
HttpEntity entity = response.getEntity();
if (entity != null )
return EntityUtils.toString(entity);
else
throw new ClientProtocolException("Unexpected response status: " + status);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy