org.xowl.infra.server.xsp.XSPReplyUtils.toHttpResponse()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(15.6k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中org.xowl.infra.server.xsp.XSPReplyUtils.toHttpResponse()方法的一些代码示例,展示了XSPReplyUtils.toHttpResponse()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XSPReplyUtils.toHttpResponse()方法的具体详情如下:
包路径:org.xowl.infra.server.xsp.XSPReplyUtils
类名称:XSPReplyUtils
方法名:toHttpResponse

XSPReplyUtils.toHttpResponse介绍

暂无

代码示例

代码示例来源:origin: org.xowl.platform/xowl-service-connection

  1. /**
  2. * Responds to the request to delete a previously spawned parametric connector
  3. *
  4. * @param connectorId The identifier of the connector to delete
  5. * @return The response
  6. */
  7. private HttpResponse onMessageDeleteConnector(String connectorId) {
  8. XSPReply reply = delete(connectorId);
  9. return XSPReplyUtils.toHttpResponse(reply, null);
  10. }

代码示例来源:origin: org.xowl.platform/xowl-service-connection

  1. @Override
  2. public HttpResponse handle(SecurityService securedService, HttpApiRequest request) {
  3. return XSPReplyUtils.toHttpResponse(XSPReplyUnsupported.instance(), null);
  4. }

代码示例来源:origin: org.xowl.platform/xowl-service-domain

  1. /**
  2. * Responds to the request to delete a previously spawned parametric connector
  3. *
  4. * @param parameters The request parameters
  5. * @return The response
  6. */
  7. private HttpResponse onMessageDeleteConnector(Map<String, String[]> parameters) {
  8. String[] ids = parameters.get("id");
  9. if (ids == null || ids.length == 0)
  10. return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter");
  11. XSPReply reply = delete(ids[0]);
  12. return XSPReplyUtils.toHttpResponse(reply, null);
  13. }

代码示例来源:origin: org.xowl.platform/xowl-kernel-impl

  1. /**
  2. * Responds to a request for the list of available metrics
  3. *
  4. * @param securityService The current security service
  5. * @return The metrics
  6. */
  7. private HttpResponse onMessageGetMetricList(SecurityService securityService) {
  8. XSPReply reply = securityService.checkAction(ACTION_GET_METRICS);
  9. if (!reply.isSuccess())
  10. return XSPReplyUtils.toHttpResponse(reply, null);
  11. // get all the metrics
  12. boolean first = true;
  13. StringBuilder builder = new StringBuilder("[");
  14. for (Metric metric : getMetrics()) {
  15. if (!first)
  16. builder.append(", ");
  17. first = false;
  18. builder.append(metric.serializedJSON());
  19. }
  20. builder.append("]");
  21. return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, builder.toString());
  22. }

代码示例来源:origin: org.xowl.platform/xowl-service-impact

  1. @Override
  2. public HttpResponse handle(SecurityService securityService, HttpApiRequest request) {
  3. if (!HttpConstants.METHOD_POST.equals(request.getMethod()))
  4. return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected POST method");
  5. byte[] content = request.getContent();
  6. if (content == null || content.length == 0)
  7. return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_FAILED_TO_READ_CONTENT), null);
  8. BufferedLogger logger = new BufferedLogger();
  9. ASTNode root = JSONLDLoader.parseJSON(logger, new String(content, IOUtils.CHARSET));
  10. if (root == null)
  11. return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_CONTENT_PARSING_FAILED, logger.getErrorsAsString()), null);
  12. return XSPReplyUtils.toHttpResponse(perform(new XOWLImpactAnalysisSetup(root)), null);
  13. }

代码示例来源:origin: org.xowl.platform/xowl-kernel-impl

  1. @Override
  2. public HttpResponse handle(SecurityService securityService, HttpApiRequest request) {
  3. XSPReply reply = securityService.checkAction(ACTION_GET_LOG);
  4. if (!reply.isSuccess())
  5. return XSPReplyUtils.toHttpResponse(reply, null);
  6. if (!HttpConstants.METHOD_GET.equals(request.getMethod()))
  7. return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected GET method");
  8. StringBuilder builder = new StringBuilder("[");
  9. boolean first = true;
  10. for (PlatformLogMessage message : buffer.getMessages()) {
  11. if (!first)
  12. builder.append(", ");
  13. first = false;
  14. builder.append(message.serializedJSON());
  15. }
  16. builder.append("]");
  17. return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, builder.toString());
  18. }

