PigResource { @GET @Path("/request/{requestId}/output") @Produces( {MediaType.TEXT_PLAIN} ) public Response getOutput(@PathParam("requestId") String requestId) throws IOException { logger.info("Request for reading output for " + requestId); String outputPath= PropertyLoader.getInstance().getProperty(Constants.REQUEST_PATH) + requestId; StreamingPigOutputImpl streamingPigOutputImpl = new StreamingPigOutputImpl(outputPath); if(streamingPigOutputImpl.isAvailable() == false) { logger.info("Request " + requestId + " not available"); return Response.status(404).entity("Invalid Request ID").build(); } return Response.ok(streamingPigOutputImpl).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 testGetOutpu() throws Exception { PigResource resource= new PigResource(); String requestId= UUID.randomUUID().toString(); String inputString= "1,2,3,4,5"; String path= PropertyLoader.getInstance().getProperty("requests.basepath") + requestId + "/output/part-00000"; BufferedWriter writer= new BufferedWriter( new OutputStreamWriter(fileSystem.create(new Path(path), false))); writer.write(inputString); writer.close(); Response resp= resource.getOutput(requestId); Assert.assertEquals(resp.getStatus(), 200); StreamingPigOutputImpl out= (StreamingPigOutputImpl) resp.getEntity(); ByteArrayOutputStream output= new ByteArrayOutputStream(); out.write(output); String outStr= output.toString(); Assert.assertEquals(outStr.contains("1,2,3,4"), true); requestId= "abc"; try { resp= resource.getOutput(requestId); } catch (Exception e) { Assert.assertNotNull(resp); } }