Package org.apache.tuscany.sca.common.http

Examples of org.apache.tuscany.sca.common.http.HTTPContext


           
            CORSHeaderProcessor.processCORS(binding.getCORSConfiguration(), request, response);
        }

        //create context
        HTTPContext bindingContext = new HTTPContext();
        bindingContext.setHttpRequest(request);
        bindingContext.setHttpResponse(response);
       

        try {
            //store in thread local
            ThreadHTTPContext.setHTTPContext(bindingContext);
View Full Code Here


            throw new ServiceRuntimeException(e);
        }
    }

    private Message invokeRequest(Message msg) throws IOException, SAXException {
        HTTPContext context = msg.getBindingContext();
        HttpServletRequest servletRequest = context.getHttpRequest();
        if ("GET".equals(servletRequest.getMethod())) {
            msg.setBody(getRequestFromQueryString(msg.getOperation(), servletRequest));
        } else {
            msg.setBody(new Object[]{domHelper.load(read(servletRequest))});
        }
View Full Code Here

        this.messageFactory = messageFactory;
    }
   
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HTTPContext bindingContext = new HTTPContext();
        bindingContext.setHttpRequest(request);
        bindingContext.setHttpResponse(response);
        Message msg = messageFactory.createMessage();
        msg.setBindingContext(bindingContext);
        Message responseMessage = wire.invoke(msg);
        // return response to client
        if (responseMessage.isFault()) {
View Full Code Here

        }
        return msg;
    }

    private Message invokeResponse(Message msg) throws IOException {
        HTTPContext context = msg.getBindingContext();
        HttpServletResponse servletResponse = context.getHttpResponse();

        servletResponse.setContentType("text/xml");
       
        Object o = msg.getBody();
        if (msg.isFault()) {
View Full Code Here

        this.next = next;
    }

    public Message invoke(Message msg) {

        HTTPContext bindingContext = (HTTPContext)msg.getBindingContext();

        // By-pass the operation selector
        if (bindingContext == null) {
            return getNext().invoke(msg);
        }

        String path = null;
        try {
            path = URLDecoder.decode(HTTPUtils.getRequestPath(bindingContext.getHttpRequest()), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException(e);
        }

        if (path.startsWith("/")) {
            path = path.substring(1);
        }

        List<Operation> operations =
            filterOperationsByHttpMethod(interfaceContract, bindingContext.getHttpRequest().getMethod());

        Operation operation = findOperation(path, operations);

        final JavaOperation javaOperation = (JavaOperation)operation;
        final Method method = javaOperation.getJavaMethod();

        if (path != null && path.length() > 0) {
            if (method.getAnnotation(Path.class) != null) {
                msg.setBody(new Object[] {path});
            }
        }

        // FIXME: [rfeng] We should follow JAX-RS rules to identify the entity parameter
        Class<?>[] paramTypes = method.getParameterTypes();
        if (paramTypes.length == 1) {
            Class<?> type = paramTypes[0];
            InputStream is = (InputStream)((Object[])msg.getBody())[0];
            Object target = convert(is, bindingContext.getHttpRequest().getContentType(), type);
            msg.setBody(new Object[] {target});
        } else if (paramTypes.length == 0) {
            msg.setBody(null);
        }
View Full Code Here

            throw new ServiceRuntimeException(e);
        }
    }

    private Message invokeRequest(Message msg) throws IOException {
        HTTPContext context = msg.getBindingContext();
        HttpServletRequest servletRequest = context.getHttpRequest();
        if ("GET".equals(servletRequest.getMethod())) {
            msg.setBody(getRequestFromQueryString(msg.getOperation(), servletRequest));
        } else {
            msg.setBody(getRequestFromPost(msg.getOperation(), servletRequest));
        }
View Full Code Here

        }
        return os.toArray();
    }

    private Message invokeResponse(Message msg) throws IOException {
        HTTPContext context = msg.getBindingContext();
        HttpServletRequest servletRequest = context.getHttpRequest();
        HttpServletResponse servletResponse = context.getHttpResponse();
       
        if (msg.isFault()) {           
            servletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, String.valueOf(msg.getBody()));
        } else {
            String response = getResponseAsString(servletRequest, servletResponse, msg.getBody());
View Full Code Here

    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        if (binding.isCORS()) {
            CORSHeaderProcessor.processCORS(binding.getCORSConfiguration(), request, response);
        }
        if( binding.getOperationSelector() != null || binding.getRequestWireFormat() != null) {
            HTTPContext bindingContext = new HTTPContext();
            bindingContext.setHttpRequest(request);
            bindingContext.setHttpResponse(response);

            // Dispatch the service interaction to the service invoker
            Message requestMessage = messageFactory.createMessage();
            requestMessage.setBindingContext(bindingContext);
View Full Code Here

    public void setNext(Invoker next) {
        this.next = next;
    }

    public Message invoke(Message msg) {
        HTTPContext bindingContext = (HTTPContext) msg.getBindingContext();
        if (bindingContext == null) {
            return getNext().invoke(msg);
        }


        if (binding.getRequestWireFormat() instanceof XMLWireFormat) {
            if( isPayloadSupported(bindingContext.getHttpRequest().getMethod()) && msg.getBody() != null) {
                msg = invokeRequest(bindingContext, msg);
            }
        }

        msg = getNext().invoke(msg);
View Full Code Here

    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        if( binding.getOperationSelector() != null || binding.getRequestWireFormat() != null) {
            HTTPContext bindingContext = new HTTPContext();
            bindingContext.setHttpRequest(request);
            bindingContext.setHttpResponse(response);

            // Dispatch the service interaction to the service invoker
            Message requestMessage = messageFactory.createMessage();
            requestMessage.setBindingContext(bindingContext);
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.common.http.HTTPContext

Copyright © 2018 www.massapicom. 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.