Commit 1588d977 authored by Gabriel Guardincerri's avatar Gabriel Guardincerri Committed by gguardin

Solved testing OF -> CS conection during setup always returns OK. JM-1280

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/openfire_3_5_0@10002 b35dd754-fafc-0310-a699-88a17e54d16e
parent df7f1801
...@@ -28,7 +28,6 @@ import org.jivesoftware.openfire.auth.AuthFactory; ...@@ -28,7 +28,6 @@ import org.jivesoftware.openfire.auth.AuthFactory;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.GET; import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.GET;
import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.POST; import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.POST;
import static org.jivesoftware.openfire.clearspace.WSUtils.getReturn;
import org.jivesoftware.openfire.component.ExternalComponentConfiguration; import org.jivesoftware.openfire.component.ExternalComponentConfiguration;
import org.jivesoftware.openfire.component.ExternalComponentManager; import org.jivesoftware.openfire.component.ExternalComponentManager;
import org.jivesoftware.openfire.component.ExternalComponentManagerListener; import org.jivesoftware.openfire.component.ExternalComponentManagerListener;
...@@ -161,23 +160,7 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM ...@@ -161,23 +160,7 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
super("Clearspace integration module for testing only"); super("Clearspace integration module for testing only");
this.properties = properties; this.properties = properties;
this.uri = properties.get("clearspace.uri"); init();
if (!this.uri.endsWith("/")) {
this.uri = this.uri + "/";
}
sharedSecret = properties.get("clearspace.sharedSecret");
userIDCache = Collections.synchronizedMap(new HashMap<String, Long>());
groupIDCache = Collections.synchronizedMap(new HashMap<String, Long>());
if (Log.isDebugEnabled()) {
StringBuilder buf = new StringBuilder();
buf.append("Created new ClearspaceManager() instance, fields:\n");
buf.append("\t URI: ").append(uri).append("\n");
buf.append("\t sharedSecret: ").append(sharedSecret).append("\n");
Log.debug("ClearspaceManager: " + buf.toString());
}
} }
/** /**
...@@ -244,21 +227,24 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM ...@@ -244,21 +227,24 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
} }
}; };
this.uri = JiveGlobals.getXMLProperty("clearspace.uri"); init();
sharedSecret = JiveGlobals.getXMLProperty("clearspace.sharedSecret"); }
private void init() {
this.uri = properties.get("clearspace.uri");
if (uri != null) {
if (!this.uri.endsWith("/")) {
this.uri = this.uri + "/";
}
// Updates the host/port attributes based on the uri
updateHostPort();
}
sharedSecret = properties.get("clearspace.sharedSecret");
// Creates the cache maps
userIDCache = Collections.synchronizedMap(new HashMap<String, Long>()); userIDCache = Collections.synchronizedMap(new HashMap<String, Long>());
groupIDCache = Collections.synchronizedMap(new HashMap<String, Long>()); groupIDCache = Collections.synchronizedMap(new HashMap<String, Long>());
if (uri != null && !"".equals(uri.trim())) {
try {
URL url = new URL(uri);
host = url.getHost();
port = url.getPort();
} catch (MalformedURLException e) {
// this won't happen
}
}
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
...@@ -270,6 +256,21 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM ...@@ -270,6 +256,21 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
} }
} }
/**
* Updates the host port attributes based on the URI.
*/
private void updateHostPort() {
if (uri != null && !"".equals(uri.trim())) {
try {
URL url = new URL(uri);
host = url.getHost();
port = url.getPort();
} catch (MalformedURLException e) {
// this won't happen
}
}
}
/** /**
* Check a username/password pair for valid authentication. * Check a username/password pair for valid authentication.
* *
...@@ -297,12 +298,13 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM ...@@ -297,12 +298,13 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
public Boolean testConnection() { public Boolean testConnection() {
// Test invoking a simple method // Test invoking a simple method
try { try {
String path = ClearspaceUserProvider.USER_URL_PREFIX + "users/count"; // If there is a problem with the URL or the user/password this service throws an exception
Element element = executeRequest(GET, path); String path = IM_URL_PREFIX + "testCredentials";
getReturn(element); executeRequest(GET, path);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
// Nothing to do. // It is not ok, return false.
} }
return false; return false;
...@@ -330,6 +332,10 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM ...@@ -330,6 +332,10 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
} }
this.uri = uri; this.uri = uri;
properties.put("clearspace.uri", uri); properties.put("clearspace.uri", uri);
//Updates the host/port attributes
updateHostPort();
if (isEnabled()) { if (isEnabled()) {
startClearspaceConfig(); startClearspaceConfig();
} }
...@@ -641,6 +647,12 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM ...@@ -641,6 +647,12 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("Outgoing REST call results: " + body); Log.debug("Outgoing REST call results: " + body);
} }
// Checks the http status
if (method.getStatusCode() != 200) {
throw new ConnectException("Error connecting to Clearspace, http status code: " + method.getStatusCode());
}
Element response = localParser.get().parseDocument(body).getRootElement(); Element response = localParser.get().parseDocument(body).getRootElement();
// Check for exceptions // Check for exceptions
......
package org.jivesoftware.openfire.clearspace;
/**
* Thrown when an exception occurs connecting to CS.
*/
public class ConnectException extends Exception {
public ConnectException() {
super();
}
public ConnectException(String s) {
super(s);
}
public ConnectException(String s, Throwable throwable) {
super(s, throwable);
}
public ConnectException(Throwable throwable) {
super(throwable);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment