Package org.apache.tuscany.sca.invocation

Examples of org.apache.tuscany.sca.invocation.Message


        }

        // Perform the async invocation
        Invoker headInvoker = chain.getHeadInvoker();

        Message msgContext = ThreadMessageContext.setMessageContext(msg);
        try {
            try {
                ((InvokerAsyncRequest)headInvoker).invokeAsyncRequest(msg);
            } catch (ServiceRuntimeException ex) {
                throw ex;
View Full Code Here


        } else if (path.startsWith("/")) {
            // Return a specific entry in the collection
            org.apache.abdera.model.Entry feedEntry;

            // Invoke the get operation on the service implementation
            Message requestMessage = messageFactory.createMessage();
            String id = path.substring(1);
            requestMessage.setBody(new Object[] {id});
            Message responseMessage = getInvoker.invoke(requestMessage);
            if (responseMessage.isFault()) {
                Object body = responseMessage.getBody();
                if (body.getClass().getName().endsWith(".NotFoundException")) {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                    return;
                } else {
                    throw new ServletException((Throwable)responseMessage.getBody());
                }

            }
            if (supportsFeedEntries) {
                // The service implementation returns a feed entry
                feedEntry = responseMessage.getBody();
            } else {
                // The service implementation only returns a data item, create an entry
                // from it
                Entry<Object, Object> entry = new Entry<Object, Object>(id, responseMessage.getBody());
                feedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator, abderaFactory);
            }
            // Write the Atom entry
            if (feedEntry != null) {
                String entryETag = null;
View Full Code Here

    }

    protected Feed getFeed( HttpServletRequest request ) throws ServletException {
        if (supportsFeedEntries) {
            // The service implementation supports feed entries, invoke its getFeed operation
            Message requestMessage = messageFactory.createMessage();
            Message responseMessage;
            if (request.getQueryString() != null) {
                requestMessage.setBody(new Object[] {request.getQueryString()});
                responseMessage = queryInvoker.invoke(requestMessage);
            } else {
                responseMessage = getFeedInvoker.invoke(requestMessage);
            }
            if (responseMessage.isFault()) {
                throw new ServletException((Throwable)responseMessage.getBody());
            }
            return (Feed)responseMessage.getBody();
        } else {

            // The service implementation does not support feed entries,
            // invoke its getAll operation to get the data item collection, then create
            // feed entries from the items
            Message requestMessage = messageFactory.createMessage();
            Message responseMessage;
            if (request.getQueryString() != null) {
                requestMessage.setBody(new Object[] {request.getQueryString()});
                responseMessage = queryInvoker.invoke(requestMessage);
            } else {
                responseMessage = getAllInvoker.invoke(requestMessage);
            }
            if (responseMessage.isFault()) {
                throw new ServletException((Throwable)responseMessage.getBody());
            }
            Entry<Object, Object>[] collection = (Entry<Object, Object>[])responseMessage.getBody();
            if (collection != null) {

                // Create the feed
                Feed feed = abderaFactory.newFeed();
View Full Code Here

                // Let the component implementation create it
                if (supportsFeedEntries) {

                    // The service implementation supports feed entries, pass the entry to it
                    Message requestMessage = messageFactory.createMessage();
                    requestMessage.setBody(new Object[] {feedEntry});
                    Message responseMessage = postInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    createdFeedEntry = responseMessage.getBody();
                } else {

                    // The service implementation does not support feed entries, pass the data item to it
                    Message requestMessage = messageFactory.createMessage();
                    Entry<Object, Object> entry = entry(feedEntry, itemClassType, itemXMLType, mediator);
                    requestMessage.setBody(new Object[] {entry.getKey(), entry.getData()});
                    Message responseMessage = postInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    entry.setKey(responseMessage.getBody());
                    createdFeedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator, abderaFactory);
                }

            } else if (contentType != null) {
                // Create a new media entry

                // Get incoming headers
                String title = request.getHeader("Title");
                String slug = request.getHeader("Slug");

                // Let the component implementation create the media entry
                Message requestMessage = messageFactory.createMessage();
                requestMessage.setBody(new Object[] {title, slug, contentType, request.getInputStream()});
                Message responseMessage = postMediaInvoker.invoke(requestMessage);
                if (responseMessage.isFault()) {
                    throw new ServletException((Throwable)responseMessage.getBody());
                }
                createdFeedEntry = responseMessage.getBody();

                // Transfer media info to response header.
                // Summary is a comma separated list of header properties.
                String summary = createdFeedEntry.getSummary();
                addPropertiesToHeader( response, summary );
View Full Code Here

                }

                // Let the component implementation create it
                if (supportsFeedEntries) {
                    // The service implementation supports feed entries, pass the entry to it
                    Message requestMessage = messageFactory.createMessage();
                    requestMessage.setBody(new Object[] {id, feedEntry});
                    Message responseMessage = putInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        Object body = responseMessage.getBody();
                        if (body.getClass().getName().endsWith(".NotFoundException")) {
                            response.sendError(HttpServletResponse.SC_NOT_FOUND);
                        } else {
                            throw new ServletException((Throwable)responseMessage.getBody());
                        }
                    }
                } else {
                    // The service implementation does not support feed entries, pass the data item to it
                    Message requestMessage = messageFactory.createMessage();
                    Entry<Object, Object> entry = entry(feedEntry, itemClassType, itemXMLType, mediator);
                    requestMessage.setBody(new Object[] {entry.getKey(), entry.getData()});
                    Message responseMessage = putInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        Object body = responseMessage.getBody();
                        if (body.getClass().getName().endsWith(".NotFoundException")) {
                            response.sendError(HttpServletResponse.SC_NOT_FOUND);
                        } else {
                            throw new ServletException((Throwable)responseMessage.getBody());
                        }
                    }
                }

            } else if (contentType != null) {

                // Update a media entry

                // Let the component implementation create the media entry
                Message requestMessage = messageFactory.createMessage();
                requestMessage.setBody(new Object[] {id, contentType, request.getInputStream()});
                Message responseMessage = putMediaInvoker.invoke(requestMessage);

                Object body = responseMessage.getBody();
                if (responseMessage.isFault()) {
                    if (body.getClass().getName().endsWith(".NotFoundException")) {
                        response.sendError(HttpServletResponse.SC_NOT_FOUND);
                    } else {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                }

                // Transfer content to response header.
View Full Code Here

        } else {
            id = "";
        }

        // Delete a specific entry from the collection
        Message requestMessage = messageFactory.createMessage();
        requestMessage.setBody(new Object[] {id});
        Message responseMessage = deleteInvoker.invoke(requestMessage);
        if (responseMessage.isFault()) {
            Object body = responseMessage.getBody();
            if (body.getClass().getName().endsWith(".NotFoundException")) {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            } else {
                throw new ServletException((Throwable)responseMessage.getBody());
            }
        }
    }
