Package org.apache.tuscany.sca.invocation

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


        if (Object.class == method.getDeclaringClass()) {
            return invokeObjectMethod(method, args);
        }

        // wire not pre-selected, so select a wire now to be used for the callback
        Message msgContext = ThreadMessageContext.getMessageContext();
        RuntimeWire wire = ((CallbackReferenceImpl)callableReference).selectCallbackWire(msgContext);
        if (wire == null) {
            //FIXME: need better exception
            throw new ServiceRuntimeException("No callback wire found for " + msgContext.getFrom().getURI());
        }

        // set the conversational state based on the interface that
        // is specified for the reference that this wire belongs to
        init(wire);

        // set the conversation id into the conversation object. This is
        // a special case for callbacks as, unless otherwise set manually,
        // the callback should use the same conversation id as was received
        // on the incoming call to this component
        if (conversational) {

            if (conversation == null || conversation.getState() == ConversationState.ENDED) {
                conversation = null;
            }
            Object convID = conversation == null ? null : conversation.getConversationID();

            // create a conversation id if one doesn't exist
            // already, i.e. the conversation is just starting
            if (convID == null) {
                convID = msgContext.getFrom().getReferenceParameters().getConversationID();
                if (convID != null) {
                    conversation = ((RuntimeWireImpl)wire).getConversationManager().getConversation(convID);
                    if (callableReference != null) {
                        ((CallableReferenceImpl)callableReference).attachConversation(conversation);
                    }
                }
            }
        }

        Object callbackID = msgContext.getFrom().getReferenceParameters().getCallbackID();
        ((CallbackReferenceImpl)callableReference).attachCallbackID(callbackID);

        EndpointReference epr = msgContext.getFrom().getReferenceParameters().getCallbackReference();
        setEndpoint(epr);

        // need to set the endpoint on the binding also so that when the chains are created next
        // the sca binding can decide whether to provide local or remote invokers.
        // TODO - there is a problem here though in that I'm setting a target on a
View Full Code Here


     * @param args the response data
     * @param headers - any header
     */
    public void invokeAsyncResponse(Object args, Map<String, Object> headers) {
       
        Message msg = messageFactory.createMessage();

        msg.setOperation(getOperation( args ));
       
        // If this is not native async, then any Throwable is being passed as a parameter and
        // requires wrapping
        if( !isNativeAsync && args instanceof Throwable ) {
          args = new AsyncFaultWrapper( (Throwable) args );
        } // end if
       
        // If this is not native async, then the message must contain an array of args since
        // this is what is expected when invoking an EPR for the async response...
        if( !isNativeAsync ) {
          Object[] objs = new Object[1];
          objs[0] = args;
          args = objs;
        } // end if

        msg.setTo(requestEndpoint);
        msg.setFrom(responseEndpointReference);
       
        if( headers != null ) {
          msg.getHeaders().putAll(headers);
        }
       
        if( args instanceof Throwable ) {
          msg.setFaultBody(args);
        } else {
          msg.setBody(args);
        } // end if
       
        invokeAsyncResponse(msg);
       
    } // end method invokeAsyncResponse(Object)
