Examples of HTTPRequest

Otherwise, the HTTP request will go directly to the host:
header "Connection" or "Proxy-Connection"
The HttpRequest sets the appropriate connection header to "Keep-Alive" to keep alive the connection to the host or proxy (respectively). By setting the appropriate connection header, the user can control whether the HttpRequest tries to use Keep-Alives.
header "Host"
The HTTP/1.1 protocol requires that the "Host" header be set to the name of the machine being contacted. By default, this is derived from the URL used to construct the HttpRequest, and is set automatically if the user does not set it.
header "Content-Length"
If the user calls getOutputStream and writes some data to it, the "Content-Length" header will be set to the amount of data that has been written at the time that connect is called.
Once all data has been read from the remote host, the underlying socket may be automatically recycled and used again for subsequent requests to the same remote host. If the user is not planning on reading all the data from the remote host, the user should call close to release the socket. Although it happens under the covers, the user should be aware that if an IOException occurs or once data has been read normally from the remote host, close is called automatically. This is to ensure that the minimal number of sockets are left open at any time.

The input stream that getInputStream provides automatically hides whether the remote host is providing HTTP/1.1 "chunked" encoding or regular streaming data. The user can simply read until reaching the end of the input stream, which signifies that all the available data from this request has been read. If reading from a "chunked" source, the data is automatically de-chunked as it is presented to the user. Currently, no access is provided to the underlying raw input stream. @author Colin Stevens (colin.stevens@sun.com) @version 2.5

  • twitter4j.internal.http.HttpRequest

  • Examples of org.safehaus.asyncweb.http.HttpRequest

            return InvocationResponse.CONTINUE;
        }

        private void sendAsyncResponse(MessageContext msgContext, OMOutputFormat format, OMElement dataOut) throws AxisFault {

            HttpRequest request = (HttpRequest) msgContext.getProperty(Constants.OUT_TRANSPORT_INFO);
            HttpResponse response = request.createHttpResponse();

            response.setStatus(ResponseStatus.OK);

            String contentType;
            Object contentTypeObject = msgContext.getProperty(Constants.Configuration.CONTENT_TYPE);
            if (contentTypeObject != null) {
                contentType = (String) contentTypeObject;
            } else if (msgContext.isDoingREST()) {
                contentType = HTTPConstants.MEDIA_TYPE_APPLICATION_XML;
            } else {
                contentType = format.getContentType();
                format.setSOAP11(msgContext.isSOAP11());
            }

            response.setHeader("Content-Type:",
                contentType + "; charset=" + format.getCharSetEncoding());
            //response.setHeader("Content-Type:", "text/xml; charset=UTF-8");

            OutputStream out = response.getOutputStream();

            format.setDoOptimize(msgContext.isDoingMTOM());
            try {
                dataOut.serializeAndConsume(out, format);
            } catch (Exception e) {
                throw new AxisFault(e);
            }

            request.commitResponse(response);
        }
    View Full Code Here

    Examples of org.sentinel.servers.http.protocol.HTTPRequest

        @Test
        public void testGetParam() throws MalformedURLException
        {
            ApplicationImpl impl = new ApplicationImpl();
            impl.request = new HTTPRequest();
            assertNull(impl.getParam("test", null));
           
            URL url = new URL("http://localhost/something?test=1&test2=abc");
            impl.request.setRequestURL(url);
            assertEquals("1", impl.getParam("test"));
    View Full Code Here

    Examples of org.springframework.http.HttpRequest

        this.accessToken = accessToken;
        this.oauth2Version = oauth2Version;
      }
     
      public ClientHttpResponse intercept(final HttpRequest request, final byte[] body, ClientHttpRequestExecution execution) throws IOException {
        HttpRequest protectedResourceRequest = new HttpRequestDecorator(request);
        protectedResourceRequest.getHeaders().set("Authorization", oauth2Version.getAuthorizationHeaderValue(accessToken));
        return execution.execute(protectedResourceRequest, body);
      }
    View Full Code Here

    Examples of org.webbitserver.HttpRequest

        @Test
        public void matchesRequestWithFullUri() throws Exception {
            HttpHandler handler = mock(HttpHandler.class);
            PathMatchHandler pmh = new PathMatchHandler("/hello", handler);

            HttpRequest req = new StubHttpRequest("http://host.com:8080/hello");
            HttpResponse res = new StubHttpResponse();
            HttpControl ctl = new StubHttpControl();

            pmh.handleHttpRequest(req, res, ctl);
            verify(handler).handleHttpRequest(req, res, ctl);
    View Full Code Here

    Examples of org.xlightweb.HttpRequest

        // create exchange
        ClientExchange exchange = new ClientExchange(this, getWorkerpool());
       
        // create data body sink / data body source pair
        IBodySinkPair pair = HttpClientConnection.newBodySinkPair(null, exchange.getExecutor(), requestHeader.getCharacterEncoding());
        IHttpRequest request = new HttpRequest(requestHeader, pair.getBodyDataSource());

        // init and process it
        exchange.init(request, responseHandler);
        httpClientRequestHandlerChain.onRequest(exchange);
         
    View Full Code Here

    Examples of placeholder.http.HttpRequest

          // do nothing
        }

        // request
        try {
          HttpRequest request = new HttpRequest("http://62.75.144.112/~heiko/placeholder/set.php", HttpMethod.POST);
          request.addPostFields(postFields);
          request.send();
          if (request.getConnection().getResponseCode() != 200) {
            throw new HttpWebsiteResultQueueFlushException("Error while sending website results to server.", request, request.getConnection().getResponseMessage(), request.getConnection().getResponseCode());
          }
        } catch (Exception e) {
          throw new WebsiteResultQueueFlushException(e);
        }
       
    View Full Code Here

    Examples of pt.opensoft.http.HttpRequest

    *
    */
    public class CookieUtils {

      public static String getCookieValue(Request request, String cookieName) {
        HttpRequest httpRequest = (HttpRequest) request;
        Cookie[] cookies = httpRequest.getCookies();
        if (cookies == null) return null;
        for (int i = 0; i < cookies.length; i++) {
          String name = cookies[i].getName();
          if (name.equals(cookieName)) {
            String value = cookies[i].getValue();
    View Full Code Here

    Examples of slash.navigation.rest.HttpRequest

        @Test
        public void testUpdateWithWrongPassword() throws Exception {
            Post request1 = createCategory("Upload", "Interesting");
            request1.executeAsString();
            String key = parseCategoryKey(request1.getLocation());
            HttpRequest request2 = updateCategory(key, "Interesting" + System.currentTimeMillis(), "user-does-not-exist", "password-is-wrong");
            assertNull(request2.executeAsString());
            assertEquals(401, request2.getStatusCode());
            assertFalse(request2.isSuccessful());
            assertTrue(request2.isUnAuthorized());
        }
    View Full Code Here

    Examples of sunlabs.brazil.util.http.HttpRequest

      if (!request.query.equals("")) {
          url += "?" + request.query;
      }

      HttpRequest target = new HttpRequest(requestPrefix + url);
      // System.out.println("Fetching: " + requestPrefix + url);
      if (proxyHost != null) {
          target.setProxy(proxyHost, proxyPort);
      }
      target.setMethod(request.method);

      HttpRequest.removePointToPointHeaders(request.headers, false);
            request.headers.remove("if-modified-since")// wrong spot XXX
      request.headers.copyTo(target.requestHeaders);

      /* XXX This doesn't belong here! - the proxy should do it */
      target.requestHeaders.remove("host");
      if (tokens != null) {
          target.addHeaders(tokens, request.props);
      }
      target.requestHeaders.putIfNotPresent("Host",host);

            boolean code=true;
      try {
          if (request.postData != null) {
        OutputStream out = target.getOutputStream();
        out.write(request.postData);
        out.close();
          }

          // Connect to target and read the response headers

          target.connect();
          // System.out.println("Got headers: " + target.responseHeaders);
          HttpRequest.removePointToPointHeaders(target.responseHeaders, true);
          target.responseHeaders.copyTo(request.responseHeaders);

          // Now filter the output, writing the header and content if true

          request.log(Server.LOG_DIAGNOSTIC,
          "  Response headers: " +  target.responseHeaders);
          if (shouldFilter(request.responseHeaders)) {
       
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        target.getInputStream().copyTo(out);

        request.log(Server.LOG_DIAGNOSTIC,
          "  parsing/modifying " + out.size() + " bytes");
        byte[] content = modifyContent(request, out.toByteArray());

        if (content == null) {  // This is wrong!!
            request.log(Server.LOG_DIAGNOSTIC,
              "  null content, returning false");
            code=false;
        } else {
            request.sendResponse(content, null);
        }
          } else {
        request.log(Server.LOG_DIAGNOSTIC, "Delivering normal content");
        request.sendResponse(target.getInputStream(),
          target.getContentLength(), null,
          target.getResponseCode());
          }
            } catch (InterruptedIOException e) {
                /*
                 * Read timeout while reading from the remote side.  We use a
                 * read timeout in case the target never responds.
                 */
                request.sendError(408, "Timeout / No response");
            } catch (UnknownHostException e) {
                request.sendError(503, urlPrefix +  " Not reachable");
            } catch (ConnectException e) {
                request.sendError(500, "Connection refused");
      } catch (IOException e) {
          request.sendError(500, "Error retrieving response: " + e);
          e.printStackTrace();
            } finally {
                target.close();
          // System.out.println("Finally (proxy): " + code);
            }
      return code;
        }
    View Full Code Here

    Examples of twitter4j.internal.http.HttpRequest

                new HttpParameter("q", place),
                new HttpParameter("flags", "J")
            };
            Map<String, String> header = new HashMap<>();
            header.put("Accept", "application/json");
            HttpRequest req = new HttpRequest(RequestMethod.GET, "http://where.yahooapis.com/geocode", para, null, header);
            HttpResponse resp = client.request(req);
            requestCounter++;
            return resp.asJSONObject().getJSONObject("ResultSet");
        }
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. 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.