XML-RPC Client

This commit is contained in:
Peter Hormanns 2010-09-23 15:30:34 +00:00
parent e21fdda8b2
commit 977d020f77
11 changed files with 141 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,22 +2,52 @@ package de.hsadmin.web;
import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
@ManagedBean
@ManagedBean(name="hello")
@SessionScoped
public class Bean {
public final static DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
@ManagedProperty(value="#{context}")
private Context context;
@ManagedProperty(value="#{remote}")
private Remote remote;
public String getMessage() {
return "Hallo Welt";
Map<String, String> where = new HashMap<String, String>();
where.put("name", context.getUser());
String name = "Welt";
try {
Object test = remote.callSearch("user", context.getUser(), where);
if (test instanceof Object[] && ((Object[])test).length > 0 ) {
if (((Object[])test)[0] instanceof Map) {
name = (String) ((Map<?, ?>)((Object[])test)[0]).get("comment");
}
}
} catch (HsarwebException e) {
e.printStackTrace();
}
return "Hallo " + name;
}
public String getTime() {
return df.format(new Date());
}
public void setContext(Context context) {
this.context = context;
}
public void setRemote(Remote remote) {
this.remote = remote;
}
}

View File

@ -9,19 +9,29 @@ import org.jasig.cas.client.authentication.AttributePrincipal;
import org.jasig.cas.client.util.AbstractCasFilter;
import org.jasig.cas.client.validation.Assertion;
@ManagedBean
@ManagedBean(name="context")
@SessionScoped
public class Context {
private ExternalContext getContext() {
private ExternalContext getExternalContext() {
return FacesContext.getCurrentInstance().getExternalContext();
}
public String getUser() {
Assertion assertion = (Assertion) getContext().getSessionMap().get(AbstractCasFilter.CONST_CAS_ASSERTION);
AttributePrincipal principal = assertion.getPrincipal();
String proxyTicket = principal.getProxyTicketFor("https://agnes.ostwall195.de/backend");
return principal.getName();
private AttributePrincipal getPrincipal() {
ExternalContext context = getExternalContext();
Assertion assertion = (Assertion) context.getSessionMap().get(AbstractCasFilter.CONST_CAS_ASSERTION);
return assertion.getPrincipal();
}
public String getUser() {
return getPrincipal().getName();
}
public String getProxyTicket() {
return getPrincipal().getProxyTicketFor("https://agnes.ostwall195.de:9443/hsar/backend");
}
public String getContextPath() {
return getExternalContext().getRequestContextPath();
}
}

View File

@ -0,0 +1,20 @@
package de.hsadmin.web;
public class HsarwebException extends Exception {
private static final long serialVersionUID = 1L;
public HsarwebException(String msg, Exception e) {
super(msg, e);
}
public HsarwebException(Exception e) {
super(e);
}
public HsarwebException(String msg) {
super(msg);
}
}

View File

@ -3,20 +3,31 @@ package de.hsadmin.web;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
@ManagedBean
@ApplicationScoped
@ManagedBean(name="modules")
@SessionScoped
public class Modules {
@ManagedProperty(value="#{context}")
private Context context;
public String[] pageNames = new String[] { "hello" };
public List<String> getPageNames() {
ArrayList<String> names = new ArrayList<String>();
String path = context.getContextPath() + "/";
names.add(path + context.getUser());
for (String name : pageNames) {
names.add(name);
names.add(path + name);
}
return names;
}
public void setContext(Context context) {
this.context = context;
}
}

View File

@ -0,0 +1,52 @@
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 {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
try {
config.setServerURL(new URL("https://agnes.ostwall195.de:9443/hsar/xmlrpc/hsadmin"));
} catch (MalformedURLException e) {
throw new HsarwebException("error in remote server url", e);
}
client = new XmlRpcClient();
client.setConfig(config);
}
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 {
res = client.execute(module + ".search", params);
} catch (XmlRpcException e) {
throw new HsarwebException("error in remote server call", e);
}
return res;
}
public void setContext(Context context) {
this.context = context;
}
}

View File

@ -13,7 +13,7 @@
<ui:param name="title" value="Hallo schöne Welt"/>
<ui:define name="content">
<f:view>
Hallo&#160; <h:outputText value="#{context.user}"/>, es ist jetzt&#160; <h:outputText value="#{bean.time}"/> Uhr.
<h:outputText value="#{hello.message}"/>, es ist jetzt&#160; <h:outputText value="#{hello.time}"/> Uhr.
</f:view>
</ui:define>
</ui:composition>

View File

@ -54,6 +54,9 @@ body {
padding-left:0px;
padding-right:0px;
}
.dummy {
clear:both;
}
.content {
width:606px;
margin-left:304px;

View File

@ -24,6 +24,7 @@
<div class="content">
<ui:insert name="content">Default Content</ui:insert>
</div>
<div class="dummy"></div>
</div>
<div class="footer">
<ui:insert name="footer">Default Footer</ui:insert>