Example usage for org.apache.http.impl DefaultHttpRequestFactory DefaultHttpRequestFactory

List of usage examples for org.apache.http.impl DefaultHttpRequestFactory DefaultHttpRequestFactory

Introduction

In this page you can find the example usage for org.apache.http.impl DefaultHttpRequestFactory DefaultHttpRequestFactory.

Prototype

DefaultHttpRequestFactory

Source Link

Usage

From source file:org.apache.axis2.transport.nhttp.PlainServerIOEventDispatch.java

public void connected(final IOSession session) {
    // Decorate I/O session with logging capabilities
    LoggingNHttpServerConnection conn = new LoggingNHttpServerConnection(new LoggingIOSession(session),
            new DefaultHttpRequestFactory(), new HeapByteBufferAllocator(), this.params);
    session.setAttribute(NHTTP_CONN, conn);
    this.handler.connected(conn);
}

From source file:net.swas.explorer.httpprofile.Profile.java

/**
 * @param fileName fileName of HTTP dump file
 * @param context context is for capturing the knowledge base configuration.
 * @return boolean//from w  ww .ja v  a 2  s .com
 * @throws IOException
 * @throws HttpException
 * @throws SQLException
 */
public static boolean parseRequestByFile(String fileName, ServletContext context)
        throws IOException, HttpException, SQLException {

    log.info("In Parse Request by file");
    boolean check = false;
    HttpMessageParser requestParser;
    List<HttpRequest> request = new ArrayList<HttpRequest>();

    @SuppressWarnings("resource")
    BufferedReader br = new BufferedReader(new FileReader(fileName));

    List<String> requestList = new ArrayList<String>();
    String requestString = "";
    String line = "";
    line = br.readLine();
    int i = 0;
    while (line != null) {

        if (line.startsWith("GET") || line.startsWith("POST")) {
            if (i == 0) {
                i = 1;
            } else {
                requestList.add(requestString);
            }
            requestString = "";
            requestString = "    " + requestString + line + "\r\n";
        } else {
            if (line.contains(":")) {
                requestString = requestString + line + "\r\n";
            } else if (!line.equals("")) {
                requestString = requestString + "SSRG: " + line + "\r\n";
            }

        }
        line = br.readLine();
    }
    for (String string : requestList) {

        SessionInputBuffer inbuffer = new FileInputBuffer(string, 1024, new BasicHttpParams());
        requestParser = HttpRequestParser.createRequestParser(inbuffer, new DefaultHttpRequestFactory(),
                new BasicHttpParams());
        HttpRequest httpRequest = HttpRequestParser.receiveRequestHeaderByFile(requestParser);
        request.add(httpRequest);
    }

    ArrayList<String> urls = null;
    DOProfile profile = new DOProfile(context);
    profile.insertRequest(request);
    log.info("Rquest Inserted");

    urls = (ArrayList<String>) profile.getUrl();
    if (urls.size() > 0) {
        check = true;
        profile.insertPairs(urls);
    } else {
        check = false;
    }

    log.info("Pairs inserted");

    return check;

}

From source file:org.siddhiesb.transport.http.conn.ServerConnFactory.java

public ServerConnFactory(final HttpRequestFactory requestFactory, final ByteBufferAllocator allocator,
        final org.siddhiesb.transport.http.conn.SSLContextDetails ssl,
        final Map<InetSocketAddress, org.siddhiesb.transport.http.conn.SSLContextDetails> sslByIPMap,
        final HttpParams params) {
    super();//w w w  .ja v a2s  .c  o  m
    this.requestFactory = requestFactory != null ? requestFactory : new DefaultHttpRequestFactory();
    this.allocator = allocator != null ? allocator : new HeapByteBufferAllocator();
    this.ssl = ssl;
    this.sslByIPMap = sslByIPMap != null
            ? new ConcurrentHashMap<InetSocketAddress, org.siddhiesb.transport.http.conn.SSLContextDetails>(
                    sslByIPMap)
            : null;
    this.params = params != null ? params : new BasicHttpParams();
}

From source file:com.alibaba.openapi.client.rpc.AbstractHttpRequestBuilder.java

public AbstractHttpRequestBuilder(ClientPolicy clientPolicy) {
    requestFactory = new DefaultHttpRequestFactory();
    this.clientPolicy = clientPolicy;
}

From source file:org.apache.axis2.transport.nhttp.SSLServerIOEventDispatch.java

