/** * Wrap supplied HTTP request */ public Request buildOtherRequest(HttpRequestBase r) { return new Request(r); }
public Request withEntity(HttpEntity e) { getHttpEntityEnclosingRequestBase().setEntity(e); return this; }
public Request withContent(String content) throws UnsupportedEncodingException { return withEntity(new StringEntity(content, "UTF-8")); } /**
/** * Executes a {@link QueryTestCase} by sending the * {@link QueryTestCase#getContent() query} as an POST request to the * <code>{@link #endpointPath}/{@link QueryTestCase#getServicePath()}</Code>. * @param path the path to perform the field query. "/query" is added to the * parsed value * @param test the field query test * @return the result executor used for the test * @throws IOException on any exception while connecting to the entityhub * @throws JSONException if the returned results are not valid JSON */ protected RequestExecutor executeQuery(QueryTestCase test) throws IOException, JSONException { Request request = builder.buildPostRequest(endpointPath+test.getServicePath()); for(Entry<String,String> header : test.getHeaders().entrySet()){ request.withHeader(header.getKey(), header.getValue()); } request.withContent(test.getContent()); RequestExecutor re = executor.execute(request); assertQueryResults(re, test); return re; } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
while(waiting){ 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(); .setRedirectsEnabled(r.getRedirects()) .setRelativeRedirectsAllowed(true).build(); request.setConfig(rc);
/** * 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); }
return withContent(""); return withContent(content.toString());
.withHeader("Accept", "text/html") .withHeader("Accept", "application/json")); re.assertStatus(200); re.assertContentType("application/json"); re = executor.execute( builder.buildGetRequest("/entityhub/site/"+referencedSite) .withHeader("Accept", "application/json")); //check JSON serializer re.assertStatus(200); re.assertContentType("application/json"); re = executor.execute(builder.buildGetRequest("/entityhub/site/"+referencedSite) .withHeader("Accept", "application/rdf+xml"));//check RDF serializer re.assertStatus(200); re.assertContentType("application/rdf+xml");
/** * 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(); }
/** * Build a GET request to specified path with optional query * parameters. See {@link #buildUrl(String, String...)} for * queryParameters semantics. */ public Request buildGetRequest(String path, String... queryParameters) { return new Request(new HttpGet(buildUrl(path, queryParameters))); }
/** * Build a POST request to specified path with optional query * parameters. See {@link #buildUrl(String, String...)} for * queryParameters semantics. */ public Request buildPostRequest(String path) { return new Request(new HttpPost(buildUrl(path))); }