Неверный Http-ответ для Gemfire? - PullRequest
       8

Неверный Http-ответ для Gemfire?

0 голосов
/ 27 сентября 2018

введите описание изображения здесь открытый класс GemfireTest расширяет SecurityManager {

            public static void main(String[] args) throws NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException, IOException {

                System.setProperty("gemfire.locators", "localhost[8091]");
                Properties properties = new Properties();

             ServerLauncher serverLauncher = new ServerLauncher.Builder()

                        .setMemberName("server1")
                        .setServerPort(40404)
                        .set("start-locator", "localhost[8091]")
            .build();
                serverLauncher.start();
                System.out.println(serverLauncher.status());
String restapi ="http://localhost:8091/gemfire-api/v1/";
             //   URLConnection urlConnection = new URL(restapi).openConnection();
                try {
                    URL obj = new URL(restapi);
                    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
                    con.setRequestMethod("GET");
                    con.setRequestProperty("accept","application/json");
                    int responseCode = con.getResponseCode();
                    System.out.println(responseCode);
                   // if (responseCode == HttpURLConnection.HTTP_OK) { // success
                        BufferedReader in = new BufferedReader(new InputStreamReader(
                                con.getInputStream()));
                        String inputLine;
                        StringBuffer response = new StringBuffer();

                        while ((inputLine = in.readLine()) != null) {
                            response.append(inputLine);
                        }
                        in.close();

                        // print result
                        System.out.println("reason"+response.toString());

Сервер в C: \ Users \ xxx \ IdeaProjects \ Gemfire на DESKTOP-MRCV2EH [40404]поскольку server1 в настоящее время онлайн.Идентификатор процесса: 2640 Время работы: 7 секунд Версия Geode: 9.5.1 Версия Java: 1.8.0_171 Файл журнала: C: \ Users \ xxx \ IdeaProjects \ Gemfire \ server1.log Аргументы JVM: -Dgemfire.enable-cluster-configuration = true-Dgemfire.load-cluster-configuration-from-dir = false -Dgemfire.jmx-manager-bind-address = localhost -Djava.rmi.server.hostname = localhost -Dgemfire.launcher.registerSignalHandlers = true -Djava.awt.headless= true -javaagent: C: \ Program Files \ JetBrains \ IntelliJ IDEA Community Edition 2017.3.2 \ lib \ idea_rt.jar = 54053: C: \ Program Files \ JetBrains \ IntelliJ IDEA Community Edition 2017.3.2 \ bin -Dfile.encoding= UTF-8

Получение кода ответа: -1, Неверный Http-ответ.

Как мне решить эту проблему?

Ответы [ 2 ]

0 голосов
/ 28 сентября 2018

Я протестировал ваш исходный код локально (плюс одна / две небольшие модификации), и все, кажется, работает просто отлично:

public static void main(String[] args) throws IOException {
    Integer httpServicePort = 8080;
    ServerLauncher serverLauncher = 
        new ServerLauncher.Builder()
        .set("log-file", "")
        .set("http-service-port", httpServicePort.toString())   
        .set("start-dev-rest-api", "true")
        .set("http-service-bind-address", "localhost")
        .setPdxReadSerialized(true)
        .build();

    serverLauncher.start();
    System.out.println("REST server successfully started, press any key to stop it...");
    String restapi ="http://localhost:" + httpServicePort + "/gemfire-api/v1/";

    try {
        URL obj = new URL(restapi);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("GET");
        con.setRequestProperty("accept","application/json");
        int responseCode = con.getResponseCode();
        System.out.println("Response Code: " + responseCode);

         if (responseCode == HttpURLConnection.HTTP_OK) { // success
               BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
               String inputLine;
               StringBuffer response = new StringBuffer();
               while ((inputLine = in.readLine()) != null) {
                   response.append(inputLine);
               }

               in.close();
               System.out.println("Response: " + response.toString());
         }
    } catch (Exception exception) {
        exception.printStackTrace();
    }

    System.in.read();
    serverLauncher.stop();
    System.exit(0);
}

При запуске вышеуказанной программы выводится следующее:

REST server successfully started, press any key to stop it...
Response Code: 200
Response: {  "regions" : [ ]}

Правильно ли установлена ​​переменная окружения GEODE_HOME? Как насчет port, используемого при выполнении команды curl?, Это тот же номер, который вы настроили с помощью свойства http-service-port ?.Приветствия.

0 голосов
/ 28 сентября 2018

Кажется, что в исходном коде отсутствует переменная окружения GEODE_HOME, которая необходима серверу во время запуска для поиска библиотек, необходимых для запуска REST API, в частности install-dir/tools/Extensions/geode-web-api-n.n.n.war.Вы можете найти более подробную информацию об этом в Настройка и настройка .

Надеюсь, это поможет.Приветствия.

...