use of javax.servlet.ServletOutputStream in project jena by apache.
the class ResponseModel method doResponseModel.
public static void doResponseModel(HttpAction action, Model model) {
HttpServletRequest request = action.request;
HttpServletResponse response = action.response;
// Header request type
String mimeType = null;
// TODO Use MediaType throughout.
MediaType i = ConNeg.chooseContentType(request, DEF.rdfOffer, DEF.acceptRDFXML);
if (i != null)
mimeType = i.getContentType();
String outputField = ResponseOps.paramOutput(request, shortNamesModel);
if (outputField != null)
mimeType = outputField;
String writerMimeType = mimeType;
if (mimeType == null) {
Fuseki.requestLog.warn("Can't find MIME type for response");
String x = WebLib.getAccept(request);
String msg;
if (x == null)
msg = "No Accept: header";
else
msg = "Accept: " + x + " : Not understood";
error(HttpSC.NOT_ACCEPTABLE_406, msg);
}
String contentType = mimeType;
String charset = WebContent.charsetUTF8;
String forceAccept = ResponseOps.paramForceAccept(request);
if (forceAccept != null) {
contentType = forceAccept;
charset = WebContent.charsetUTF8;
}
Lang lang = RDFLanguages.contentTypeToLang(contentType);
if (lang == null)
errorBadRequest("Can't determine output content type: " + contentType);
try {
ResponseResultSet.setHttpResponse(request, response, contentType, charset);
response.setStatus(HttpSC.OK_200);
ServletOutputStream out = response.getOutputStream();
RDFDataMgr.write(out, model, lang);
out.flush();
} catch (Exception ex) {
slog.info("Exception while writing the response model: " + ex.getMessage(), ex);
errorOccurred("Exception while writing the response model: " + ex.getMessage(), ex);
}
}
use of javax.servlet.ServletOutputStream in project jena by apache.
the class ActionPing method doCommon.
protected void doCommon(HttpServletRequest request, HttpServletResponse response) {
try {
ServletOps.setNoCache(response);
response.setContentType(contentTypeTextPlain);
response.setCharacterEncoding(charsetUTF8);
response.setStatus(HttpSC.OK_200);
ServletOutputStream out = response.getOutputStream();
out.println(DateTimeUtils.nowAsXSDDateTimeString());
} catch (IOException ex) {
Fuseki.serverLog.warn("ping :: IOException :: " + ex.getMessage());
}
}
use of javax.servlet.ServletOutputStream in project jena by apache.
the class ActionDataset method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
// request.getRemoteUser() ;
// request.getUserPrincipal() ;
String dataset = FusekiLib.safeParameter(request, "dataset");
HttpSession session = request.getSession(true);
session.setAttribute("dataset", dataset);
// 10 mins
session.setMaxInactiveInterval(15 * 60);
boolean known = DatasetRegistry.get().isRegistered(dataset);
if (!known) {
response.sendError(HttpSC.BAD_REQUEST_400, "No such dataset: " + dataset);
return;
}
if (true) {
// Redirect to GET page.
response.setHeader(HttpNames.hLocation, PageNames.pageAfterLogin);
response.setStatus(HttpSC.SEE_OTHER_303);
} else {
// Welcome style - but HTML inline :-(
response.setContentType("text/html");
response.setStatus(HttpSC.OK_200);
ServletOutputStream out = response.getOutputStream();
out.print("<p>" + dataset + "(" + known + ")</p>");
for (String name : DatasetRegistry.get().keys()) {
out.print("<li>");
out.print(name);
out.println("</li>");
}
out.println("</ul>");
out.println("<p><a href=\"info\">Next</a></p>");
}
// Cookie cookie = new Cookie("org.apache.jena.fuseki.session", dataset) ;
// // 24 hours.
// cookie.setMaxAge(24*60*60) ;
}
use of javax.servlet.ServletOutputStream in project jena by apache.
the class PingServlet method doCommon.
protected void doCommon(HttpServletRequest request, HttpServletResponse response) {
try {
response.setHeader(HttpNames.hCacheControl, "must-revalidate,no-cache,no-store");
response.setHeader(HttpNames.hPragma, "no-cache");
response.setContentType(contentTypeTextPlain);
response.setCharacterEncoding(charsetUTF8);
response.setStatus(HttpSC.OK_200);
ServletOutputStream out = response.getOutputStream();
out.println(DateTimeUtils.nowAsXSDDateTimeString());
} catch (IOException ex) {
Fuseki.serverLog.warn("ping :: IOException :: " + ex.getMessage());
}
}
use of javax.servlet.ServletOutputStream in project jena by apache.
the class StatsServlet method statsJSON.
private void statsJSON(HttpServletRequest req, HttpServletResponse resp) throws IOException {
ServletOutputStream out = resp.getOutputStream();
resp.setContentType(WebContent.contentTypeJSON);
resp.setCharacterEncoding(WebContent.charsetUTF8);
/*
* { "server" : ....
* "datasets" : {
* "ds1": { counters... }
* GSP stucture?
*
*/
JsonObject obj = new JsonObject();
JsonObject datasets = new JsonObject();
JsonObject server = new JsonObject();
server.put("host", req.getLocalName() + ":" + req.getLocalPort());
for (String ds : DatasetRegistry.get().keys()) statsJSON(datasets, ds);
obj.put("server", server);
obj.put("datasets", datasets);
JSON.write(out, obj);
out.flush();
}
Aggregations