use of org.apache.jena.atlas.web.HttpException in project jena by apache.
the class TestAdmin method checkExistsNotActive.
private static void checkExistsNotActive(String name) {
adminPing(name);
try {
askPing(name);
fail("askPing did not cause an Http Exception");
} catch (HttpException ex) {
}
JsonValue v = getDatasetDescription(name);
assertFalse(v.getAsObject().get("ds.state").getAsBoolean().value());
}
use of org.apache.jena.atlas.web.HttpException in project jena by apache.
the class HttpQuery method execPost.
private InputStream execPost() throws QueryExceptionHTTP {
URL target = null;
try {
target = new URL(serviceURL);
} catch (MalformedURLException malEx) {
throw new QueryExceptionHTTP(0, "Malformed URL: " + malEx);
}
log.trace("POST " + target.toExternalForm());
ARQ.getHttpRequestLogger().trace(target.toExternalForm());
try {
// Get the actual response stream
TypedInputStream stream = HttpOp.execHttpPostFormStream(serviceURL, this, contentTypeResult, client, getContext());
if (stream == null)
throw new QueryExceptionHTTP(404);
return execCommon(stream);
} catch (HttpException httpEx) {
throw rewrap(httpEx);
}
}
use of org.apache.jena.atlas.web.HttpException in project jena by apache.
the class HttpOp method exec.
// ---- Perform the operation!
private static void exec(String url, HttpUriRequest request, String acceptHeader, HttpResponseHandler handler, HttpClient httpClient, HttpContext httpContext) {
// whether we should close the client after request execution
// only true if we built the client right here
httpClient = firstNonNull(httpClient, getDefaultHttpClient());
// and also only true if the handler won't close the client for us
try {
if (handler == null)
// This cleans up left-behind streams
handler = nullHandler;
long id = counter.incrementAndGet();
String baseURI = determineBaseIRI(url);
if (log.isDebugEnabled())
log.debug(format("[%d] %s %s", id, request.getMethod(), request.getURI().toString()));
// Accept
if (acceptHeader != null)
request.addHeader(HttpNames.hAccept, acceptHeader);
// User-Agent
applyUserAgent(request);
HttpResponse response = httpClient.execute(request, httpContext);
// Response
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (HttpSC.isClientError(statusCode) || HttpSC.isServerError(statusCode)) {
log.debug(format("[%d] %s %s", id, statusLine.getStatusCode(), statusLine.getReasonPhrase()));
// Error responses can have bodies so it is important to clear
// up.
final String contentPayload = readPayload(response.getEntity());
throw new HttpException(statusLine.getStatusCode(), statusLine.getReasonPhrase(), contentPayload);
}
if (handler != null)
handler.handle(baseURI, response);
} catch (IOException ex) {
throw new HttpException(ex);
}
}
use of org.apache.jena.atlas.web.HttpException in project jena by apache.
the class HttpQuery method execGet.
private InputStream execGet() throws QueryExceptionHTTP {
URL target = null;
String qs = getQueryString();
ARQ.getHttpRequestLogger().trace(qs);
try {
if (count() == 0)
target = new URL(serviceURL);
else
target = new URL(serviceURL + (serviceParams ? "&" : "?") + qs);
} catch (MalformedURLException malEx) {
throw new QueryExceptionHTTP(0, "Malformed URL: " + malEx);
}
log.trace("GET " + target.toExternalForm());
try {
try {
// Get the actual response stream
TypedInputStream stream = HttpOp.execHttpGet(target.toString(), contentTypeResult, client, getContext());
if (stream == null)
throw new QueryExceptionHTTP(404);
return execCommon(stream);
} catch (HttpException httpEx) {
// Back-off and try POST if something complain about long URIs
if (httpEx.getResponseCode() == 414)
return execPost();
throw httpEx;
}
} catch (HttpException httpEx) {
throw rewrap(httpEx);
}
}
use of org.apache.jena.atlas.web.HttpException in project jena by apache.
the class TestEmbeddedFuseki method embedded_09.
@Test
public void embedded_09() {
DatasetGraph dsg = dataset();
int port = FusekiLib.choosePort();
FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).setContextPath("/ABC").parseConfigFile(DIR + "config.ttl").build();
server.start();
try {
try {
query("http://localhost:" + port + "/FuTest", "ASK{}", x -> {
});
} catch (HttpException ex) {
assertEquals(HttpSC.METHOD_NOT_ALLOWED_405, ex.getResponseCode());
}
query("http://localhost:" + port + "/ABC/FuTest", "ASK{}", x -> {
});
} finally {
server.stop();
}
}
Aggregations