Methods Summary |
---|
private boolean | checkAccess()Check whether the calling user is authenticated.
boolean allowed = true;
if (userName != null) {
// Authentication is configured.
Principal principal = endpointContext.getUserPrincipal();
allowed = principal != null && userName.equals(principal.getName());
}
return allowed;
|
public void | destroy()Called when the service instance is no longer required.
// Nothing to do
|
public void | getBookAuthor(java.lang.String title, javax.xml.rpc.holders.StringHolder author)Gets the author for a books with a given title
String authorName = ContextBookServiceServantData.getBookAuthor(title);
if (authorName == null || !checkAccess()) {
throw new ContextBookServiceException("Unknown author: " + title);
}
author.value = authorName;
|
public int | getBookCount()Gets the number of books known to the service
String[] titles = ContextBookServiceServantData.getBookTitles();
return titles == null || !checkAccess() ? 0 : titles.length;
|
public java.lang.String | getBookTitle(int index)Gets the title of a given book.
String[] bookTitles = ContextBookServiceServantData.getBookTitles();
if (bookTitles == null || index < 0 || index >= bookTitles.length || !checkAccess()) {
return null;
}
return isUpperCase() ? bookTitles[index].toUpperCase() : bookTitles[index];
|
public void | init(java.lang.Object context)
/* -- Implementation of the ServiceLifeCycle interface -- */
endpointContext = (ServletEndpointContext)context;
// Get the authorized user name from the init parameters
ServletContext servletContext = endpointContext.getServletContext();
userName = servletContext.getInitParameter("UserName");
// Get alphabetic sorting flag from JNDI
try {
InitialContext namingCtx = new InitialContext();
Object value = namingCtx.lookup("java:comp/env/sorted");
sorted = value instanceof Boolean ? ((Boolean)value).booleanValue() : false;
ContextBookServiceServantData.setSorted(sorted);
} catch (NamingException ex) {
servletContext.log("Exception while accessing naming context", ex);
}
|
public boolean | isUpperCase()Returns whether book titles are being forced to
upper case.
HttpSession session = endpointContext.getHttpSession();
if (session != null) {
Boolean upperCase = (Boolean)session.getAttribute(UPPER_CASE);
return upperCase == null ? false : upperCase.booleanValue();
}
// No session - upper case mode not allowed
return false;
|
public void | log(java.lang.String value)Makes a log entry.
if (checkAccess()) {
endpointContext.getServletContext().log(new Date() + ": " + value);
}
|
public void | setUpperCase(boolean cond)Sets whether book titles returned by the
getBookTitle() method should be in upper case.
HttpSession session = endpointContext.getHttpSession();
if (session != null) {
session.setAttribute(UPPER_CASE, cond ? Boolean.TRUE : Boolean.FALSE);
}
|