protected HttpResponse buildFailureResponse(RequestLine requestLine, MuleMessage message) throws TransformerException { EndpointURI uri = endpoint.getEndpointURI(); String failedPath = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + message.getProperty(HttpConnector.HTTP_REQUEST_PATH_PROPERTY); if (logger.isDebugEnabled()) { logger.debug("Failed to bind to " + failedPath); } HttpResponse response = new HttpResponse(); response.setStatusLine(requestLine.getHttpVersion(), HttpConstants.SC_NOT_FOUND); response.setBody(HttpMessages.cannotBindToAddress(failedPath).toString()); RequestContext.setEvent( new DefaultMuleEvent( new DefaultMuleMessage(response), endpoint, new DefaultMuleSession(service, connector.getMuleContext()), true)); // The DefaultResponseTransformer will set the necessary headers return transformResponse(response); }
private void sendExpect100(Map headers, RequestLine requestLine) throws TransformerException, IOException { // respond with status code 100, for Expect handshake // according to rfc 2616 and http 1.1 // the processing will continue and the request will be fully // read immediately after if (HttpConstants.HTTP11.equals(headers.get(HttpConnector.HTTP_VERSION_PROPERTY))) { // just in case we have something other than String in // the headers map String expectHeaderValue = ObjectUtils.toString(headers.get(HttpConstants.HEADER_EXPECT)).toLowerCase(); if (HttpConstants.HEADER_EXPECT_CONTINUE_REQUEST_VALUE.equals(expectHeaderValue)) { HttpResponse expected = new HttpResponse(); expected.setStatusLine(requestLine.getHttpVersion(), HttpConstants.SC_CONTINUE); final DefaultMuleEvent event = new DefaultMuleEvent( new DefaultMuleMessage(expected), endpoint, new DefaultMuleSession(service, connector.getMuleContext()), true); RequestContext.setEvent(event); conn.writeResponse(transformResponse(expected)); } } }
protected HttpResponse doBad(RequestLine requestLine) throws MuleException { MuleMessage message = new DefaultMuleMessage(NullPayload.getInstance()); MuleEvent event = new DefaultMuleEvent( message, endpoint, new DefaultMuleSession(message, new NullSessionHandler(), connector.getMuleContext()), true); OptimizedRequestContext.unsafeSetEvent(event); HttpResponse response = new HttpResponse(); response.setStatusLine(requestLine.getHttpVersion(), HttpConstants.SC_BAD_REQUEST); response.setBody(HttpMessages.malformedSyntax().toString() + HttpConstants.CRLF); return transformResponse(response); }
protected HttpResponse doOtherValid(RequestLine requestLine, String method) throws MuleException { MuleMessage message = new DefaultMuleMessage(NullPayload.getInstance()); MuleEvent event = new DefaultMuleEvent( message, endpoint, new DefaultMuleSession(message, new NullSessionHandler(), connector.getMuleContext()), true); OptimizedRequestContext.unsafeSetEvent(event); HttpResponse response = new HttpResponse(); response.setStatusLine(requestLine.getHttpVersion(), HttpConstants.SC_METHOD_NOT_ALLOWED); response.setBody(HttpMessages.methodNotAllowed(method).toString() + HttpConstants.CRLF); return transformResponse(response); }
protected Map parseHeaders(HttpRequest request) throws MalformedCookieException { RequestLine requestLine = request.getRequestLine(); Map headers = new HashMap(); for (Iterator rhi = request.getHeaderIterator(); rhi.hasNext(); ) { Header header = (Header) rhi.next(); String headerName = header.getName(); Object headerValue = header.getValue(); // fix Mule headers? if (headerName.startsWith("X-MULE")) { headerName = headerName.substring(2); } // Parse cookies? else if (headerName.equals(HttpConnector.HTTP_COOKIES_PROPERTY)) { if (enableCookies) { Cookie[] cookies = CookieHelper.parseCookies(header, cookieSpec); if (cookies.length > 0) { // yum! headerValue = cookies; } else { // bad cookies?! continue; } } else { // no cookies for you! continue; } } // accept header & value headers.put(headerName, headerValue); } headers.put(HttpConnector.HTTP_METHOD_PROPERTY, requestLine.getMethod()); headers.put(HttpConnector.HTTP_REQUEST_PROPERTY, requestLine.getUri()); headers.put(HttpConnector.HTTP_VERSION_PROPERTY, requestLine.getHttpVersion().toString()); headers.put(HttpConnector.HTTP_COOKIE_SPEC_PROPERTY, cookieSpec); return headers; }