View Full Code Here

            return;
        }
        String path = URLDecoder.decode(pathInfo, "UTF-8");

        // Invoke the get operation on the service implementation
        Message requestMessage = messageFactory.createMessage();

        String id = path.substring(1);
       
        Message responseMessage = null;
        HTTPCacheContext cacheContext = null;
        try {
           cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
        } catch (ParseException e) {         
        }

        // Route message based on availability of cache info and cache methods
        if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalGetInvoker != null )) {       
          requestMessage.setBody(new Object[] {id, cacheContext});
          responseMessage = conditionalGetInvoker.invoke(requestMessage);
        } else {
          requestMessage.setBody(new Object[] {id});
          responseMessage = getInvoker.invoke(requestMessage);
        }
        if (responseMessage.isFault()) {
          Object body = responseMessage.getBody();
         
          int index = -1;
          if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
            if ( index > -1 )
                response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
            else
                response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
            return;
          } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
            if ( index > -1 )
                response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
            else
                response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
            return;               
            }
                     
            throw new ServletException((Throwable)responseMessage.getBody());
        }
       
        if(response.getContentType() == null || response.getContentType().length() == 0){
            // Calculate content-type based on extension
            String contentType = HTTPContentTypeMapper.getContentType(id);
            if(contentType != null && contentType.length() >0) {
                response.setContentType(contentType);
            }
        }
       
        // Write the response from the service implementation to the response
        // output stream
        InputStream is = (InputStream)responseMessage.getBody();
        OutputStream os = response.getOutputStream();
        byte[] buffer = new byte[2048];
        for (;;) {
            int n = is.read(buffer);
            if (n <= 0)
View Full Code Here

            response.sendRedirect(request.getRequestURL().append('/').toString());
            return;
        }

        // Invoke the get operation on the service implementation
        Message requestMessage = messageFactory.createMessage();
        String id = path.substring(1);
       
        Message responseMessage = null;
        HTTPCacheContext cacheContext = null;
        try {
           cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
        } catch (ParseException e) {         
        }
       
        // Route message based on availability of cache info and cache methods
        if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalDeleteInvoker != null )) {       
          requestMessage.setBody(new Object[] {id, cacheContext});
          responseMessage = conditionalDeleteInvoker.invoke(requestMessage);
        } else {
          requestMessage.setBody(new Object[] {id});
          responseMessage = deleteInvoker.invoke(requestMessage);
        }
        if (responseMessage.isFault()) {
          Object body = responseMessage.getBody();
         
          int index = -1;
          if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
            if ( index > -1 )
                response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
            else
                response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
            return;
          } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
            if ( index > -1 )
                response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
            else
                response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
            return;               
            }           
         
            throw new ServletException((Throwable)responseMessage.getBody());
        }
       
        // Write the response from the service implementation to the response
        // output stream
        InputStream is = (InputStream)responseMessage.getBody();
        OutputStream os = response.getOutputStream();
        byte[] buffer = new byte[2048];
        for (;;) {
            int n = is.read(buffer);
            if (n <= 0)
View Full Code Here

            response.sendRedirect(request.getRequestURL().append('/').toString());
            return;
        }

        // Invoke the get operation on the service implementation
        Message requestMessage = messageFactory.createMessage();
        String id = path.substring(1);
       
        Message responseMessage = null;
        HTTPCacheContext cacheContext = null;
        try {
           cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
        } catch (ParseException e) {         
        }
       
        // Route message based on availability of cache info and cache methods
        if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalPutInvoker != null )) {       
          requestMessage.setBody(new Object[] {id, cacheContext});
          responseMessage = conditionalPutInvoker.invoke(requestMessage);
        } else {
          requestMessage.setBody(new Object[] {id});
          responseMessage = putInvoker.invoke(requestMessage);
        }
        if (responseMessage.isFault()) {
          Object body = responseMessage.getBody();
         
          int index = -1;
          if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
            if ( index > -1 )
                response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
            else
                response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
            return;
          } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
            if ( index > -1 )
                response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
            else
                response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
            return;               
            }           
         
            throw new ServletException((Throwable)responseMessage.getBody());
        }
       
        // Write the response from the service implementation to the response
        // output stream
        InputStream is = (InputStream)responseMessage.getBody();
        OutputStream os = response.getOutputStream();
        byte[] buffer = new byte[2048];
        for (;;) {
            int n = is.read(buffer);
            if (n <= 0)
View Full Code Here

            response.sendRedirect(request.getRequestURL().append('/').toString());
            return;
        }

        // Invoke the get operation on the service implementation
        Message requestMessage = messageFactory.createMessage();
        // String id = path.substring(1);
       
        Message responseMessage = null;
        HTTPCacheContext cacheContext = null;
        try {
           cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
        } catch (ParseException e) {         
        }
       
        // Route message based on availability of cache info and cache methods
        if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalPostInvoker != null )) {       
          requestMessage.setBody(new Object[] {cacheContext});
          responseMessage = conditionalPostInvoker.invoke(requestMessage);
        } else {
          requestMessage.setBody(new Object[] {});
          responseMessage = postInvoker.invoke(requestMessage);
        }
        if (responseMessage.isFault()) {
          Object body = responseMessage.getBody();
         
          int index = -1;
          if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
            if ( index > -1 )
                response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
            else
                response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
            return;
          } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
            if ( index > -1 )
                response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
            else
                response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
            return;               
            }           
         
            throw new ServletException((Throwable)responseMessage.getBody());
        }


        // Test if the ETag and LastModified are returned as a cache context.
      Object body = responseMessage.getBody();
      if ( body.getClass() == HTTPCacheContext.class ) {
        // Transfer to header if so.
        HTTPCacheContext cc = (HTTPCacheContext)responseMessage.getBody();
        if (( cc != null ) && ( cc.isEnabled() )) {
          String eTag = cc.getETag();
              if ( eTag != null )
                response.setHeader( "ETag", cc.getETag() );
              String lastModified = cc.getLastModified();
View Full Code Here

     * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message)
     */
    public Message invoke(Message msg) {
        TransactionalInvocation invocation = new TransactionalInvocation(next, msg);

        Message result = null;
        if (msg.getOperation().isNonBlocking()) {

        }
        TransactionIntent interactionIntent = TransactionIntent.propagatesTransacton;
        if (interactionPolicy != null) {
View Full Code Here

    }

    public void beforeInvoke(Object... context) {
        for ( int count = 0 ; count < context.length ; ++count ) {
            if ( context[count] instanceof Message ) {
                Message msg = (Message)context[count];
                Object args[] = (Object[])msg.getBody();
                if ( msg.getQoSContext().get(Message.QOS_CTX_SECURITY_PRINCIPAL) != null ) {
                        BigbankCheckingsAcl.authorize((Principal)msg.getQoSContext().get(Message.QOS_CTX_SECURITY_PRINCIPAL),
                                                      (String)args[0]);
                }
            }
        }
    }
View Full Code Here

                    BigbankCheckingsAcl.authorize((Principal)msg.getQoSContext().get(Message.QOS_CTX_SECURITY_PRINCIPAL),
                                                  (String)args[0]);
            }
        }
       
        Message responseMsg = null;
        try {
            responseMsg = getNext().invoke(msg);
            return responseMsg;
        } catch (RuntimeException e) {
            throw e;
View Full Code Here

                // Return a feed containing the entries in the collection
                Feed feed = null;
                if (supportsFeedEntries) {

                    // The service implementation supports feed entries, invoke its getFeed operation
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage = getFeedInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    feed = (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());
                    }
                    org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[] collection =
                        (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[])responseMessage.getBody();
                    if (collection != null) {
                        // Create the feed
                        feed = new Feed();
                        feed.setTitle("Feed");
                        for (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object> entry: collection) {
                            Entry feedEntry = createFeedEntry(entry);
                            feed.getEntries().add(feedEntry);
                        }
                    }
                }
                if (feed != null) {
                   
                    // Write the Atom feed
                    response.setContentType("application/atom+xml; charset=utf-8");
                    feed.setFeedType(requestFeedType);
                    WireFeedOutput feedOutput = new WireFeedOutput();
                    try {
                        feedOutput.output(feed, getWriter(response));
                    } catch (FeedException e) {
                        throw new ServletException(e);
                    }
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                }
               
            } else if (path.startsWith("/")) {

                // Return a specific entry in the collection
                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()) {
                    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
                    feedEntry = createFeedEntry(new org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>(id, responseMessage.getBody()));
                }

                // Write the Atom entry
                if (feedEntry != null) {
                    response.setContentType("application/atom+xml; charset=utf-8");
                    try {
                        AtomFeedEntryUtil.writeFeedEntry(feedEntry, feedType, getWriter(response));
                    } catch (FeedException e) {
                        throw new ServletException(e);
                    }
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                }

            } else {

                // Path doesn't match any known pattern
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            }
        } else {

            // Handle an RSS request
            if (path == null || path.length() == 0 || path.equals("/")) {

                // Return an RSS feed containing the entries in the collection
                Feed feed = null;
                if (supportsFeedEntries) {

                    // The service implementation supports feed entries, invoke its getFeed operation
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage = getFeedInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    feed = (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 data 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());
                    }
                    org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[] collection =
                        (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[])responseMessage.getBody();
                    if (collection != null) {
                        // Create the feed
                        feed = new Feed();
                        feed.setTitle("Feed");
                        for (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object> entry: collection) {
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.