Hi there,
my target is to develop a java client, which has access to the open xchange
http-api and lists the available calendars. I tried to access it with the following login-method:
public User loginUser(String name, String password, String redirect) {
BufferedReader reader = null;
try {
URL url = new URL("http://localhost:8084/ajax/login?action=login&name=" + name + "&password=" + password);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
cookie += conn.getHeaderField("Set-Cookie");
if (cookie.contains("; path=/")) {
cookie = cookie.substring(0, cookie.indexOf("; path=/"));
}
System.out.println("cookie: " + cookie);
reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line = null;
String result = "";
while ((line = reader.readLine()) != null) {
result += line;
}
reader.close();
System.out.println("Result login: " + result);
JSONObject obj = new JSONObject(result);
String session = obj.getString("session");
url = new URL("http://localhost:8084/ajax/calendar?action=all&session=" + session);
System.out.println("URL3: " + url.toString());
HttpURLConnection connCal = (HttpURLConnection) url.openConnection();
connCal.setRequestProperty("Cookie", cookie);
connCal.connect();
reader = new BufferedReader(new InputStreamReader(connCal.getInputStream()));
result = "";
while ((line = reader.readLine()) != null) {
result += line;
}
reader.close();
System.out.println("Result calendars: " + result);
return null;
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return null;
}
I thought it was the right way to access via http-api, but my java console says this:
cookie: open-xchange-session-9af7232dde2c45e5afb709e822551205=e534460f81cd406d9 d1dfec3ae73c64c
Result login: {"session":"59e32f8b4a954e3787d9a897a177f07c","ran dom":"dc028e84f3bd4468b54255be234df536"}
URL3: http://localhost:8084/ajax/calendar?...d9a897a177f07c
Result calendars: {"code":"SES-0202","error_id":"1643285578-1","category":8,"error_params":[],"error":"The cookie with the session identifier is missing."}
Can someone give me a code example, which corrects my failures? Thanks
for any help,
Jan
my target is to develop a java client, which has access to the open xchange
http-api and lists the available calendars. I tried to access it with the following login-method:
public User loginUser(String name, String password, String redirect) {
BufferedReader reader = null;
try {
URL url = new URL("http://localhost:8084/ajax/login?action=login&name=" + name + "&password=" + password);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
cookie += conn.getHeaderField("Set-Cookie");
if (cookie.contains("; path=/")) {
cookie = cookie.substring(0, cookie.indexOf("; path=/"));
}
System.out.println("cookie: " + cookie);
reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line = null;
String result = "";
while ((line = reader.readLine()) != null) {
result += line;
}
reader.close();
System.out.println("Result login: " + result);
JSONObject obj = new JSONObject(result);
String session = obj.getString("session");
url = new URL("http://localhost:8084/ajax/calendar?action=all&session=" + session);
System.out.println("URL3: " + url.toString());
HttpURLConnection connCal = (HttpURLConnection) url.openConnection();
connCal.setRequestProperty("Cookie", cookie);
connCal.connect();
reader = new BufferedReader(new InputStreamReader(connCal.getInputStream()));
result = "";
while ((line = reader.readLine()) != null) {
result += line;
}
reader.close();
System.out.println("Result calendars: " + result);
return null;
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return null;
}
I thought it was the right way to access via http-api, but my java console says this:
cookie: open-xchange-session-9af7232dde2c45e5afb709e822551205=e534460f81cd406d9 d1dfec3ae73c64c
Result login: {"session":"59e32f8b4a954e3787d9a897a177f07c","ran dom":"dc028e84f3bd4468b54255be234df536"}
URL3: http://localhost:8084/ajax/calendar?...d9a897a177f07c
Result calendars: {"code":"SES-0202","error_id":"1643285578-1","category":8,"error_params":[],"error":"The cookie with the session identifier is missing."}
Can someone give me a code example, which corrects my failures? Thanks
for any help,
Jan
Comment