PigResource { @GET @Path("/request/{requestId}") @Produces( {MediaType.APPLICATION_JSON} ) public Response getInput(@PathParam("requestId") String requestId) throws IOException { logger.info("Request for getting request " + requestId); PigRequestParameters params = PigJobServerImpl .getPigJobServer() .getInputRequest(requestId); return Response.ok() .entity(new Gson().toJson(params, PigRequestParameters.class)) .build(); }  @POST @Path("/jar/{jarName}") @Consumes ( {MediaType.APPLICATION_OCTET_STREAM} ) @Produces ({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) Response registerJar(@PathParam("jarName") String jarName, InputStream uploadedJar); @DELETE @Path("/jar/{jarName}") @Produces ( {MediaType.TEXT_PLAIN} ) Response unregisterJar(@PathParam("jarName") String jarName); @GET @Path("/jar/{jarName}") @Produces ( {MediaType.APPLICATION_OCTET_STREAM} ) Response getRegisteredJar(@PathParam("jarName") String jarName); @POST @Path("/script/{scriptName}") @Consumes ( {MediaType.APPLICATION_OCTET_STREAM} ) @Produces ({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) Response registerScript(@PathParam("scriptName") String scriptName, InputStream uploadedScript); @DELETE @Path("/script/{scriptName}") @Produces ( {MediaType.TEXT_PLAIN} ) Response unregisterScript(@PathParam("scriptName") String scriptName); @GET @Path("/script/{scriptName}") @Produces ( {MediaType.APPLICATION_OCTET_STREAM} ) Response getRegisteredScript(@PathParam("scriptName") String scriptName); @POST @Path("/request/{scriptName}") @Consumes( {MediaType.APPLICATION_JSON} ) @Produces( {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN} ) Response submitPigJob(@PathParam("scriptName") String scriptName, String data); @GET @Path("/request/{requestId}") @Produces( {MediaType.APPLICATION_JSON} ) Response getInput(@PathParam("requestId") String requestId); @GET @Path("/request/{requestId}/stats") @Produces( {MediaType.APPLICATION_JSON} ) Response getRequestStats(@PathParam("requestId") String requestId); @GET @Path("/request/{requestId}/output") @Produces( {MediaType.TEXT_PLAIN} ) Response getOutput(@PathParam("requestId") String requestId); @GET @Path("request/{requestId}/status") @Produces( {MediaType.TEXT_PLAIN} ) Response getRequestStatus(@PathParam("requestId") String requestId); @GET @Path("request/{requestId}/cancel") @Produces( {MediaType.TEXT_PLAIN} ) Response cancelRequest(@PathParam("requestId") String requestId);  }
@Test public void testGetRequest() throws Exception { PigResource resource= new PigResource(); PigRequestParameters input= new PigRequestParameters(); input.setHttpCallback("123"); input.setPigScript("abc.pig"); input.setRequestStartTime(new Date()); String requestId= UUID.randomUUID().toString(); Gson gson= new GsonBuilder().setPrettyPrinting().setDateFormat("yyyy/MM/dd-HH:mm").create(); String inputString= Base64.encodeBase64URLSafeString(gson.toJson(input).getBytes()); String path= PropertyLoader.getInstance().getProperty("requests.basepath") + requestId + "/input"; BufferedWriter writer= new BufferedWriter( new OutputStreamWriter(fileSystem.create(new Path(path), false))); writer.write(inputString); writer.close(); Response resp= resource.getInput(requestId); Assert.assertEquals(resp.getStatus(), 200); requestId= "abc"; try { resp= resource.getInput(requestId); } catch (Exception e) { Assert.assertNotNull(e); } requestId= UUID.randomUUID().toString(); fileSystem.mkdirs(new Path(PropertyLoader.getInstance().getProperty("requests.basepath") + requestId)); try { resp= resource.getInput(requestId); } catch (Exception e) { Assert.assertNotNull(e); } }