Package org.elasticsearch.rest

Examples of org.elasticsearch.rest.BytesRestResponse


            new JRMgmBaseActionListener<JRStateRequest, JRStateResponse, NodeJRStateResponse>(actionRequest,
                restRequest, restChannel) {

              @Override
              protected void handleJiraRiverResponse(NodeJRStateResponse nodeInfo) throws Exception {
                restChannel.sendResponse(new BytesRestResponse(RestStatus.OK, XContentType.JSON.restContentType(),
                    nodeInfo.stateInformation.getBytes()));
              }

            });
  }
View Full Code Here


              @Override
              protected void handleJiraRiverResponse(NodeFullUpdateResponse nodeInfo) throws Exception {
                if (actionRequest.isProjectKeyRequest() && !nodeInfo.projectFound) {
                  restChannel
                      .sendResponse(new BytesRestResponse(RestStatus.NOT_FOUND, buildMessageDocument(restRequest,
                          "Project '" + projectKey + "' is not indexed by JiraRiver with name: " + riverName)));
                } else {
                  restChannel.sendResponse(new BytesRestResponse(OK, buildMessageDocument(restRequest,
                      "Scheduled full reindex for JIRA projects: " + nodeInfo.reindexedProjectNames)));
                }
              }

            });
View Full Code Here

            new JRMgmBaseActionListener<JRStateRequest, JRStateResponse, NodeJRStateResponse>(actionRequest,
                restRequest, restChannel) {

              @Override
              protected void handleJiraRiverResponse(NodeJRStateResponse nodeInfo) throws Exception {
                restChannel.sendResponse(new BytesRestResponse(nodeInfo.stateInformation.getBytes(), XContentType.JSON
                    .restContentType()));
              }

            });
  }
View Full Code Here

      if (arg != null && !arg.isEmpty()) {
        builder.field("message", arg);
      }

      builder.endObject();
      channel.sendResponse(new BytesRestResponse(status, builder));
    } catch (final Exception e) {
      log.error("Failed to send a response.", e);
      try {
        channel.sendResponse(new BytesRestResponse(channel,
            e));
      } catch (final IOException e1) {
        log.error("Failed to send a failure response.", e1);
      }
    }
View Full Code Here

                    }
                }
            }
        } catch (Throwable e) {
            try {
                channel.sendResponse(new BytesRestResponse(channel, e));
            } catch (Throwable e1) {
                logger.error("failed to send failure response for uri [" + request.uri() + "]", e1);
            }
        }
    }
View Full Code Here

        }
    }

    void handlePluginSite(HttpRequest request, HttpChannel channel) {
        if (disableSites) {
            channel.sendResponse(new BytesRestResponse(FORBIDDEN));
            return;
        }
        if (request.method().name().equals("OPTIONS")) {
            // when we have OPTIONS request, simply send OK by default (with the Access Control Origin header which gets automatically added)
            channel.sendResponse(new BytesRestResponse(OK));
            return;
        }
        if (request.method().name().equals("GET")) {
            channel.sendResponse(new BytesRestResponse(FORBIDDEN));
            return;
        }
        // TODO for a "/_plugin" endpoint, we should have a page that lists all the plugins?

        String path = request.rawPath().substring("/_plugin/".length());
        int i1 = path.indexOf('/');
        String pluginName;
        String sitePath;
        if (i1 == -1) {
            pluginName = path;
            sitePath = null;
            // If a trailing / is missing, we redirect to the right page #2654
            channel.sendResponse(new BytesRestResponse(RestStatus.MOVED_PERMANENTLY, "text/html", "<head><meta http-equiv=\"refresh\" content=\"0; URL=" + request.rawPath() + "/\"></head>"));
            return;
        } else {
            pluginName = path.substring(0, i1);
            sitePath = path.substring(i1 + 1);
        }

        if (sitePath.length() == 0) {
            sitePath = "/index.html";
        }

        // Convert file separators.
        sitePath = sitePath.replace('/', File.separatorChar);

        // this is a plugin provided site, serve it as static files from the plugin location
        File siteFile = new File(new File(environment.pluginsFile(), pluginName), "_site");
        File file = new File(siteFile, sitePath);
        if (!file.exists() || file.isHidden()) {
            channel.sendResponse(new BytesRestResponse(NOT_FOUND));
            return;
        }
        if (!file.isFile()) {
            // If it's not a dir, we send a 403
            if (!file.isDirectory()) {
                channel.sendResponse(new BytesRestResponse(FORBIDDEN));
                return;
            }
            // We don't serve dir but if index.html exists in dir we should serve it
            file = new File(file, "index.html");
            if (!file.exists() || file.isHidden() || !file.isFile()) {
                channel.sendResponse(new BytesRestResponse(FORBIDDEN));
                return;
            }
        }
        if (!file.getAbsolutePath().startsWith(siteFile.getAbsolutePath())) {
            channel.sendResponse(new BytesRestResponse(FORBIDDEN));
            return;
        }
        try {
            byte[] data = Streams.copyToByteArray(file);
            channel.sendResponse(new BytesRestResponse(OK, guessMimeType(sitePath), data));
        } catch (IOException e) {
            channel.sendResponse(new BytesRestResponse(INTERNAL_SERVER_ERROR));
        }
    }
View Full Code Here

            new JRMgmBaseActionListener<JRStateRequest, JRStateResponse, NodeJRStateResponse>(actionRequest,
                restRequest, restChannel) {

              @Override
              protected void handleRiverResponse(NodeJRStateResponse nodeInfo) throws Exception {
                restChannel.sendResponse(new BytesRestResponse(nodeInfo.stateInformation.getBytes(), XContentType.JSON
                    .restContentType()));
              }

            });
  }
View Full Code Here

                restRequest, restChannel) {

              @Override
              protected void handleRiverResponse(NodeJRPeriodResponse nodeInfo) throws Exception {
                if (nodeInfo.indexerFound) {
                  restChannel.sendResponse(new BytesRestResponse(OK, buildMessageDocument(restRequest,
                      "Period changed to " + period + "[ms] for at least one of defined indexers")));
                } else {
                  restChannel.sendResponse(new BytesRestResponse(RestStatus.NOT_FOUND, buildMessageDocument(
                      restRequest, "No any of defined indexers '" + indexerNames + "' found")));
                }
              }

            });
View Full Code Here

            new JRMgmBaseActionListener<JRLifecycleRequest, JRLifecycleResponse, NodeJRLifecycleResponse>(
                actionRequest, restRequest, restChannel) {

              @Override
              protected void handleRiverResponse(NodeJRLifecycleResponse nodeInfo) throws Exception {
                restChannel.sendResponse(new BytesRestResponse(OK, buildMessageDocument(restRequest,
                    "Command successful")));
              }

            });
  }
View Full Code Here

              XContentBuilder builder = RestXContentBuilder.restContentBuilder(restRequest);
              builder.startObject();
              builder.field("sysinfo_river_names", allRivers);
              builder.endObject();
              restChannel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
            } catch (Exception e) {
              onFailure(e);
            }
          }

          @Override
          public void onFailure(Throwable e) {
            try {
              restChannel.sendResponse(new BytesRestResponse(restChannel, e));
            } catch (IOException e1) {
              logger.error("Failed to send failure response", e1);
            }
          }
View Full Code Here

TOP

Related Classes of org.elasticsearch.rest.BytesRestResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.