本文整理了Java中org.xowl.infra.server.xsp.XSPReplyUtils.toHttpResponse()
方法的一些代码示例,展示了XSPReplyUtils.toHttpResponse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XSPReplyUtils.toHttpResponse()
方法的具体详情如下:
包路径:org.xowl.infra.server.xsp.XSPReplyUtils
类名称:XSPReplyUtils
方法名:toHttpResponse
暂无
代码示例来源:origin: org.xowl.platform/xowl-service-connection
/**
* Responds to the request to delete a previously spawned parametric connector
*
* @param connectorId The identifier of the connector to delete
* @return The response
*/
private HttpResponse onMessageDeleteConnector(String connectorId) {
XSPReply reply = delete(connectorId);
return XSPReplyUtils.toHttpResponse(reply, null);
}
代码示例来源:origin: org.xowl.platform/xowl-service-connection
@Override
public HttpResponse handle(SecurityService securedService, HttpApiRequest request) {
return XSPReplyUtils.toHttpResponse(XSPReplyUnsupported.instance(), null);
}
代码示例来源:origin: org.xowl.platform/xowl-service-domain
/**
* Responds to the request to delete a previously spawned parametric connector
*
* @param parameters The request parameters
* @return The response
*/
private HttpResponse onMessageDeleteConnector(Map<String, String[]> parameters) {
String[] ids = parameters.get("id");
if (ids == null || ids.length == 0)
return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter");
XSPReply reply = delete(ids[0]);
return XSPReplyUtils.toHttpResponse(reply, null);
}
代码示例来源:origin: org.xowl.platform/xowl-kernel-impl
/**
* Responds to a request for the list of available metrics
*
* @param securityService The current security service
* @return The metrics
*/
private HttpResponse onMessageGetMetricList(SecurityService securityService) {
XSPReply reply = securityService.checkAction(ACTION_GET_METRICS);
if (!reply.isSuccess())
return XSPReplyUtils.toHttpResponse(reply, null);
// get all the metrics
boolean first = true;
StringBuilder builder = new StringBuilder("[");
for (Metric metric : getMetrics()) {
if (!first)
builder.append(", ");
first = false;
builder.append(metric.serializedJSON());
}
builder.append("]");
return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, builder.toString());
}
代码示例来源:origin: org.xowl.platform/xowl-service-impact
@Override
public HttpResponse handle(SecurityService securityService, HttpApiRequest request) {
if (!HttpConstants.METHOD_POST.equals(request.getMethod()))
return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected POST method");
byte[] content = request.getContent();
if (content == null || content.length == 0)
return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_FAILED_TO_READ_CONTENT), null);
BufferedLogger logger = new BufferedLogger();
ASTNode root = JSONLDLoader.parseJSON(logger, new String(content, IOUtils.CHARSET));
if (root == null)
return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_CONTENT_PARSING_FAILED, logger.getErrorsAsString()), null);
return XSPReplyUtils.toHttpResponse(perform(new XOWLImpactAnalysisSetup(root)), null);
}
代码示例来源:origin: org.xowl.platform/xowl-kernel-impl
@Override
public HttpResponse handle(SecurityService securityService, HttpApiRequest request) {
XSPReply reply = securityService.checkAction(ACTION_GET_LOG);
if (!reply.isSuccess())
return XSPReplyUtils.toHttpResponse(reply, null);
if (!HttpConstants.METHOD_GET.equals(request.getMethod()))
return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected GET method");
StringBuilder builder = new StringBuilder("[");
boolean first = true;
for (PlatformLogMessage message : buffer.getMessages()) {
if (!first)
builder.append(", ");
first = false;
builder.append(message.serializedJSON());
}
builder.append("]");
return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, builder.toString());
}
代码示例来源:origin: org.xowl.platform/xowl-connector-semanticweb
String contentType = request.getContentType();
if (name == null)
return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'name'"), null);
if (base == null)
return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'base'"), null);
if (version == null)
return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'version'"), null);
if (archetype == null)
return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'archetype'"), null);
if (contentType == null || contentType.isEmpty())
return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_HEADER_CONTENT_TYPE), null);
int index = contentType.indexOf(";");
if (index != -1)
XSPReply reply = loader.load(new InputStreamReader(new ByteArrayInputStream(request.getContent())), resource, contentType);
if (!reply.isSuccess())
return XSPReplyUtils.toHttpResponse(reply, null);
代码示例来源:origin: org.xowl.platform/xowl-kernel-impl
/**
* Responds to a request for the policy resource
*
* @param request The web API request to handle
* @return The HTTP response
*/
private HttpResponse handleRequestPolicy(HttpApiRequest request) {
if (request.getUri().equals(apiUri + "/policy")) {
if (!HttpConstants.METHOD_GET.equals(request.getMethod()))
return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected GET method");
return XSPReplyUtils.toHttpResponse(getPolicy().getConfiguration(), null);
}
if (request.getUri().startsWith(apiUri + "/policy/actions/")) {
String rest = request.getUri().substring(apiUri.length() + "/policy/actions/".length());
String actionId = URIUtils.decodeComponent(rest);
if (actionId.isEmpty())
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
if (!HttpConstants.METHOD_PUT.equals(request.getMethod()))
return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected PUT method");
String definition = new String(request.getContent(), IOUtils.CHARSET);
return XSPReplyUtils.toHttpResponse(getPolicy().setPolicy(actionId, definition), null);
}
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
}
代码示例来源:origin: org.xowl.platform/xowl-service-connection
/**
* Responds to the request to push an artifact to a connector
* When successful, this action creates the appropriate job and returns it.
*
* @param connectorId The identifier of the connector to delete
* @param request The request to handle
* @return The response
*/
private HttpResponse onMessagePushToConnector(String connectorId, HttpApiRequest request) {
String artifact = request.getParameter("artifact");
if (artifact == null)
return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'artifact'"), null);
JobExecutionService executor = Register.getComponent(JobExecutionService.class);
if (executor == null)
return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null);
Job job = new PushArtifactJob(connectorId, artifact);
executor.schedule(job);
return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON());
}
}
代码示例来源:origin: org.xowl.platform/xowl-kernel-impl
if (job == null)
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
return XSPReplyUtils.toHttpResponse(cancel(job), null);
代码示例来源:origin: org.xowl.platform/xowl-service-lts
/**
* Responds to a request to delete an artifact
*
* @param parameters The request parameters
* @return The response
*/
private HttpResponse onMessageDeleteArtifact(Map<String, String[]> parameters) {
String[] ids = parameters.get("id");
if (ids == null || ids.length == 0)
return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter");
JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class);
if (executor == null)
return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null);
Job job = new DeleteArtifactJob(ids[0]);
executor.schedule(job);
return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON());
}
代码示例来源:origin: org.xowl.platform/xowl-service-lts
/**
* Responds to the request to pull an artifact from the live store
* When successful, this action creates the appropriate job and returns it.
*
* @param parameters The request parameters
* @return The response
*/
private HttpResponse onMessagePullFromLive(Map<String, String[]> parameters) {
String[] ids = parameters.get("id");
if (ids == null || ids.length == 0)
return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter");
JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class);
if (executor == null)
return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null);
Job job = new PullArtifactFromLiveJob(ids[0]);
executor.schedule(job);
return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON());
}
代码示例来源:origin: org.xowl.platform/xowl-service-lts
/**
* Responds to a request for the header of a specified artifact
*
* @param artifactId The identifier of an artifact
* @return The response
*/
private HttpResponse onMessageGetArtifactMetadata(String artifactId) {
XSPReply reply = retrieve(artifactId);
if (!reply.isSuccess())
return XSPReplyUtils.toHttpResponse(reply, null);
Artifact artifact = ((XSPReplyResult<Artifact>) reply).getData();
if (artifact == null)
return new HttpResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, HttpConstants.MIME_TEXT_PLAIN, "Failed to retrieve the artifact");
BufferedLogger logger = new BufferedLogger();
StringWriter writer = new StringWriter();
RDFSerializer serializer = new NQuadsSerializer(writer);
serializer.serialize(logger, artifact.getMetadata().iterator());
if (!logger.getErrorMessages().isEmpty())
return new HttpResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, HttpConstants.MIME_TEXT_PLAIN, logger.getErrorsAsString());
return new HttpResponse(HttpURLConnection.HTTP_OK, AbstractRepository.SYNTAX_NQUADS, writer.toString());
}
代码示例来源:origin: org.xowl.platform/xowl-service-lts
/**
* Responds to the request to push an artifact to the live store
* When successful, this action creates the appropriate job and returns it.
*
* @param parameters The request parameters
* @return The response
*/
private HttpResponse onMessagePushToLive(Map<String, String[]> parameters) {
String[] ids = parameters.get("id");
if (ids == null || ids.length == 0)
return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter");
JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class);
if (executor == null)
return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null);
Job job = new PushArtifactToLiveJob(ids[0]);
executor.schedule(job);
return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON());
}
}
代码示例来源:origin: org.xowl.platform/xowl-kernel-impl
/**
* Responds to a request for the login resource
*
* @param request The web API request to handle
* @return The HTTP response
*/
private HttpResponse handleRequestLogin(HttpApiRequest request) {
if (!HttpConstants.METHOD_POST.equals(request.getMethod()))
return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected POST method");
String login = request.getParameter("login");
if (login == null)
return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'login'"), null);
String password = new String(request.getContent(), IOUtils.CHARSET);
XSPReply reply = login(request.getClient(), login, password);
if (!reply.isSuccess())
return XSPReplyUtils.toHttpResponse(reply, null);
String token = ((XSPReplyResult<String>) reply).getData();
HttpResponse response = new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, getCurrentUser().serializedJSON());
response.addHeader(HttpConstants.HEADER_SET_COOKIE, AUTH_TOKEN + "=" + token +
"; Max-Age=" + Long.toString(securityTokenTTL) +
"; Path=" + PlatformHttp.getUriPrefixApi() +
"; Secure" +
"; HttpOnly");
return response;
}
代码示例来源:origin: org.xowl.platform/xowl-kernel-impl
/**
* Responds to a request for the logout resource
*
* @param request The web API request to handle
* @return The HTTP response
*/
private HttpResponse handleRequestLogout(HttpApiRequest request) {
if (!HttpConstants.METHOD_POST.equals(request.getMethod()))
return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected POST method");
XSPReply reply = logout();
if (!reply.isSuccess())
return XSPReplyUtils.toHttpResponse(reply, null);
HttpResponse response = new HttpResponse(HttpURLConnection.HTTP_OK);
response.addHeader(HttpConstants.HEADER_SET_COOKIE, AUTH_TOKEN + "= " +
"; Max-Age=0" +
"; Path=" + PlatformHttp.getUriPrefixApi() +
"; Secure" +
"; HttpOnly");
return response;
}
代码示例来源:origin: org.xowl.platform/xowl-service-connection
/**
* Responds to the request to pull an artifact from a connector
* When successful, this action creates the appropriate job and returns it.
*
* @param connectorId The identifier of the connector to delete
* @return The response
*/
private HttpResponse onMessagePullFromConnector(String connectorId) {
JobExecutionService executor = Register.getComponent(JobExecutionService.class);
if (executor == null)
return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null);
Job job = new PullArtifactJob(connectorId);
executor.schedule(job);
return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON());
}
代码示例来源:origin: org.xowl.platform/xowl-kernel-impl
/**
* Responds to a request for the values of a metric
*
* @param securityService The current security service
* @param identifier The requested metric
* @return The metrics' values
*/
private HttpResponse onMessageGetMetricValue(SecurityService securityService, String identifier) {
XSPReply reply = securityService.checkAction(ACTION_POLL);
if (!reply.isSuccess())
return XSPReplyUtils.toHttpResponse(reply, null);
MetricSnapshot value = pollMetric(identifier);
if (value == null)
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, value.serializedJSON());
}
代码示例来源:origin: org.xowl.platform/xowl-service-lts
/**
* Responds to a request for the content of a specified artifact
*
* @param artifactId The identifier of an artifact
* @return The artifact
*/
private HttpResponse onMessageGetArtifactContent(String artifactId) {
XSPReply reply = retrieve(artifactId);
if (!reply.isSuccess())
return XSPReplyUtils.toHttpResponse(reply, null);
Artifact artifact = ((XSPReplyResult<Artifact>) reply).getData();
if (artifact == null)
return new HttpResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, HttpConstants.MIME_TEXT_PLAIN, "Failed to retrieve the artifact");
Collection<Quad> content = artifact.getContent();
if (content == null)
return new HttpResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, HttpConstants.MIME_TEXT_PLAIN, "Failed to retrieve the content of the artifact");
BufferedLogger logger = new BufferedLogger();
StringWriter writer = new StringWriter();
RDFSerializer serializer = new NQuadsSerializer(writer);
serializer.serialize(logger, content.iterator());
if (!logger.getErrorMessages().isEmpty())
return new HttpResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, HttpConstants.MIME_TEXT_PLAIN, logger.getErrorsAsString());
return new HttpResponse(HttpURLConnection.HTTP_OK, AbstractRepository.SYNTAX_NQUADS, writer.toString());
}
代码示例来源:origin: org.xowl.platform/xowl-kernel-impl
/**
* Responds to a request for the definition of a metric
*
* @param securityService The current security service
* @param identifier The identifier of the requested metric
* @return The metrics
*/
private HttpResponse onMessageGetMetric(SecurityService securityService, String identifier) {
XSPReply reply = securityService.checkAction(ACTION_GET_METRICS);
if (!reply.isSuccess())
return XSPReplyUtils.toHttpResponse(reply, null);
for (MetricProvider provider : Register.getComponents(MeasurableService.class)) {
for (Metric metric : provider.getMetrics()) {
if (metric.getIdentifier().equals(identifier))
return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, metric.serializedJSON());
}
}
return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
}
内容来源于网络,如有侵权,请联系作者删除!