/** * parses the request into the 3 different parts, request, headers, and body * * @param input the data input for this page * @throws java.io.IOException if an exception is thrown */ protected void readMessage(InputStream input) throws IOException { DataInput in = new DataInputStream(input); readRequestLine(in); readHeaders(in); readBody(in); parameters.putAll(this.getFormParameters()); parameters.putAll(this.getQueryParameters()); //temp-debug------------------------------------------- // System.out.println("******************* HEADERS ******************"); // for (Map.Entry<String, String> entry : headers.entrySet()) { // System.out.println(entry); // } // System.out.println("**********************************************"); // System.out.println(new String(body)); // System.out.println("**********************************************"); //end temp-debug--------------------------------------- }
@Override public int getIntHeader(final String s) { final String header = getHeader(s); return header == null ? -1 : Integer.parseInt(header); }
public HttpSession getSession() { return getSession(true); }
@Override public void initPathFromContext(final String context) { super.initPathFromContext(context); thisContextPath = super.getContextPath(); }
@Override public Cookie[] getCookies() { if (cookies != null) return toCookies(cookies); cookies = new HashMap<String, String>(); final String cookieHeader = getHeader(HEADER_COOKIE); if (cookieHeader == null) return toCookies(cookies); final StringTokenizer tokens = new StringTokenizer(cookieHeader, ";"); while (tokens.hasMoreTokens()) { final StringTokenizer token = new StringTokenizer(tokens.nextToken(), "="); final String name = token.nextToken(); final String value = token.nextToken(); cookies.put(name, value); } return toCookies(cookies); }
private HttpResponseImpl process(final Socket socket, final URI socketURI, final InputStream in) throws OpenEJBException { final HttpRequestImpl req = new HttpRequestImpl(socketURI); final HttpResponseImpl res = new HttpResponseImpl(); if (!req.readMessage(in)) { return res; req.print(log, indent); String location = null; try { uri = req.getURI(); location = uri.getPath(); final int querry = location.indexOf("?"); req.setAttribute("openejb_response", res); req.setAttribute("openejb_socket", socket); listener.onMessage(req, res); } catch (Throwable t) { final boolean async = "true".equals(req.getAttribute("openejb_async")); return !async ? res : null;
length = parseContentLength(); contentType = getHeader(HttpRequest.HEADER_CONTENT_TYPE); final boolean hasBody = hasBody(); if (hasBody && contentType != null && (contentType.startsWith(FORM_URL_ENCODED) || contentType.startsWith(MULTIPART_FORM_DATA))) { String rawParams; body = readContent(in); this.in = new ServletByteArrayIntputStream(body); rawParams = new String(body); } else if (hasBody && CHUNKED.equals(getHeader(TRANSFER_ENCODING))) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); body = readContent(in); this.in = new ServletByteArrayIntputStream(body); } else {
@Override public String getRemoteHost() { return getURI().getHost(); }
private HttpResponseImpl process(final URI socketURI, final InputStream in) throws OpenEJBException { final HttpRequestImpl req = new HttpRequestImpl(socketURI); final HttpResponseImpl res = new HttpResponseImpl(); req.readMessage(in); req.print(log, indent); String location = null; try { uri = req.getURI(); location = uri.getPath(); final int querry = location.indexOf("?");
final WebContext web = findWebContext(request.getURI() == null ? request.getContextPath() : request.getURI().getPath()); if (web != null) { httpRequest.setApplication(web); httpRequest.initPathFromContext(ctx); wbc = web.getWebbeansContext() != null ? web.getWebbeansContext() : web.getAppContext().getWebBeansContext(); } else { httpRequest.setAttribute("openejb_owb_context", wbc); initCdi(wbc, httpRequest).init(); } finally { if (wbc != null) { HttpRequestImpl.class.cast(request).destroy();
/** * reads and parses the request line * * @param in the input to be read * @throws java.io.IOException if an exception is thrown */ private void readRequestLine(final DataInput in) throws IOException { final String line; try { line = in.readLine(); // System.out.println(line); } catch (final Exception e) { throw new IOException("Could not read the HTTP Request Line :" + e.getClass().getName() + " : " + e.getMessage()); } final StringTokenizer lineParts = new StringTokenizer(line, " "); /* [1] Parse the method */ parseMethod(lineParts); /* [2] Parse the URI */ parseURI(lineParts); }
length = parseContentLength(); contentType = getHeader(HttpRequest.HEADER_CONTENT_TYPE); body = readContent(in); rawParams = new String(body); } catch (Exception e) { body = readContent(in); this.in = new ByteArrayInputStream(body); } else {
private HttpResponseImpl process(URI socketURI, InputStream in) throws OpenEJBException { HttpRequestImpl req = new HttpRequestImpl(socketURI); HttpResponseImpl res = new HttpResponseImpl(); req.readMessage(in); res.setRequest(req); } catch (Throwable t) { String location = null; try { uri = req.getURI(); location = uri.getPath(); int querry = location.indexOf("?");
@Override public void forward(final ServletRequest request, final ServletResponse response) throws ServletException, IOException { if (!HttpRequestImpl.class.isInstance(request)) { if (HttpServletResponse.class.isInstance(response)) { HttpServletResponse.class.cast(response).sendError(HttpServletResponse.SC_NOT_FOUND); } return; } final HttpRequestImpl cast = HttpRequestImpl.class.cast(request); final HttpRequestImpl httpRequest = new HttpRequestImpl(cast.socketURI); httpRequest.uri = cast.uri; httpRequest.parameters.putAll(cast.parameters); httpRequest.initPathFromContext(cast.contextPath); httpRequest.initServletPath(path); httpRequest.method = cast.method; try { SystemInstance.get().getComponent(HttpListenerRegistry.class).onMessage( httpRequest, HttpResponse.class.isInstance(response)? HttpResponse.class.cast(response) : new ServletResponseAdapter(HttpServletResponse.class.cast(response))); } catch (final Exception e) { throw new ServletException(e.getMessage(), e); } }
HttpRequestImpl mockRequest = null; try { mockRequest = new HttpRequestImpl(new URI("http://mock/")); mockRequest.parseURI(new StringTokenizer("mock\n")); // will do http://mock/mock, we don't really care mock = mockRequest; } catch (final Exception e) {
req.setUri(HttpRequestImpl.class.cast(request).getURI()); req.setAttribute("openejb_async_dispatch", true); registry.onMessage(req, HttpResponse.class.isInstance(response) ? HttpResponse.class.cast(response) : new ServletResponseAdapter(HttpServletResponse.class.cast(response))); complete();
@Override public void onMessage(final HttpRequest request, final HttpResponse response) throws Exception { if (request instanceof HttpRequestImpl) { final HttpRequestImpl req = (HttpRequestImpl) request; req.initPathFromContext((!context.startsWith("/") ? "/" : "") + context); } delegate.service(request, response); }
public void addQueryParams(final String query) { parseQueryParams(query); parameters.putAll(queryParams); // a merge would be better }
@Override public void onMessage(final HttpRequest httpRequest, final HttpResponse httpResponse) throws Exception { // fix the address (to manage multiple connectors) if (HttpRequestImpl.class.isInstance(httpRequest)) { final HttpRequestImpl requestImpl = HttpRequestImpl.class.cast(httpRequest); requestImpl.initPathFromContext(context); requestImpl.initServletPath(servlet); } boolean matchedStatic = false; if (TRY_STATIC_RESOURCES || (matchedStatic = matchPath(httpRequest))) { final String pathInfo = httpRequest.getPathInfo(); if (serveStaticContent(httpRequest, httpResponse, pathInfo)) { if (matchedStatic) { // we should have gotten the resource throw new ServletException("Static resource " + pathInfo + " is not available"); } return; // ok that's a surely rest service } } doInvoke(httpRequest, httpResponse); }
length = parseContentLength(); contentType = getHeader(HttpRequest.HEADER_CONTENT_TYPE); final boolean hasBody = hasBody(); if (hasBody && FORM_URL_ENCODED.equals(contentType)) { final String rawParams; body = readContent(in); this.in = new ServletByteArrayIntputStream(body); rawParams = new String(body); body = readContent(in); this.in = new ServletByteArrayIntputStream(body); } else {