代码示例来源:origin: org.xowl.platform/xowl-connector-semanticweb

  1. String contentType = request.getContentType();
  2. if (name == null)
  3. return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'name'"), null);
  4. if (base == null)
  5. return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'base'"), null);
  6. if (version == null)
  7. return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'version'"), null);
  8. if (archetype == null)
  9. return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'archetype'"), null);
  10. if (contentType == null || contentType.isEmpty())
  11. return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_HEADER_CONTENT_TYPE), null);
  12. int index = contentType.indexOf(";");
  13. if (index != -1)
  14. XSPReply reply = loader.load(new InputStreamReader(new ByteArrayInputStream(request.getContent())), resource, contentType);
  15. if (!reply.isSuccess())
  16. return XSPReplyUtils.toHttpResponse(reply, null);

代码示例来源:origin: org.xowl.platform/xowl-kernel-impl

  1. /**
  2. * Responds to a request for the policy resource
  3. *
  4. * @param request The web API request to handle
  5. * @return The HTTP response
  6. */
  7. private HttpResponse handleRequestPolicy(HttpApiRequest request) {
  8. if (request.getUri().equals(apiUri + "/policy")) {
  9. if (!HttpConstants.METHOD_GET.equals(request.getMethod()))
  10. return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected GET method");
  11. return XSPReplyUtils.toHttpResponse(getPolicy().getConfiguration(), null);
  12. }
  13. if (request.getUri().startsWith(apiUri + "/policy/actions/")) {
  14. String rest = request.getUri().substring(apiUri.length() + "/policy/actions/".length());
  15. String actionId = URIUtils.decodeComponent(rest);
  16. if (actionId.isEmpty())
  17. return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
  18. if (!HttpConstants.METHOD_PUT.equals(request.getMethod()))
  19. return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected PUT method");
  20. String definition = new String(request.getContent(), IOUtils.CHARSET);
  21. return XSPReplyUtils.toHttpResponse(getPolicy().setPolicy(actionId, definition), null);
  22. }
  23. return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
  24. }

代码示例来源:origin: org.xowl.platform/xowl-service-connection

  1. /**
  2. * Responds to the request to push an artifact to a connector
  3. * When successful, this action creates the appropriate job and returns it.
  4. *
  5. * @param connectorId The identifier of the connector to delete
  6. * @param request The request to handle
  7. * @return The response
  8. */
  9. private HttpResponse onMessagePushToConnector(String connectorId, HttpApiRequest request) {
  10. String artifact = request.getParameter("artifact");
  11. if (artifact == null)
  12. return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'artifact'"), null);
  13. JobExecutionService executor = Register.getComponent(JobExecutionService.class);
  14. if (executor == null)
  15. return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null);
  16. Job job = new PushArtifactJob(connectorId, artifact);
  17. executor.schedule(job);
  18. return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON());
  19. }
  20. }

代码示例来源:origin: org.xowl.platform/xowl-kernel-impl

  1. if (job == null)
  2. return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
  3. return XSPReplyUtils.toHttpResponse(cancel(job), null);

代码示例来源:origin: org.xowl.platform/xowl-service-lts

  1. /**
  2. * Responds to a request to delete an artifact
  3. *
  4. * @param parameters The request parameters
  5. * @return The response
  6. */
  7. private HttpResponse onMessageDeleteArtifact(Map<String, String[]> parameters) {
  8. String[] ids = parameters.get("id");
  9. if (ids == null || ids.length == 0)
  10. return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter");
  11. JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class);
  12. if (executor == null)
  13. return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null);
  14. Job job = new DeleteArtifactJob(ids[0]);
  15. executor.schedule(job);
  16. return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON());
  17. }

