/** * Creates a new test server. * * @param proc the HTTP processors to be used by the server, or * <code>null</code> to use a * {@link #newProcessor default} processor * @param reuseStrat the connection reuse strategy to be used by the * server, or <code>null</code> to use * {@link #newConnectionReuseStrategy() default} * strategy. * @param params the parameters to be used by the server, or * <code>null</code> to use * {@link #newDefaultParams default} parameters * @param sslcontext optional SSL context if the server is to leverage * SSL/TLS transport security */ public HttpTestServer( final BasicHttpProcessor proc, final ConnectionReuseStrategy reuseStrat, final HttpResponseFactory responseFactory, final HttpExpectationVerifier expectationVerifier, final HttpParams params, final SSLContext sslcontext) { this.handlerRegistry = new HttpRequestHandlerRegistry(); this.workers = Collections.synchronizedSet(new HashSet<Worker>()); this.httpservice = new HttpService( proc != null ? proc : newProcessor(), reuseStrat != null ? reuseStrat : newConnectionReuseStrategy(), responseFactory != null ? responseFactory : newHttpResponseFactory(), handlerRegistry, expectationVerifier, params != null ? params : newDefaultParams()); this.sslcontext = sslcontext; }
/** * */ @Test public void handleResponseTest() throws Exception { ResponseHandler handler = new ResponseHandler(); HttpResponseFactory factory = new DefaultHttpResponseFactory(); HttpResponse responseSent = factory.newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "reason"), null); HttpResponse response = handler.handleResponse(responseSent); Assert.assertEquals(handler.getStatus(), HttpStatus.SC_OK); Assert.assertFalse(handler.hasContent()); // response with content. BasicHttpEntity entity = new BasicHttpEntity(); InputStream inputStream = new ByteArrayInputStream("new content".getBytes()); entity.setContent(inputStream); entity.setContentLength("new content".length()); // sets the length response.setEntity(entity); response = handler.handleResponse(responseSent); Assert.assertEquals("new content", handler.getResponseContent()); }
@Override protected HttpMessageParser<HttpResponse> createResponseParser( final SessionInputBuffer buffer, final HttpResponseFactory responseFactory, final HttpParams params) { // override in derived class to specify a line parser return new DefaultHttpResponseParser (buffer, null, responseFactory, params); }
public DefaultResponseParser( final SessionInputBuffer buffer, final LineParser parser, final HttpResponseFactory responseFactory, final HttpParams params) { super(buffer, parser, params); if (responseFactory == null) { throw new IllegalArgumentException ("Response factory may not be null"); } this.responseFactory = responseFactory; this.lineBuf = new CharArrayBuffer(128); this.maxGarbageLines = getMaxGarbageLines(params); }
public DefaultHttpResponseParser( final SessionInputBuffer buffer, final LineParser parser, final HttpResponseFactory responseFactory, final HttpParams params) { super(buffer, parser, params); if (responseFactory == null) { throw new IllegalArgumentException ("Response factory may not be null"); } this.responseFactory = responseFactory; this.lineBuf = new CharArrayBuffer(128); }
/** * Create a new HTTP service. * * @param processor the processor to use on requests and responses * @param connStrategy the connection reuse strategy * @param responseFactory the response factory * @param handlerResolver the handler resolver. May be null. * @param expectationVerifier the expectation verifier. May be null. * @param params the HTTP parameters * * @since 4.1 */ public HttpService( final HttpProcessor processor, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory, final HttpRequestHandlerResolver handlerResolver, final HttpExpectationVerifier expectationVerifier, final HttpParams params) { super(); if (processor == null) { throw new IllegalArgumentException("HTTP processor may not be null"); } if (connStrategy == null) { throw new IllegalArgumentException("Connection reuse strategy may not be null"); } if (responseFactory == null) { throw new IllegalArgumentException("Response factory may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this.processor = processor; this.connStrategy = connStrategy; this.responseFactory = responseFactory; this.handlerResolver = handlerResolver; this.expectationVerifier = expectationVerifier; this.params = params; }
/** * Create a new HTTP service. * * @param proc the processor to use on requests and responses * @param connStrategy the connection reuse strategy * @param responseFactory the response factory * * @deprecated (4.1) use {@link HttpService#HttpService(HttpProcessor, * ConnectionReuseStrategy, HttpResponseFactory, HttpRequestHandlerResolver, HttpParams)} */ @Deprecated public HttpService( final HttpProcessor proc, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory) { super(); setHttpProcessor(proc); setConnReuseStrategy(connStrategy); setResponseFactory(responseFactory); }
/** * @deprecated (4.1) set {@link HttpResponseFactory} using constructor */ @Deprecated public void setResponseFactory(final HttpResponseFactory responseFactory) { if (responseFactory == null) { throw new IllegalArgumentException("Response factory may not be null"); } this.responseFactory = responseFactory; }
/** * Creates an instance of this class. * * @param buffer the session input buffer. * @param parser the line parser. * @param responseFactory the factory to use to create * {@link HttpResponse}s. * @param params HTTP parameters. */ public HttpResponseParser( final SessionInputBuffer buffer, final LineParser parser, final HttpResponseFactory responseFactory, final HttpParams params) { super(buffer, parser, params); if (responseFactory == null) { throw new IllegalArgumentException("Response factory may not be null"); } this.responseFactory = responseFactory; this.lineBuf = new CharArrayBuffer(128); }
/** * Creates an instance of this class. * * @param buffer the session input buffer. * @param parser the line parser. * @param responseFactory the factory to use to create * {@link HttpResponse}s. * @param params HTTP parameters. */ public DefaultHttpResponseParser( final SessionInputBuffer buffer, final LineParser parser, final HttpResponseFactory responseFactory, final HttpParams params) { super(buffer, parser, params); if (responseFactory == null) { throw new IllegalArgumentException("Response factory may not be null"); } this.responseFactory = responseFactory; this.lineBuf = new CharArrayBuffer(128); }
public YaaccHttpService(HttpProcessor proc, ConnectionReuseStrategy connStrategy, HttpResponseFactory responseFactory, Context context) { super(proc, connStrategy, responseFactory); this.context = context; }
@Override protected HttpMessageParser<HttpResponse> createResponseParser(final SessionInputBuffer buffer, final HttpResponseFactory responseFactory, final HttpParams params) { // override in derived class to specify a line parser return new DefaultHttpResponseParser(buffer, null, responseFactory, params); }
public ListeningHandler( final HttpHost targetHost, final ConnectingIOReactor connectingIOReactor, final HttpProcessor httpProcessor, final HttpResponseFactory responseFactory, final ConnectionReuseStrategy connStrategy, final HttpParams params) { super(); this.targetHost = targetHost; this.connectingIOReactor = connectingIOReactor; this.httpProcessor = httpProcessor; this.connStrategy = connStrategy; this.responseFactory = responseFactory; this.params = params; }
public DefaultHttpResponseParserFactory( final LineParser lineParser, final HttpResponseFactory responseFactory) { super(); this.lineParser = lineParser != null ? lineParser : BasicLineParserHC4.INSTANCE; this.responseFactory = responseFactory != null ? responseFactory : DefaultHttpResponseFactoryHC4.INSTANCE; }
/** * @deprecated (4.3) use {@link DefaultHttpResponseParser#DefaultHttpResponseParser( * SessionInputBuffer, LineParser, HttpResponseFactory, MessageConstraints)} */ @Deprecated public DefaultHttpResponseParser( final SessionInputBuffer buffer, final LineParser parser, final HttpResponseFactory responseFactory, final HttpParams params) { super(buffer, parser, params); Args.notNull(responseFactory, "Response factory"); this.responseFactory = responseFactory; this.lineBuf = new CharArrayBuffer(128); }
public DefaultHttpResponseParserFactory(final LineParser lineParser, final HttpResponseFactory responseFactory) { super(); this.lineParser = lineParser != null ? lineParser : BasicLineParserHC4.INSTANCE; this.responseFactory = responseFactory != null ? responseFactory : DefaultHttpResponseFactoryHC4.INSTANCE; }
@Override protected String sendAndReturn(HttpUriRequest request) throws IOException{ HttpResponseFactory factory = new DefaultHttpResponseFactory(); HttpResponse response = factory.newHttpResponse( new BasicStatusLine(HttpVersion.HTTP_1_1, this.status, null),null); StringBuilder sb = new StringBuilder(); sb.append(String.format("%s = %s;", "METHOD", request.getMethod())); sb.append(String.format("%s = %s;", "URI", request.getURI())); if (request.getAllHeaders().length > 0){ sb.append("HEADER_EXISTS"); } for (Header h : request.getAllHeaders()){ sb.append(String.format("%s = %s;", h.getName(), h.getValue())); } if (request instanceof HttpEntityEnclosingRequestBase){ HttpEntity entity = ((HttpEntityEnclosingRequestBase)request).getEntity(); if (entity != null){ sb.append("BODY_EXISTS"); sb.append(String.format("%s = %s;", "BODY", EntityUtils.toString(entity))); } } response.setEntity(new StringEntity(sb.toString())); return parseResponse(response); }
public DefaultResponseParser( final SessionInputBuffer buffer, final LineParser parser, final HttpResponseFactory responseFactory, final HttpParams params) { super(buffer, parser, params); Args.notNull(responseFactory, "Response factory"); this.responseFactory = responseFactory; this.lineBuf = new CharArrayBuffer(128); this.maxGarbageLines = getMaxGarbageLines(params); }
public DefaultHttpResponseParserFactory( final LineParser lineParser, final HttpResponseFactory responseFactory) { super(); this.lineParser = lineParser != null ? lineParser : BasicLineParser.INSTANCE; this.responseFactory = responseFactory != null ? responseFactory : DefaultHttpResponseFactory.INSTANCE; }
@Override protected HttpMessageParser createResponseParser( final SessionInputBuffer buffer, final HttpResponseFactory responseFactory, final HttpParams params) { // override in derived class to specify a line parser return new DefaultResponseParser (buffer, null, responseFactory, params); }
public DefaultResponseParser( final SessionInputBuffer buffer, final LineParser parser, final HttpResponseFactory responseFactory, final HttpParams params) { super(buffer, parser, params); if (responseFactory == null) { throw new IllegalArgumentException ("Response factory may not be null"); } this.responseFactory = responseFactory; this.lineBuf = new CharArrayBuffer(128); this.maxGarbageLines = params.getIntParameter( ConnConnectionPNames.MAX_STATUS_LINE_GARBAGE, Integer.MAX_VALUE); }
@Override protected HttpMessageParser<HttpResponse> createResponseParser( final SessionInputBuffer buffer, final HttpResponseFactory responseFactory, final HttpParams params) { return new DefaultHttpResponseParser( buffer, new MyLineParser(), responseFactory, params); }
public AxisHttpService( final HttpProcessor httpProcessor, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory, final ConfigurationContext configurationContext, final Worker worker) { super(); if (httpProcessor == null) { throw new IllegalArgumentException("HTTP processor may not be null"); } if (connStrategy == null) { throw new IllegalArgumentException("Connection strategy may not be null"); } if (responseFactory == null) { throw new IllegalArgumentException("Response factory may not be null"); } if (worker == null) { throw new IllegalArgumentException("Worker may not be null"); } if (configurationContext == null) { throw new IllegalArgumentException("Configuration context may not be null"); } this.httpProcessor = httpProcessor; this.connStrategy = connStrategy; this.responseFactory = responseFactory; this.configurationContext = configurationContext; this.worker = worker; }
public DefaultHttpResponseParserFactory( final HttpResponseFactory responseFactory) { this(null, responseFactory); }
public GarbageAllergicHttpResponseParser(SessionInputBuffer buffer, LineParser lineParser, HttpResponseFactory responseFactory, MessageConstraints constraints) { super(buffer, lineParser, responseFactory, constraints); }
protected HttpResponseFactory newHttpResponseFactory() { return new DefaultHttpResponseFactory(); }
public HttpResponseFactory newResponseFactory() { return new DefaultHttpResponseFactory(); }