enter image description here public class GemfireTest extends 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());
Server in C:\Users\xxx\IdeaProjects\Gemfire on DESKTOP-MRCV2EH[40404] as server1 is currently online. Process ID: 2640 Uptime: 7 seconds Geode Version: 9.5.1 Java Version: 1.8.0_171 Log File: C:\Users\xxx\IdeaProjects\Gemfire\server1.log JVM Arguments: -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
Getting response code : -1 , Invalid Http response.
How can i solve this issue?
I've tested your source code locally (plus one/two small modifications), and everything seems to work just fine:
Running the above program prints the following:
Did you correctly set the
GEODE_HOME
environment variable?, what about theport
used when executing thecurl
command?, is the same number that you configured through thehttp-service-port
property?. Cheers.It seems that you're missing the
GEODE_HOME
environment variable within your source code, which is needed by the server during the startup in order to find the libraries required to start the REST API, specificallyinstall-dir/tools/Extensions/geode-web-api-n.n.n.war
. You can find more details about this in Setup and Configuration.Hope this helps. Cheers.