PigResource { @POST @Path("/jar/{jarName}") @Consumes ( {MediaType.APPLICATION_OCTET_STREAM} ) @Produces ({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) public Response registerJar(@PathParam("jarName") String jarName, InputStream uploadedJar) throws IOException { logger.info("Request for registring jar with name " + jarName); if (uploadedJar == null || uploadedJar.available() == 0){ logger.error("Empty input stream passed"); return Response.status(400).entity("Bad request. No jar uploaded!").build(); } String pathName= PropertyLoader.getInstance().getProperty(Constants.JARS_PATH) + jarName; PigJobServerImpl.getPigJobServer().registerFile(pathName, uploadedJar); return Response.ok().entity(pathName).type(MediaType.TEXT_PLAIN).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 testRegisterJar() throws Exception { PigResource resource= new PigResource(); String str= "abcde"; InputStream input= new ByteArrayInputStream(str.getBytes("UTF-8")); Response resp= resource.registerJar("a.jar", input); Assert.assertEquals(resp.getStatus(), 200); input= new ByteArrayInputStream(str.getBytes("UTF-8")); try { resp= resource.registerJar("a.jar", input); } catch (Exception e) { Assert.assertNotNull(e); } }