代码示例来源:origin: org.xowl.platform/xowl-service-lts

  1. /**
  2. * Responds to the request to pull an artifact from the live store
  3. * When successful, this action creates the appropriate job and returns it.
  4. *
  5. * @param parameters The request parameters
  6. * @return The response
  7. */
  8. private HttpResponse onMessagePullFromLive(Map<String, String[]> parameters) {
  9. String[] ids = parameters.get("id");
  10. if (ids == null || ids.length == 0)
  11. return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter");
  12. JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class);
  13. if (executor == null)
  14. return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null);
  15. Job job = new PullArtifactFromLiveJob(ids[0]);
  16. executor.schedule(job);
  17. return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON());
  18. }

代码示例来源:origin: org.xowl.platform/xowl-service-lts

  1. /**
  2. * Responds to a request for the header of a specified artifact
  3. *
  4. * @param artifactId The identifier of an artifact
  5. * @return The response
  6. */
  7. private HttpResponse onMessageGetArtifactMetadata(String artifactId) {
  8. XSPReply reply = retrieve(artifactId);
  9. if (!reply.isSuccess())
  10. return XSPReplyUtils.toHttpResponse(reply, null);
  11. Artifact artifact = ((XSPReplyResult<Artifact>) reply).getData();
  12. if (artifact == null)
  13. return new HttpResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, HttpConstants.MIME_TEXT_PLAIN, "Failed to retrieve the artifact");
  14. BufferedLogger logger = new BufferedLogger();
  15. StringWriter writer = new StringWriter();
  16. RDFSerializer serializer = new NQuadsSerializer(writer);
  17. serializer.serialize(logger, artifact.getMetadata().iterator());
  18. if (!logger.getErrorMessages().isEmpty())
  19. return new HttpResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, HttpConstants.MIME_TEXT_PLAIN, logger.getErrorsAsString());
  20. return new HttpResponse(HttpURLConnection.HTTP_OK, AbstractRepository.SYNTAX_NQUADS, writer.toString());
  21. }

代码示例来源:origin: org.xowl.platform/xowl-service-lts

  1. /**
  2. * Responds to the request to push an artifact to the live store
  3. * When successful, this action creates the appropriate job and returns it.
  4. *
  5. * @param parameters The request parameters
  6. * @return The response
  7. */
  8. private HttpResponse onMessagePushToLive(Map<String, String[]> parameters) {
  9. String[] ids = parameters.get("id");
  10. if (ids == null || ids.length == 0)
  11. return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter");
  12. JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class);
  13. if (executor == null)
  14. return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null);
  15. Job job = new PushArtifactToLiveJob(ids[0]);
  16. executor.schedule(job);
  17. return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON());
  18. }
  19. }

代码示例来源:origin: org.xowl.platform/xowl-kernel-impl

  1. /**
  2. * Responds to a request for the login resource
  3. *
  4. * @param request The web API request to handle
  5. * @return The HTTP response
  6. */
  7. private HttpResponse handleRequestLogin(HttpApiRequest request) {
  8. if (!HttpConstants.METHOD_POST.equals(request.getMethod()))
  9. return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected POST method");
  10. String login = request.getParameter("login");
  11. if (login == null)
  12. return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'login'"), null);
  13. String password = new String(request.getContent(), IOUtils.CHARSET);
  14. XSPReply reply = login(request.getClient(), login, password);
  15. if (!reply.isSuccess())
  16. return XSPReplyUtils.toHttpResponse(reply, null);
  17. String token = ((XSPReplyResult<String>) reply).getData();
  18. HttpResponse response = new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, getCurrentUser().serializedJSON());
  19. response.addHeader(HttpConstants.HEADER_SET_COOKIE, AUTH_TOKEN + "=" + token +
  20. "; Max-Age=" + Long.toString(securityTokenTTL) +
  21. "; Path=" + PlatformHttp.getUriPrefixApi() +
  22. "; Secure" +
  23. "; HttpOnly");
  24. return response;
  25. }

代码示例来源:origin: org.xowl.platform/xowl-kernel-impl

  1. /**
  2. * Responds to a request for the logout resource
  3. *
  4. * @param request The web API request to handle
  5. * @return The HTTP response
  6. */
  7. private HttpResponse handleRequestLogout(HttpApiRequest request) {
  8. if (!HttpConstants.METHOD_POST.equals(request.getMethod()))
  9. return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected POST method");
  10. XSPReply reply = logout();
  11. if (!reply.isSuccess())
  12. return XSPReplyUtils.toHttpResponse(reply, null);
  13. HttpResponse response = new HttpResponse(HttpURLConnection.HTTP_OK);
  14. response.addHeader(HttpConstants.HEADER_SET_COOKIE, AUTH_TOKEN + "= " +
  15. "; Max-Age=0" +
  16. "; Path=" + PlatformHttp.getUriPrefixApi() +
  17. "; Secure" +
  18. "; HttpOnly");
  19. return response;
  20. }

