use of org.apache.http.HttpException in project camel by apache.
the class HttpProducerTwoHeadersWithSameKeyTest method setUp.
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/myapp", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
Header[] from = request.getHeaders("from");
assertEquals("me", from[0].getValue());
Header[] to = request.getHeaders("to");
assertEquals("[foo, bar]", to[0].getValue());
response.setHeader("bar", "yes");
response.addHeader("foo", "123");
response.addHeader("foo", "456");
response.setEntity(new StringEntity("OK", "ASCII"));
response.setStatusCode(HttpStatus.SC_OK);
}
}).registerHandler("/myapp", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
Header[] from = request.getHeaders("from");
assertEquals("me", from[0].getValue());
Header[] to = request.getHeaders("to");
assertEquals("[foo, bar]", to[0].getValue());
response.setHeader("bar", "yes");
response.addHeader("foo", "123");
response.addHeader("foo", "456");
response.setEntity(new StringEntity("OK", "ASCII"));
response.setStatusCode(HttpStatus.SC_OK);
}
}).create();
localServer.start();
super.setUp();
}
use of org.apache.http.HttpException in project camel by apache.
the class HttpProducerTwoParametersWithSameKeyTest method setUp.
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/myapp", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
String uri = request.getRequestLine().getUri();
assertEquals("/myapp?from=me&to=foo&to=bar", uri);
response.setHeader("bar", "yes");
response.addHeader("foo", "123");
response.addHeader("foo", "456");
response.setEntity(new StringEntity("OK", "ASCII"));
response.setStatusCode(HttpStatus.SC_OK);
}
}).create();
localServer.start();
super.setUp();
}
use of org.apache.http.HttpException in project camel by apache.
the class HttpProducerContentTypeTest method setUp.
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/content", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
String contentType = request.getFirstHeader(Exchange.CONTENT_TYPE).getValue();
assertEquals(CONTENT_TYPE, contentType);
response.setEntity(new StringEntity(contentType, "ASCII"));
response.setStatusCode(HttpStatus.SC_OK);
}
}).create();
localServer.start();
super.setUp();
}
use of org.apache.http.HttpException in project camel by apache.
the class HttpNoCamelHeaderTest method setUp.
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/hello", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
response.setStatusCode(HttpStatus.SC_OK);
Object header = request.getFirstHeader(Exchange.FILE_NAME);
assertNull("There should be no Camel header", header);
for (Header h : request.getAllHeaders()) {
if (h.getName().startsWith("Camel") || h.getName().startsWith("org.apache.camel")) {
assertNull("There should be no Camel header", h);
}
}
// set ar regular and Camel header
response.setHeader("MyApp", "dude");
response.setHeader(Exchange.TO_ENDPOINT, "foo");
}
}).create();
localServer.start();
super.setUp();
}
use of org.apache.http.HttpException in project android_frameworks_base by ParanoidAndroid.
the class Connection method processRequests.
/**
* Process requests in queue
* pipelines requests
*/
void processRequests(Request firstRequest) {
Request req = null;
boolean empty;
int error = EventHandler.OK;
Exception exception = null;
LinkedList<Request> pipe = new LinkedList<Request>();
int minPipe = MIN_PIPE, maxPipe = MAX_PIPE;
int state = SEND;
while (state != DONE) {
if (HttpLog.LOGV)
HttpLog.v(states[state] + " pipe " + pipe.size());
/* If a request was cancelled, give other cancel requests
some time to go through so we don't uselessly restart
connections */
if (mActive == STATE_CANCEL_REQUESTED) {
try {
Thread.sleep(100);
} catch (InterruptedException x) {
/* ignore */
}
mActive = STATE_NORMAL;
}
switch(state) {
case SEND:
{
if (pipe.size() == maxPipe) {
state = READ;
break;
}
/* get a request */
if (firstRequest == null) {
req = mRequestFeeder.getRequest(mHost);
} else {
req = firstRequest;
firstRequest = null;
}
if (req == null) {
state = DRAIN;
break;
}
req.setConnection(this);
/* Don't work on cancelled requests. */
if (req.mCancelled) {
if (HttpLog.LOGV)
HttpLog.v("processRequests(): skipping cancelled request " + req);
req.complete();
break;
}
if (mHttpClientConnection == null || !mHttpClientConnection.isOpen()) {
if (!openHttpConnection(req)) {
state = DONE;
break;
}
}
/* we have a connection, let the event handler
* know of any associated certificate,
* potentially none.
*/
req.mEventHandler.certificate(mCertificate);
try {
/* FIXME: don't increment failure count if old
connection? There should not be a penalty for
attempting to reuse an old connection */
req.sendRequest(mHttpClientConnection);
} catch (HttpException e) {
exception = e;
error = EventHandler.ERROR;
} catch (IOException e) {
exception = e;
error = EventHandler.ERROR_IO;
} catch (IllegalStateException e) {
exception = e;
error = EventHandler.ERROR_IO;
}
if (exception != null) {
if (httpFailure(req, error, exception) && !req.mCancelled) {
/* retry request if not permanent failure
or cancelled */
pipe.addLast(req);
}
exception = null;
state = clearPipe(pipe) ? DONE : SEND;
minPipe = maxPipe = 1;
break;
}
pipe.addLast(req);
if (!mCanPersist)
state = READ;
break;
}
case DRAIN:
case READ:
{
empty = !mRequestFeeder.haveRequest(mHost);
int pipeSize = pipe.size();
if (state != DRAIN && pipeSize < minPipe && !empty && mCanPersist) {
state = SEND;
break;
} else if (pipeSize == 0) {
/* Done if no other work to do */
state = empty ? DONE : SEND;
break;
}
req = (Request) pipe.removeFirst();
if (HttpLog.LOGV)
HttpLog.v("processRequests() reading " + req);
try {
req.readResponse(mHttpClientConnection);
} catch (ParseException e) {
exception = e;
error = EventHandler.ERROR_IO;
} catch (IOException e) {
exception = e;
error = EventHandler.ERROR_IO;
} catch (IllegalStateException e) {
exception = e;
error = EventHandler.ERROR_IO;
}
if (exception != null) {
if (httpFailure(req, error, exception) && !req.mCancelled) {
/* retry request if not permanent failure
or cancelled */
req.reset();
pipe.addFirst(req);
}
exception = null;
mCanPersist = false;
}
if (!mCanPersist) {
if (HttpLog.LOGV)
HttpLog.v("processRequests(): no persist, closing " + mHost);
closeConnection();
mHttpContext.removeAttribute(HTTP_CONNECTION);
clearPipe(pipe);
minPipe = maxPipe = 1;
state = SEND;
}
break;
}
}
}
}
Aggregations