/** * Create the job and check for its status until it is complete * * @param request * @throws Exception */ protected void executeAndPingSingleJob(Request request) throws Exception{ log.info("Executing: {}", request.getRequest().getURI()); String location = createJob(request); log.info("Job location is {}", location); // Get the result and ping the jId pingSingleJob(location); }
/** * Create a job, returns the location of the job. * We also assert that: * - response status code is 201 * - Location header do exists, and is unique (no multiple values allowed) * - The value of the Location header muyst be a valid URI * * @param request * @return * @throws Exception */ protected String createJob(Request request) throws Exception{ HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(request.getRequest()); // Response status code must be 201 Created assertEquals(201, response.getStatusLine().getStatusCode()); // Job location must be in the Location: http header // Location header must exists and must be unique assertTrue(response.getHeaders("Location").length==1); // Analyze the location header Header locationHeader = response.getFirstHeader("Location"); String location = locationHeader.getValue(); // Location must be a valid URI URI locationURI = URI.create(location); // We do *not* check here if the body of the response contains a description return locationURI.toString(); }
Request req = builder.buildOtherRequest(new HttpGet(location)); req.withHeader("Accept", "application/json"); log.info("Ping method: {}", req.getRequest().getMethod()); log.info("Ping location: {}", req.getRequest().getURI()); req.getRequest().setHeader("Accept","application/json"); log.info("headers:"); for(Header h : req.getRequest().getAllHeaders()){ log.info("{}: {}", h.getName(), h.getValue()); log.info("Request line:\n\n {} \n\n", req.getRequest().getRequestLine().toString()); try{ String content = executor.execute(req).assertStatus(200).assertContentType("application/json").getContent();
request = r.getRequest();