Package org.ocpsoft.rewrite.servlet.config

Examples of org.ocpsoft.rewrite.servlet.config.HttpOperation


               .addRule(Join.path("/{lang}/{path}/transposition_only").to("/{path}"))
               .where("path").transposedBy(LocaleTransposition.bundle("bundle", "lang"))

               .addRule(Join.path("/{lang}/{path}/transposition_failed_1").to("/{path}"))
               .where("path").transposedBy(LocaleTransposition.bundle("bundle", "lang").onTranspositionFailed(
                        new HttpOperation()
                        {
                           @Override
                           public void performHttp(HttpServletRewrite event, EvaluationContext context)
                           {
                              SendStatus.code(201).performHttp(event, context);
                           }
                        }))

               .addRule(Join.path("/{lang}/{path}/transposition_failed_2").to("/{path}"))
               .where("path").transposedBy(LocaleTransposition.bundle("bundle", "lang").onTranspositionFailed(
                        new HttpOperation()
                        {
                           @Override
                           public void performHttp(HttpServletRewrite event, EvaluationContext context)
                           {
                              SendStatus.code(202).performHttp(event, context);
View Full Code Here


               /*
                * Test unbuffered. Use a Join to perform a forward so we know buffering would have been activated.
                */
               .addRule(Join.path("/unbuffered").to("/unbuffered.html"))
               .addRule().when(Path.matches("/unbuffered.html"))
               .perform(new HttpOperation() {
                  @Override
                  public void performHttp(HttpServletRewrite event, EvaluationContext context)
                  {
                     if (HttpRewriteWrappedResponse.getCurrentInstance(event.getRequest())
                              .isResponseContentIntercepted())
                     {
                        throw new IllegalStateException("Buffering should not be active.");
                     }
                     else
                     {
                        Response.setStatus(201).perform(event, context);
                     }
                  }
               })

               /*
                * Test buffer failure constraints.
                */
               .addRule(Join.path("/bufferforward").to("/forward.html"))
               .addRule().when(Path.matches("/forward.html"))
               .perform(new HttpOperation() {
                  @Override
                  public void performHttp(HttpServletRewrite event, EvaluationContext context)
                  {
                     Response.withOutputInterceptedBy(new ResponseToLowercase()).perform(event, context);
                     Response.setStatus(202).perform(event, context);
                  }
               })

               .addRule().when(Path.matches("/bufferfail"))
               .perform(new HttpOperation() {
                  @Override
                  public void performHttp(HttpServletRewrite event, EvaluationContext context)
                  {
                     try {
                        event.getResponse().getOutputStream(); // cause buffers to lock
View Full Code Here

               /**
                * Define the inbound conditions and conversion mechanisms to be used when handling inbound requests.
                */
               .when(Method.isGet()
                        .and(Path.matches("/store/product/{pid}")))
               .perform(new HttpOperation() {
                  @Override
                  public void performHttp(final HttpServletRewrite event, final EvaluationContext context)
                  {
                     /**
                      * Extract the stored {pid} from our Path and load the Product. This is an example of how we can
                      * use a converter to directly bind and store the object we want into a binding. {@link Evaluation}
                      * is an low-level construct, and binds array values that must be dereferenced. If using other
                      * bindings such as {@link El}, the value will be bound directly to the type of the referenced
                      * property type, and this array downcast is not necessary.
                      */
                     ParameterStore store = (ParameterStore) context.get(ParameterStore.class);
                     Product product = (Product) Evaluation.property("pid").retrieveConverted(event, context,
                              store.get("pid"));

                     /**
                      * Marshal the Product into XML using JAXB. This has been extracted into a utility class.
                      */
                     try {
                        XMLUtil.streamFromObject(Product.class, product, event.getResponse()
                                 .getOutputStream());
                     }
                     catch (IOException e) {
                        throw new RuntimeException(e);
                     }

                     /**
                      * Set the content type and status code of the response, this again could be extracted into a REST
                      * utility class.
                      */
                     event.getResponse().setContentType("application/xml");
                     ((HttpInboundServletRewrite) event).sendStatusCode(200);
                  }
               }).where("pid").matches("\\d+")
               .constrainedBy(new IntegerConstraint())
               .convertedBy(productConverter)
               .validatedBy(productValidator)

               .addRule()
               .when(Path.matches("/store/products").and(Method.isGet()))
               .perform(new HttpOperation() {
                  @Override
                  public void performHttp(final HttpServletRewrite event, final EvaluationContext context)
                  {
                     try {
                        XMLUtil.streamFromObject(ProductRegistry.class, products, event.getResponse().getOutputStream());
                        event.getResponse().setContentType("application/xml");
                        ((HttpInboundServletRewrite) event).sendStatusCode(200);
                     }
                     catch (Exception e) {
                        throw new RuntimeException(e);
                     }
                  }
               })

               .addRule()
               .when(Path.matches("/store/products").and(Method.isPost()))
               .perform(new PostOperation())

               .addRule().when(Path.matches("/")).perform(new HttpOperation() {

                  @Override
                  public void performHttp(final HttpServletRewrite event, final EvaluationContext context)
                  {
                     try {
View Full Code Here

                */
               .addRule()
               .when(Path.matches("/binding/{value}").and(DispatchType.isRequest()))
               .perform(Forward.to("/empty.xhtml")

                        .and(PhaseOperation.enqueue(new HttpOperation() {
                           @Override
                           public void performHttp(HttpServletRewrite event, EvaluationContext context)
                           {
                              String value = event.getRequest().getParameter("v");
                              if (value != null)
                                 SendStatus.code(505).perform(event, context);
                           }
                        }).before(PhaseId.RESTORE_VIEW))

                        .and(PhaseOperation.enqueue(new HttpOperation() {
                           @Override
                           public void performHttp(HttpServletRewrite event, EvaluationContext context)
                           {
                              HttpServletRequest request = event.getRequest();
                              String value = request.getParameter("v");
View Full Code Here

   }

   @Override
   public void perform(final Rewrite event, final EvaluationContext context)
   {
      new HttpOperation() {

         boolean forwarded = false;

         @Override
         public void performHttp(final HttpServletRewrite event, final EvaluationContext context)
View Full Code Here

TOP

Related Classes of org.ocpsoft.rewrite.servlet.config.HttpOperation

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.