hs.hsadmin/hsarweb/src/de/hsadmin/web/Remote.java

61 lines
1.5 KiB
Java
Raw Normal View History

2010-09-23 17:30:34 +02:00
package de.hsadmin.web;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
@ManagedBean(name="remote")
@SessionScoped
public class Remote {
private XmlRpcClient client;
@ManagedProperty(value="#{context}")
private Context context;
public Remote() throws HsarwebException {
2010-10-05 21:43:30 +02:00
client = null;
2010-09-23 17:30:34 +02:00
}
public Object callSearch(String module, String user, Map<String, String> where) throws HsarwebException {
Object[] params = new Object[3];
params[0] = user;
params[1] = context.getProxyTicket();
params[2] = where;
Object res;
try {
2010-10-05 21:43:30 +02:00
res = getClient().execute(module + ".search", params);
2010-09-23 17:30:34 +02:00
} catch (XmlRpcException e) {
throw new HsarwebException("error in remote server call", e);
}
return res;
}
2010-10-05 21:43:30 +02:00
private XmlRpcClient getClient() throws HsarwebException {
if (client == null) {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
try {
String xmlrpcURL = context.getContextParam("xmlrpcURL");
config.setServerURL(new URL(xmlrpcURL));
} catch (MalformedURLException e) {
throw new HsarwebException("error in remote server url", e);
}
client = new XmlRpcClient();
client.setConfig(config);
}
return client;
}
2010-09-23 17:30:34 +02:00
public void setContext(Context context) {
this.context = context;
}
}