package stockManagement.pull; import java.util.*; import javax.ws.rs.*; import javax.ws.rs.client.*; import javax.ws.rs.core.*; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; import pushPullRefactor.Getter; import pushPullRefactor.Message; import pushPullRefactor.Resource; import pushPullRefactor.State; import com.fasterxml.jackson.core.JsonProcessingException; @Path("/arrival") @Resource("arrival") @Component public class Arrival { private Client client = ClientBuilder.newClient(); @State private Map.Entry<String, Integer> value; @PUT @Message({}) public void arrive(@FormParam("num") int num, @FormParam("item") String item) throws JsonProcessingException { this.value = new AbstractMap.SimpleEntry<>(item, num); Map<String, Integer> stock_json = client.target("http://localhost:8080").path("/stock").request().get(HashMap.class); Map<String, Integer> stock = new HashMap<>(); stock = stock_json; Form form = new Form(); form.param("arrival", new ObjectMapper().writeValueAsString(this.value)); form.param("stock", new ObjectMapper().writeValueAsString(stock)); Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path("/available").request().put(entity, String.class); } @Produces(MediaType.APPLICATION_JSON) @GET @Getter public Map.Entry<String, Integer> getValue() { return value; } }