Removing RMI based servlet clients.
This commit is contained in:
parent
ac9e98e7cd
commit
381e235e19
2 changed files with 0 additions and 191 deletions
|
@ -1,108 +0,0 @@
|
||||||
/*
|
|
||||||
* Helma License Notice
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Helma License
|
|
||||||
* Version 2.0 (the "License"). You may not use this file except in
|
|
||||||
* compliance with the License. A copy of the License is available at
|
|
||||||
* http://adele.helma.org/download/helma/license.txt
|
|
||||||
*
|
|
||||||
* Copyright 1998-2003 Helma Software. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* $RCSfile$
|
|
||||||
* $Author$
|
|
||||||
* $Revision$
|
|
||||||
* $Date$
|
|
||||||
*/
|
|
||||||
|
|
||||||
package helma.servlet;
|
|
||||||
|
|
||||||
import helma.framework.*;
|
|
||||||
import java.rmi.Naming;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
import javax.servlet.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the HOP servlet adapter. This class communicates with any
|
|
||||||
* Hop application on a given Hop server, extracting the application name
|
|
||||||
* from the request path.
|
|
||||||
*/
|
|
||||||
public class MultiServletClient extends AbstractServletClient {
|
|
||||||
private Hashtable apps;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param init ...
|
|
||||||
*
|
|
||||||
* @throws ServletException ...
|
|
||||||
*/
|
|
||||||
public void init(ServletConfig init) throws ServletException {
|
|
||||||
super.init(init);
|
|
||||||
apps = new Hashtable();
|
|
||||||
host = init.getInitParameter("host");
|
|
||||||
|
|
||||||
if (host == null) {
|
|
||||||
host = "localhost";
|
|
||||||
}
|
|
||||||
|
|
||||||
String portstr = init.getInitParameter("port");
|
|
||||||
|
|
||||||
port = (portstr == null) ? 5055 : Integer.parseInt(portstr);
|
|
||||||
hopUrl = "//" + host + ":" + port + "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void destroy() {
|
|
||||||
if (apps != null) {
|
|
||||||
apps.clear();
|
|
||||||
apps = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ResponseTrans execute(RequestTrans req) throws Exception {
|
|
||||||
// the app-id is the first element in the request path
|
|
||||||
// so we have to first get than and than rewrite req.path.
|
|
||||||
int slash = req.path.indexOf("/");
|
|
||||||
String appId = null;
|
|
||||||
|
|
||||||
if (slash == -1) {
|
|
||||||
// no slash found, path equals app-id
|
|
||||||
appId = req.path;
|
|
||||||
req.path = "";
|
|
||||||
} else {
|
|
||||||
// cut path into app id and rewritten path
|
|
||||||
appId = req.path.substring(0, slash);
|
|
||||||
req.path = req.path.substring(slash + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
IRemoteApp app = getApp(appId);
|
|
||||||
|
|
||||||
try {
|
|
||||||
return app.execute(req);
|
|
||||||
} catch (Exception x) {
|
|
||||||
invalidateApp(appId);
|
|
||||||
app = getApp(appId);
|
|
||||||
|
|
||||||
return app.execute(req);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IRemoteApp getApp(String appId) throws Exception {
|
|
||||||
IRemoteApp app = (IRemoteApp) apps.get(appId);
|
|
||||||
|
|
||||||
if (app != null) {
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
app = (IRemoteApp) Naming.lookup(hopUrl + appId);
|
|
||||||
apps.put(appId, app);
|
|
||||||
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
void invalidateApp(String appId) {
|
|
||||||
apps.remove(appId);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
/*
|
|
||||||
* Helma License Notice
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Helma License
|
|
||||||
* Version 2.0 (the "License"). You may not use this file except in
|
|
||||||
* compliance with the License. A copy of the License is available at
|
|
||||||
* http://adele.helma.org/download/helma/license.txt
|
|
||||||
*
|
|
||||||
* Copyright 1998-2003 Helma Software. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* $RCSfile$
|
|
||||||
* $Author$
|
|
||||||
* $Revision$
|
|
||||||
* $Date$
|
|
||||||
*/
|
|
||||||
|
|
||||||
package helma.servlet;
|
|
||||||
|
|
||||||
import helma.framework.*;
|
|
||||||
import java.rmi.Naming;
|
|
||||||
import javax.servlet.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the standard Helma servlet adapter. This class represents a servlet
|
|
||||||
* that is dedicated to one Helma application over RMI.
|
|
||||||
*/
|
|
||||||
public class ServletClient extends AbstractServletClient {
|
|
||||||
private IRemoteApp app = null;
|
|
||||||
private String appName = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param init ...
|
|
||||||
*
|
|
||||||
* @throws ServletException ...
|
|
||||||
*/
|
|
||||||
public void init(ServletConfig init) throws ServletException {
|
|
||||||
super.init(init);
|
|
||||||
appName = init.getInitParameter("application");
|
|
||||||
host = init.getInitParameter("host");
|
|
||||||
|
|
||||||
if (host == null) {
|
|
||||||
host = "localhost";
|
|
||||||
}
|
|
||||||
|
|
||||||
String portstr = init.getInitParameter("port");
|
|
||||||
|
|
||||||
port = (portstr == null) ? 5055 : Integer.parseInt(portstr);
|
|
||||||
hopUrl = "//" + host + ":" + port + "/";
|
|
||||||
|
|
||||||
if (appName == null) {
|
|
||||||
throw new ServletException("Application name not specified for helma.servlet.ServletClient");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void destroy() {
|
|
||||||
if (app != null) {
|
|
||||||
app = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ResponseTrans execute(RequestTrans req) throws Exception {
|
|
||||||
if (app == null) {
|
|
||||||
initApp();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return app.execute(req);
|
|
||||||
} catch (Exception x) {
|
|
||||||
initApp();
|
|
||||||
|
|
||||||
return app.execute(req);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized void initApp() throws Exception {
|
|
||||||
app = (IRemoteApp) Naming.lookup(hopUrl + appName);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue