All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hyperfoil.http.handlers.StoreStatusHandler Maven / Gradle / Ivy

There is a newer version: 0.27.1
Show newest version
package io.hyperfoil.http.handlers;

import org.kohsuke.MetaInfServices;

import io.hyperfoil.api.config.InitFromParam;
import io.hyperfoil.api.config.Name;
import io.hyperfoil.http.api.HttpRequest;
import io.hyperfoil.http.api.StatusHandler;
import io.hyperfoil.api.session.Access;
import io.hyperfoil.api.session.ResourceUtilizer;
import io.hyperfoil.api.session.Session;
import io.hyperfoil.core.session.SessionFactory;

public class StoreStatusHandler implements StatusHandler, ResourceUtilizer {
   private final Access toVar;

   public StoreStatusHandler(Access toVar) {
      this.toVar = toVar;
   }

   @Override
   public void handleStatus(HttpRequest request, int status) {
      toVar.setInt(request.session, status);
   }

   @Override
   public void reserve(Session session) {
      toVar.declareInt(session);
   }

   /**
    * Stores the status into session variable.
    */
   @MetaInfServices(StatusHandler.Builder.class)
   @Name("store")
   public static class Builder implements StatusHandler.Builder, InitFromParam {
      private Object toVar;

      /**
       * @param param Variable name.
       * @return Self.
       */
      @Override
      public Builder init(String param) {
         return toVar(param);
      }

      /**
       * Variable name.
       *
       * @param toVar Variable name.
       * @return Self.
       */
      public Builder toVar(Object toVar) {
         this.toVar = toVar;
         return this;
      }

      @Override
      public StoreStatusHandler build() {
         return new StoreStatusHandler(SessionFactory.access(toVar));
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy