use of org.apache.jena.atlas.web.HttpException in project jena by apache.
the class FusekiTest method execOptions.
/** Do an HTTP Options. */
public static String execOptions(String url) {
// Prepare and execute
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpUriRequest request = new HttpOptions(url);
HttpResponse response = httpClient.execute(request, (HttpContext) null);
// Response
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (HttpSC.isClientError(statusCode) || HttpSC.isServerError(statusCode)) {
// Error responses can have bodies so it is important to clear up.
String contentPayload = "";
if (response.getEntity() != null)
contentPayload = EntityUtils.toString(response.getEntity());
throw new HttpException(statusCode, statusLine.getReasonPhrase(), contentPayload);
}
HttpResponseLib.nullResponse.handle(url, response);
return response.getFirstHeader(HttpNames.hAllow).getValue();
} catch (IOException ex) {
throw new HttpException(ex);
}
}
use of org.apache.jena.atlas.web.HttpException in project jena by apache.
the class TestAdmin method add_delete_dataset_2.
// Try to add twice
@Test
public void add_delete_dataset_2() {
checkNotThere(dsTest);
File f = new File(fileBase + "config-ds-1.ttl");
{
org.apache.http.entity.ContentType ct = org.apache.http.entity.ContentType.parse(WebContent.contentTypeTurtle + "; charset=" + WebContent.charsetUTF8);
HttpEntity e = new FileEntity(f, ct);
execHttpPost(ServerCtl.urlRoot() + "$/" + opDatasets, e);
}
// Check exists.
checkExists(dsTest);
try {
org.apache.http.entity.ContentType ct = org.apache.http.entity.ContentType.parse(WebContent.contentTypeTurtle + "; charset=" + WebContent.charsetUTF8);
HttpEntity e = new FileEntity(f, ct);
execHttpPost(ServerCtl.urlRoot() + "$/" + opDatasets, e);
} catch (HttpException ex) {
assertEquals(HttpSC.CONFLICT_409, ex.getResponseCode());
}
// Check exists.
checkExists(dsTest);
deleteDataset(dsTest);
}
Aggregations