QueryResource { @POST @Consumes(MediaType.APPLICATION_JSON) public Response submitQuery(@HeaderParam(tajoSessionIdHeaderName) String sessionId, SubmitQueryRequest request) { if (LOG.isDebugEnabled()) { LOG.debug("Client sent a submit query request."); } Response response = null; try { initializeContext(); JerseyResourceDelegateContextKey<String> sessionIdKey = JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class); context.put(sessionIdKey, sessionId); JerseyResourceDelegateContextKey<SubmitQueryRequest> submitQueryRequestKey = JerseyResourceDelegateContextKey.valueOf(submitQueryRequestKeyName, SubmitQueryRequest.class); context.put(submitQueryRequestKey, request); response = JerseyResourceDelegateUtil.runJerseyResourceDelegate( new SubmitQueryDelegate(), application, context, LOG); } catch (Throwable e) { LOG.error(e.getMessage(), e); response = ResourcesUtil.createExceptionResponse(null, e.getMessage()); } return response; }  @GET @Produces(MediaType.APPLICATION_JSON) Response getAllQueries(@QueryParam("state") String state,
      @QueryParam("startTime") long startTime,
      @QueryParam("endTime") long endTime); @POST @Consumes(MediaType.APPLICATION_JSON) Response submitQuery(@HeaderParam(tajoSessionIdHeaderName) String sessionId,
      SubmitQueryRequest request); @GET @Path("{queryId}") @Produces(MediaType.APPLICATION_JSON) Response getQuery(@PathParam("queryId") String queryId, @QueryParam("print") String printType); @DELETE @Path("{queryId}") Response terminateQuery(@PathParam("queryId") String queryId); @Path("/{queryId}/result") QueryResultResource getQueryResult(@PathParam("queryId") String queryId);  }
@Test public void testSubmitQuery() throws Exception { String sessionId = generateNewSessionAndGetId(); SubmitQueryRequest queryRequest = createNewQueryRequest("select * from lineitem"); Response response = restClient.target(queriesURI) .request().header(tajoSessionIdHeaderName, sessionId) .post(Entity.entity(queryRequest, MediaType.APPLICATION_JSON)); assertNotNull(response); assertEquals(Status.CREATED.getStatusCode(), response.getStatus()); String locationHeader = response.getHeaderString("Location"); assertTrue(locationHeader != null && !locationHeader.isEmpty()); String queryId = locationHeader.lastIndexOf('/') >= 0? locationHeader.substring(locationHeader.lastIndexOf('/')+1):null; assertTrue(queryId != null && !queryId.isEmpty()); QueryInfo queryInfo = restClient.target(queriesURI) .path("/{queryId}") .resolveTemplate("queryId", queryId) .queryParam("print", "BRIEF") .request().get(new GenericType<QueryInfo>(QueryInfo.class)); assertNotNull(queryInfo); assertEquals(queryId, queryInfo.getQueryIdStr()); }