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

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


        Message requestMessage = messageFactory.createMessage();

        String id = path.substring(1);

        Message responseMessage = null;
        HTTPCacheContext cacheContext = null;
        try {
            cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
        } catch (ParseException e) {

        }

        if (path == null || path.length() == 0 || path.equals("/")) {

        }

        // Route message based on availability of cache info and cache methods
        if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalGetInvoker != null )) {
            if(id != null && id.length() > 0) {
                requestMessage.setBody(new Object[] {id, cacheContext});
            } else {
                requestMessage.setBody(new Object[] {cacheContext});
            }
View Full Code Here


        // 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);
View Full Code Here

        // 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);
View Full Code Here

        // 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();
            if ( lastModified != null) {
                response.setHeader( "LastModified", cc.getLastModified() );
            }
        }
      }
    }
View Full Code Here

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // No authentication required for a get request

        // Test for any cache info in the request
        HTTPCacheContext cacheContext = null;
        try {
            cacheContext = HTTPCacheContext.createCacheContextFromRequest( request );
        } catch ( java.text.ParseException e ) {
        }
        // System.out.println( "AtomBindingListener.doGet cache context=" + cacheContext );
View Full Code Here

        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 )) {
            if(id != null && id.length() > 0) {
                requestMessage.setBody(new Object[] {id, cacheContext});
            } else {
                requestMessage.setBody(new Object[] {cacheContext});
            }
View Full Code Here

        // 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);
View Full Code Here

        // 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);
View Full Code Here

        // 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();
            if ( lastModified != null) {
                response.setHeader( "LastModified", cc.getLastModified() );
            }
        }
      }
    }
View Full Code Here

                    throw new PreconditionFailedException("item eTag matches " + cacheContext.getETag());
            }
        }

        // Return the ETag and LastModfied fields by serialize to a byte array
        HTTPCacheContext returnContext = new HTTPCacheContext();
        returnContext.setETag("ETag" + (new java.util.Random()).nextInt(Integer.MAX_VALUE));
        returnContext.setLastModified(new Date());
        return returnContext;
    }
View Full Code Here

TOP

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

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.