View Full Code Here

     */
    @Override
    public Message invoke(final Message msg) {
        String sessionId = (String) msg.getHeaders().get(Constants.RELATES_TO);
        Broadcaster broadcaster = CometSessionManager.get(sessionId);
        Message response = new MessageImpl();
        if (broadcaster == null) {
            response.setBody(Status.CLIENT_DISCONNECTED);
        } else {
            String callbackMethod = msg.getTo().getURI();
            Object[] body = msg.getBody();
            broadcaster.broadcast(callbackMethod + "($.secureEvalJSON('" + JSONUtil.encodeResponse(body[0]) + "'))");
            response.setBody(Status.OK);
        }
        return response;
    }
View Full Code Here

        String url = "/" + service + "/" + method;
        RuntimeEndpoint wire = CometEndpointManager.get(url);
        Operation operation = CometOperationManager.get(url);

        final Object[] args = JSONUtil.decodeJsonParamsForOperation(jsonData, operation);
        Message msg = createMessageWithMockedCometReference(args, sessionId, callbackMethod);
        boolean isVoidReturnType = operation.getOutputType().getLogical().isEmpty();
        if (!isVoidReturnType) {
            Object response = wire.invoke(operation, args);
            Broadcaster broadcaster = CometSessionManager.get(sessionId);
            if (broadcaster != null) {
View Full Code Here

     * @param callbackMethod
     *            method to call once a response is available
     * @return an invocation message
     */
    private Message createMessageWithMockedCometReference(Object[] args, String sessionId, String callbackMethod) {
        Message msg = new MessageImpl();
        msg.getHeaders().put(Constants.MESSAGE_ID, sessionId);
        msg.setBody(args);
        EndpointReference re = new RuntimeEndpointReferenceImpl();
        RuntimeEndpointImpl callbackEndpoint = new RuntimeEndpointImpl();
        callbackEndpoint.setURI(callbackMethod);
        re.setCallbackEndpoint(callbackEndpoint);
        msg.setFrom(re);
        return msg;
    }
View Full Code Here

    public RequestContextImpl(RuntimeComponent component) {
    }

    public Subject getSecuritySubject() {
       
        Message msgContext = ThreadMessageContext.getMessageContext();
       
        if (msgContext == null){
            // message in thread context could be null if the user has
            // spun up a new thread inside their component implementation
            return null;
        }
       
        Subject subject = null;
        for (Object header : msgContext.getHeaders().values()){
            if (header instanceof Subject){
                subject  = (Subject)header;
                break;
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.invocation.Message

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.