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.text.DateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped; import javax.faces.bean.SessionScoped;
@ManagedBean @ManagedBean(name="hello")
@SessionScoped @SessionScoped
public class Bean { public class Bean {
public final static DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); public final static DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
@ManagedProperty(value="#{context}")
private Context context;
@ManagedProperty(value="#{remote}")
private Remote remote;
public String getMessage() { 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() { public String getTime() {
return df.format(new Date()); 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.util.AbstractCasFilter;
import org.jasig.cas.client.validation.Assertion; import org.jasig.cas.client.validation.Assertion;
@ManagedBean @ManagedBean(name="context")
@SessionScoped @SessionScoped
public class Context { public class Context {
private ExternalContext getContext() { private ExternalContext getExternalContext() {
return FacesContext.getCurrentInstance().getExternalContext(); return FacesContext.getCurrentInstance().getExternalContext();
} }
public String getUser() { private AttributePrincipal getPrincipal() {
Assertion assertion = (Assertion) getContext().getSessionMap().get(AbstractCasFilter.CONST_CAS_ASSERTION); ExternalContext context = getExternalContext();
AttributePrincipal principal = assertion.getPrincipal(); Assertion assertion = (Assertion) context.getSessionMap().get(AbstractCasFilter.CONST_CAS_ASSERTION);
String proxyTicket = principal.getProxyTicketFor("https://agnes.ostwall195.de/backend"); return assertion.getPrincipal();
return principal.getName();
} }
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.ArrayList;
import java.util.List; import java.util.List;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
@ManagedBean @ManagedBean(name="modules")
@ApplicationScoped @SessionScoped
public class Modules { public class Modules {
@ManagedProperty(value="#{context}")
private Context context;
public String[] pageNames = new String[] { "hello" }; public String[] pageNames = new String[] { "hello" };
public List<String> getPageNames() { public List<String> getPageNames() {
ArrayList<String> names = new ArrayList<String>(); ArrayList<String> names = new ArrayList<String>();
String path = context.getContextPath() + "/";
names.add(path + context.getUser());
for (String name : pageNames) { for (String name : pageNames) {
names.add(name); names.add(path + name);
} }
return names; 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:param name="title" value="Hallo schöne Welt"/>
<ui:define name="content"> <ui:define name="content">
<f:view> <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> </f:view>
</ui:define> </ui:define>
</ui:composition> </ui:composition>

View File

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

View File

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