Java 类org.apache.camel.component.http.HttpMessage 实例源码

项目:beyondj    文件:AttachmentHttpBinding.java   
@Override
protected void populateAttachments(HttpServletRequest request, HttpMessage message) {
    Object object = request.getAttribute("org.eclipse.jetty.servlet.MultiPartFile.multiPartInputStream");
    if (object instanceof MultiPartInputStreamParser) {
        MultiPartInputStreamParser parser = (MultiPartInputStreamParser)object;
        Collection<Part> parts;
        try {
            parts = parser.getParts();
            for (Part part : parts) {
                String contentType = part.getContentType();
                if (!contentType.startsWith("application/octet-stream")) {
                    continue;
                }

                DataSource ds = new PartDataSource(part);
                message.addAttachment(part.getName(), new DataHandler(ds));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
项目:beyondj    文件:JettyRestHttpBinding.java   
@Override
protected void populateRequestParameters(HttpServletRequest request, HttpMessage message) throws Exception {
    super.populateRequestParameters(request, message);

    String path = request.getPathInfo();
    if (path == null) {
        return;
    }

    // in the endpoint the user may have defined rest {} placeholders
    // so we need to map those placeholders with data from the incoming request context path

    JettyHttpEndpoint endpoint = (JettyHttpEndpoint) message.getExchange().getFromEndpoint();
    String consumerPath = endpoint.getPath();

    if (useRestMatching(consumerPath)) {

        // split using single char / is optimized in the jdk
        String[] paths = path.split("/");
        String[] consumerPaths = consumerPath.split("/");

        for (int i = 0; i < consumerPaths.length; i++) {
            if (paths.length < i) {
                break;
            }
            String p1 = consumerPaths[i];
            if (p1.startsWith("{") && p1.endsWith("}")) {
                String key = p1.substring(1, p1.length() - 1);
                String value = paths[i];
                if (value != null) {
                    message.setHeader(key, value);
                }
            }
        }
    }
}
项目:signalk-server-java    文件:RestAuthProcessor.java   
@Override
public void process(Exchange exchange) throws Exception {
    // the Restlet request should be available if neeeded
    HttpServletRequest request = exchange.getIn(HttpMessage.class).getRequest();

     //HttpSession session = request.getSession();
    if(logger.isDebugEnabled())logger.debug("Session = "+request.getSession().getId());
      // Request request = exchange.getIn().getHeader(RestletConstants.RESTLET_REQUEST, Request.class);
       if("GET"==request.getMethod()){
        processGet(request, exchange);
       }else{
        exchange.getIn(HttpMessage.class).getResponse().setStatus(HttpServletResponse.SC_BAD_REQUEST);
       }
}
项目:signalk-server-java    文件:RestAuthProcessor.java   
private void processGet(HttpServletRequest request, Exchange exchange) throws Exception {
    // use Restlet API to create the response

       HttpServletResponse response = exchange.getIn(HttpMessage.class).getResponse();
       String path =  exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
       if(logger.isDebugEnabled())logger.debug("We are processing the path = "+path);

       //check valid request.
       if(path.length()<=SignalKConstants.SIGNALK_AUTH.length()){
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;
       }
      // path=path.substring(request.getRootRef().getPath().length());

       //logger.debug("We are processing the extension:"+path);
      //TODO: sort out proper security here!

       response.setContentType(MimeTypes.TEXT_PLAIN );
       //String uuid = UUID.randomUUID().toString();
       //Cookie cookie = new Cookie(Constants.SESSIONID, uuid);
      // cookie.setPath("/signalk/");
      // response.addCookie(cookie);
       //String breadcrumb = exchange.getIn().getHeader(Exchange.BREADCRUMB_ID,String.class);
       //breadcrumb = breadcrumb.substring(0,breadcrumb.lastIndexOf("-",breadcrumb.lastIndexOf("-")));
       //manager.add(cookieSetting.getValue(), cookieSetting.getValue());
       if(logger.isDebugEnabled())logger.info("Adding session = "+request.getSession().getId());
       //manager.add(request.getSession().getId(), request.getSession().getId(), Constants.OUTPUT_WS);

       // SEND RESPONSE
       //exchange.getOut().setBody(response.getEntityAsText());

       response.setStatus(HttpServletResponse.SC_OK);
       //send back
       //response.redirectSeeOther(request.getReferrerRef());

}
项目:signalk-server-java    文件:LoggerProcessor.java   
@Override
public void process(Exchange exchange) throws Exception {

    logger.debug("LoggerProcessor starts");
    HttpServletRequest request = exchange.getIn(HttpMessage.class).getRequest();
    logger.debug("Session = "+request.getSession().getId());
    HttpSession session = request.getSession();
    if (logger.isDebugEnabled()) {

        logger.debug("Request = " + exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST).getClass());
        logger.debug("Session = " + session.getId());
    }

    if (session.getId() != null) {

        String remoteAddress = request.getRemoteAddr();
        String localAddress = request.getLocalAddr();
        if(Util.sameNetwork(localAddress, remoteAddress)){
            exchange.getIn().setHeader(SignalKConstants.MSG_TYPE, SignalKConstants.INTERNAL_IP);
        }else{
            exchange.getIn().setHeader(SignalKConstants.MSG_TYPE, SignalKConstants.EXTERNAL_IP);
        }

        if (exchange.getIn().getHeader(Exchange.HTTP_METHOD).equals("GET")) {
            processGet(exchange);
        }
        if (exchange.getIn().getHeader(Exchange.HTTP_METHOD).equals("POST")) {
            processPost(exchange);
        }
    } else {
        exchange.getIn().setHeader("Location", SignalKConstants.SIGNALK_AUTH);
        exchange.getIn().setBody("Authentication Required");
    }
}
项目:signalk-server-java    文件:UploadProcessor.java   
@Override
public void process(Exchange exchange) throws Exception {

    logger.debug("UploadProcessor starts");
    HttpServletRequest request = exchange.getIn(HttpMessage.class).getRequest();
    logger.debug("Session = " + request.getSession().getId());
    HttpSession session = request.getSession();
    if (logger.isDebugEnabled()) {

        logger.debug("Request = " + exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST).getClass());
        logger.debug("Session = " + session.getId());
    }

    if (session.getId() != null) {

        String remoteAddress = request.getRemoteAddr();
        String localAddress = request.getLocalAddr();
        if (Util.sameNetwork(localAddress, remoteAddress)) {
            exchange.getIn().setHeader(SignalKConstants.MSG_TYPE, SignalKConstants.INTERNAL_IP);
        } else {
            exchange.getIn().setHeader(SignalKConstants.MSG_TYPE, SignalKConstants.EXTERNAL_IP);
        }
        if (exchange.getIn().getHeader(Exchange.HTTP_METHOD).equals("POST")) {
             processUpload(exchange);
        }
    } else {
        exchange.getIn().setHeader("Location", SignalKConstants.SIGNALK_AUTH);
        exchange.getIn().setBody("Authentication Required");
    }
}