Package org.apache.http

Examples of org.apache.http.HttpException


        httpExchange.setRequestState(MessageState.READY);
        httpExchange.setResponseState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.conn.isResponseSubmitted()).thenReturn(true);

        HttpException httpex = new HttpException();
        this.protocolHandler.exception(this.conn, httpex);

        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Mockito.verify(this.conn).close();
View Full Code Here


        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        BasicHttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
        Mockito.when(this.conn.getHttpRequest()).thenReturn(request);
        Mockito.when(this.requestHandler.processRequest(
                request, exchangeContext)).thenThrow(new HttpException());

        this.protocolHandler.requestReceived(this.conn);
        Mockito.verify(this.conn).shutdown();
    }
View Full Code Here

        httpExchange.setRequest(request);
        httpExchange.setRequestConsumer(this.requestConsumer);
        httpExchange.setRequestHandler(this.requestHandler);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.decoder.isCompleted()).thenReturn(true);
        Mockito.when(this.requestConsumer.getException()).thenReturn(new HttpException());
        Mockito.when(this.requestConsumer.getResult()).thenReturn(null);

        this.protocolHandler.inputReady(conn, this.decoder);

        Assert.assertEquals(MessageState.COMPLETED, httpExchange.getRequestState());
View Full Code Here

        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.setEntity(NStringEntity.create("stuff"));
        Mockito.when(this.responseProducer.generateResponse()).thenReturn(response);
        Mockito.doThrow(new HttpException()).when(
                this.httpProcessor).process(response, exchangeContext);

        this.protocolHandler.responseReady(this.conn);

        Mockito.verify(this.conn).shutdown();
View Full Code Here

            }
        } else {
            String s = request.getRequestLine().getUri();
            int idx = s.indexOf('x');
            if (idx == -1) {
                throw new HttpException("Unexpected request-URI format");
            }
            String pattern = s.substring(0, idx);
            int count = Integer.parseInt(s.substring(idx + 1, s.length()));

            StringBuilder buffer = new StringBuilder();
View Full Code Here

            public Cancellable handle(
                    final HttpRequest request,
                    final HttpAsyncResponseTrigger trigger,
                    final HttpContext context) throws HttpException, IOException {
                throw new HttpException("Boom");
            }

        }

        HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
View Full Code Here

        httpExchange.setRequestState(MessageState.COMPLETED);
        httpExchange.setResponseState(MessageState.COMPLETED);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);

        HttpException httpex = new HttpException();
        this.protocolHandler.exception(this.conn, httpex);

        Assert.assertNotNull(httpExchange.getHandler());
        Mockito.verify(this.exchangeHandler).failed(httpex);
        Mockito.verify(this.conn).close();
View Full Code Here

        }
    }

    @Test
    public void testRequestHttpException() throws Exception {
        HttpException httpex = new HttpException();
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.exchangeHandler.generateRequest()).thenThrow(httpex);
View Full Code Here

        }
    }

    @Test
    public void testResponseHttpException() throws Exception {
        HttpException httpex = new HttpException();
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpRequest request = new BasicHttpRequest("GET", "/");
        httpExchange.setRequest(request);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
View Full Code Here

                    if (s.startsWith("/?n=")) {
                        s = s.substring(4);
                        try {
                            n = Integer.parseInt(s);
                            if (n <= 0) {
                                throw new HttpException("Invalid request: " +
                                        "number of repetitions cannot be negative or zero");
                            }
                        } catch (NumberFormatException ex) {
                            throw new HttpException("Invalid request: " +
                                    "number of repetitions is invalid");
                        }
                    }

                    HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
                    String line = EntityUtils.toString(incoming);
                    ContentType contentType = ContentType.getOrDefault(incoming);
                    String charset = contentType.getCharset();
                    if (charset == null) {
                        charset = HTTP.DEFAULT_CONTENT_CHARSET;
                    }
                    RepeatingEntity outgoing = new RepeatingEntity(line, charset, n);
                    outgoing.setChunked(n % 2 == 0);
                    response.setEntity(outgoing);
                } else {
                    throw new HttpException("Invalid request: POST request expected");
                }
            }

        });
View Full Code Here

TOP

Related Classes of org.apache.http.HttpException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.