public void connected(final IOSession session) {

    SSLIOSession sslSession = new SSLIOSession(session, this.sslcontext, this.sslHandler);

    LoggingNHttpServerConnection conn = new LoggingNHttpServerConnection(new LoggingIOSession(sslSession),
            new DefaultHttpRequestFactory(), new HeapByteBufferAllocator(), this.params);

    session.setAttribute(NHTTP_CONN, conn);
    session.setAttribute(SSL_SESSION, sslSession);

    this.handler.connected(conn);

    try {/*www .j  a  v  a  2 s . c o m*/
        sslSession.bind(SSLMode.SERVER, this.params);
    } catch (SSLException ex) {
        this.handler.exception(conn, ex);
        sslSession.shutdown();
    }
}

From source file:org.deviceconnect.message.http.impl.factory.HttpMessageFactory.java

/**
 * ??HTTP??./*from  w  ww  . j av  a  2  s.c  om*/
 * @param requestline 
 * @return HTTP
 * @throws MethodNotSupportedException ??????
 */
public HttpMessage newHttpMessage(final RequestLine requestline) throws MethodNotSupportedException {
    mLogger.entering(this.getClass().getName(), "newHttpMessage", requestline);
    mLogger.exiting(this.getClass().getName(), "newHttpMessage");
    return (new DefaultHttpRequestFactory()).newHttpRequest(requestline);
}

From source file:org.commonjava.indy.httprox.handler.ProxyRequestReader.java

@Override
public void handleEvent(final ConduitStreamSourceChannel sourceChannel) {
    boolean sendResponse = false;
    try {/*from w  w w  . j  a va  2  s .  co  m*/
        final int read = doRead(sourceChannel);

        if (read <= 0) {
            logger.debug("Reads: {} ", read);
            return;
        }

        byte[] bytes = bReq.toByteArray();

        if (sslTunnel != null) {
            logger.debug("Send to ssl tunnel, {}, bytes:\n\n {}\n", new String(bytes),
                    Hex.encodeHexString(bytes));
            directTo(sslTunnel);
            return;
        }

        logger.debug("Request in progress is:\n\n{}", new String(bytes));

        if (headDone) {
            logger.debug("Request done. parsing.");
            MessageConstraints mc = MessageConstraints.DEFAULT;
            SessionInputBufferImpl inbuf = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 1024);
            HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
            LineParser lp = new BasicLineParser();

            DefaultHttpRequestParser requestParser = new DefaultHttpRequestParser(inbuf, lp, requestFactory,
                    mc);

            inbuf.bind(new ByteArrayInputStream(bytes));

            try {
                logger.debug("Passing parsed http request off to response writer.");
                HttpRequest request = requestParser.parse();
                logger.debug("Request contains {} header: '{}'", ApplicationHeader.authorization.key(),
                        request.getHeaders(ApplicationHeader.authorization.key()));

                writer.setHttpRequest(request);
                sendResponse = true;
            } catch (ConnectionClosedException e) {
                logger.warn("Client closed connection. Aborting proxy request.");
                sendResponse = false;
                sourceChannel.shutdownReads();
            } catch (HttpException e) {
                logger.error("Failed to parse http request: " + e.getMessage(), e);
                writer.setError(e);
            }
        } else {
            logger.debug("Request not finished. Pausing until more reads are available.");
            sourceChannel.resumeReads();
        }
    } catch (final IOException e) {
        writer.setError(e);
        sendResponse = true;
    }

    if (sendResponse) {
        sinkChannel.resumeWrites();
    }
}

From source file:org.apache.axis2.transport.http.server.AxisHttpConnectionImpl.java

public AxisHttpConnectionImpl(final Socket socket, final HttpParams params) throws IOException {
    super();//from w  w w . j  a  v  a  2  s .  c  o  m
    if (socket == null) {
        throw new IllegalArgumentException("Socket may not be null");
    }
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
    socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));

    int linger = HttpConnectionParams.getLinger(params);
    if (linger >= 0) {
        socket.setSoLinger(linger > 0, linger);
    }

    int buffersize = HttpConnectionParams.getSocketBufferSize(params);
    this.socket = socket;
    this.outbuffer = new SocketOutputBuffer(socket, buffersize, params);
    this.inbuffer = new SocketInputBuffer(socket, buffersize, params);
    this.contentLenStrategy = new StrictContentLengthStrategy();
    this.requestParser = new HttpRequestParser(this.inbuffer, null, new DefaultHttpRequestFactory(), params);
    this.responseWriter = new HttpResponseWriter(this.outbuffer, null, params);
}