代码示例来源:origin: org.xowl.platform/xowl-service-connection

  1. /**
  2. * Responds to the request to pull an artifact from a connector
  3. * When successful, this action creates the appropriate job and returns it.
  4. *
  5. * @param connectorId The identifier of the connector to delete
  6. * @return The response
  7. */
  8. private HttpResponse onMessagePullFromConnector(String connectorId) {
  9. JobExecutionService executor = Register.getComponent(JobExecutionService.class);
  10. if (executor == null)
  11. return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null);
  12. Job job = new PullArtifactJob(connectorId);
  13. executor.schedule(job);
  14. return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON());
  15. }

代码示例来源:origin: org.xowl.platform/xowl-kernel-impl

  1. /**
  2. * Responds to a request for the values of a metric
  3. *
  4. * @param securityService The current security service
  5. * @param identifier The requested metric
  6. * @return The metrics' values
  7. */
  8. private HttpResponse onMessageGetMetricValue(SecurityService securityService, String identifier) {
  9. XSPReply reply = securityService.checkAction(ACTION_POLL);
  10. if (!reply.isSuccess())
  11. return XSPReplyUtils.toHttpResponse(reply, null);
  12. MetricSnapshot value = pollMetric(identifier);
  13. if (value == null)
  14. return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
  15. return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, value.serializedJSON());
  16. }

代码示例来源:origin: org.xowl.platform/xowl-service-lts

  1. /**
  2. * Responds to a request for the content of a specified artifact
  3. *
  4. * @param artifactId The identifier of an artifact
  5. * @return The artifact
  6. */
  7. private HttpResponse onMessageGetArtifactContent(String artifactId) {
  8. XSPReply reply = retrieve(artifactId);
  9. if (!reply.isSuccess())
  10. return XSPReplyUtils.toHttpResponse(reply, null);
  11. Artifact artifact = ((XSPReplyResult<Artifact>) reply).getData();
  12. if (artifact == null)
  13. return new HttpResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, HttpConstants.MIME_TEXT_PLAIN, "Failed to retrieve the artifact");
  14. Collection<Quad> content = artifact.getContent();
  15. if (content == null)
  16. return new HttpResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, HttpConstants.MIME_TEXT_PLAIN, "Failed to retrieve the content of the artifact");
  17. BufferedLogger logger = new BufferedLogger();
  18. StringWriter writer = new StringWriter();
  19. RDFSerializer serializer = new NQuadsSerializer(writer);
  20. serializer.serialize(logger, content.iterator());
  21. if (!logger.getErrorMessages().isEmpty())
  22. return new HttpResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, HttpConstants.MIME_TEXT_PLAIN, logger.getErrorsAsString());
  23. return new HttpResponse(HttpURLConnection.HTTP_OK, AbstractRepository.SYNTAX_NQUADS, writer.toString());
  24. }

代码示例来源:origin: org.xowl.platform/xowl-kernel-impl

  1. /**
  2. * Responds to a request for the definition of a metric
  3. *
  4. * @param securityService The current security service
  5. * @param identifier The identifier of the requested metric
  6. * @return The metrics
  7. */
  8. private HttpResponse onMessageGetMetric(SecurityService securityService, String identifier) {
  9. XSPReply reply = securityService.checkAction(ACTION_GET_METRICS);
  10. if (!reply.isSuccess())
  11. return XSPReplyUtils.toHttpResponse(reply, null);
  12. for (MetricProvider provider : Register.getComponents(MeasurableService.class)) {
  13. for (Metric metric : provider.getMetrics()) {
  14. if (metric.getIdentifier().equals(identifier))
  15. return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, metric.serializedJSON());
  16. }
  17. }
  18. return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND);
  19. }

相关文章

XSPReplyUtils类方法