From source file:com.jeny.atmosphere.integration.websocket.RawWebSocketProtocol.java

/**
 * Since protocol is simple http tunneling over web socket using RAW approach it parses web socket body as string which represents http request by HTTP standard.
 * It takes all parameters from passed http request and takes some parameters (like Cookies, Content Type and etc) from initial http request if
 * they are missing in the passed http request. On the client side is supposed that it will take passed parameters and missing parameters from
 * browser context during form http request (like Accept-Charset, Accept-Encoding, User-Agent and etc).
 * {@inheritDoc}//  w  w  w .  j  a  v  a  2 s . co m
 */
@Override
public List<AtmosphereRequest> onMessage(WebSocket webSocket, String d) {

    HttpRequest request = null;
    try {
        HttpParams params = new BasicHttpParams();
        SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, params);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, null,
                requestFactory, params);
        requestParser.fillBuffer(newChannel(d, "UTF-8"));
        request = requestParser.parse();

    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (HttpException e) {
        throw new RuntimeException(e);
    }

    AtmosphereResourceImpl resource = (AtmosphereResourceImpl) webSocket.resource();
    if (resource == null) {
        logger.error("Invalid state. No AtmosphereResource has been suspended");
        return null;
    }
    AtmosphereRequest initialRequest = resource.getRequest();

    Map<String, Object> attributesMap = new HashMap<String, Object>();
    attributesMap.put(FrameworkConfig.WEBSOCKET_SUBPROTOCOL, FrameworkConfig.SIMPLE_HTTP_OVER_WEBSOCKET);

    // Propagate the original attribute to WebSocket message.
    attributesMap.putAll(initialRequest.attributes());

    // Determine value of path info, request URI
    String pathInfo = request.getRequestLine().getUri();
    UriBuilder pathInfoUriBuilder = UriBuilder.fromUri(pathInfo);
    URI pathInfoUri = pathInfoUriBuilder.build();
    String requestURI = pathInfoUri.getPath();

    // take the Method Type of passed http request
    methodType = request.getRequestLine().getMethod();

    // take the Content Type of passed http request
    contentType = request.getFirstHeader(HttpHeaders.CONTENT_TYPE) != null
            ? request.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue()
            : initialRequest.getContentType();

    // take the body of passed http request
    String body = null; // TODO how we can take it?

    // We need to create a new AtmosphereRequest as WebSocket message may arrive concurrently on the same connection.
    AtmosphereRequest atmosphereRequest = new AtmosphereRequest.Builder()
            // use HttpServletRequestWrapper to propagate passed http request parameters, headers, cookies and etc.
            // if some parameters (headers, cookies and etc) takes from initial request if they are missing.
            .request(new HttpServletRequestWrapper(initialRequest, request))

            .method(methodType).contentType(contentType).requestURI(requestURI).pathInfo(pathInfo)

            .attributes(attributesMap)

            .body(d) // TODO Unfortunately org.apache.http doesn't allow to take a body need to find workaround
            .destroyable(destroyable).build();

    List<AtmosphereRequest> list = new ArrayList<AtmosphereRequest>();
    list.add(atmosphereRequest);

    return list;
}

From source file:de.hshannover.f4.trust.iron.mapserver.communication.http.BasicAccessAuthenticationTest.java

private HttpRequest getHttpRequest(String user, String pass) {
    HttpRequestFactory factory = new DefaultHttpRequestFactory();
    HttpRequest req = null;/*from  ww w .java  2s.  c  om*/
    String base64 = new String(Base64.encodeBase64(user.concat(":").concat(pass).getBytes()));
    try {
        req = factory
                .newHttpRequest(new BasicRequestLine("POST", "https://localhost:8444/", HttpVersion.HTTP_1_1));
        req.addHeader("Accept-Encoding", "gzip,deflate");
        req.addHeader("Content-Type", "application/soap+xml;charset=UTF-8");
        req.addHeader("User-Agent", "IROND Testsuite/1.0");
        req.addHeader("Host", "localhost:8444");
        req.addHeader("Content-Length", "198");
        req.addHeader("Authorization", "Basic " + base64);
    } catch (MethodNotSupportedException e) {
        e.printStackTrace();
    }
    return req;
}