| Method from org.jboss.jetty.Jetty Detail: |
public WebApplication deploy(WebApplication wa,
String warUrl,
WebDescriptorParser descriptorParser) throws DeploymentException {
// use Hashtable because is is synchronised
String contextPath = wa.getMetaData().getContextRoot();
try
{
wa.setURL(new URL(warUrl));
// check whether the context already exists... - a bit hacky,
// could be nicer...
if (getContext(null, contextPath, 0)!=null)
_log.warn("A WebApplication is already deployed in context '"+contextPath+"' - proceed at your own risk.");
// deploy the WebApp
J2EEWebApplicationContext app=
new JBossWebApplicationContext(this,
descriptorParser,
wa,
warUrl);
app.setContextPath(contextPath);
Manager manager=getDistributableSessionManagerPrototype();
if (manager!=null)
{
app.setDistributableSessionManager((Manager)manager.clone());
if (getForceDistributable()) app.setDistributable(true);
}
// configure whether the context is to flatten the classes in
// the WAR or not
app.setExtractWAR (getUnpackWars());
// if a different webdefault.xml file has been provided, use it
if (getWebDefaultResource() != null)
app.setDefaultsDescriptor (getWebDefaultResource());
String virtualHost=wa.getMetaData().getVirtualHost();
addContext(virtualHost, app);
// keep track of deployed contexts for undeployment
_deployed.put(warUrl, app);
try
{
// finally start the app
app.start();
_log.info("successfully deployed "+warUrl+" to "+contextPath);
}
catch (MultiException me)
{
_log.warn("problem deploying "+warUrl+" to "+contextPath);
for (int i=0; i< me.size(); i++)
{
Exception e=me.getException(i);
_log.warn(e, e);
}
}
}
catch (DeploymentException e)
{
undeploy(warUrl);
throw e;
}
catch (Exception e)
{
undeploy(warUrl);
throw new DeploymentException(e);
}
return wa;
}
|
public URL findResourceInJar(String name) {
URL url=null;
try
{
url=getClass().getClassLoader().getResource(name);
}
catch (Exception e)
{
_log.error("Could not find resource: "+name, e);
}
return url;
}
|
static String fixURL(String url) {
// Get the separator of the JAR URL and the file reference
int index = url.indexOf( '!" );
if( index >= 0 ) {
index = url.lastIndexOf( '/", index );
} else {
index = url.lastIndexOf( '/" );
}
// Now add a "./" before the JAR file to add a different path
if( index >= 0 ) {
return
url.substring( 0, index ) +
"/." +
url.substring( index );
} else {
// Now forward slash found then there is severe problem with
// the URL but here we just ignore it
return url;
}
}
|
public String[] getCompileClasspath(ClassLoader cl) {
return _service.getCompileClasspath(cl);
}
|
public Element getConfigurationElement() {
return _configElement;
}
|
public Manager getDistributableSessionManagerPrototype() {
return _distributableSessionManagerPrototype;
}
|
public boolean getForceDistributable() {
return _forceDistributable;
}
|
public synchronized boolean getJava2ClassLoadingCompliance() {
return _loaderCompliance;
}
|
public boolean getStopWebApplicationsGracefully() {
return _stopWebApplicationsGracefully;
}
|
public synchronized String getSubjectAttributeName() {
return _subjectAttributeName;
}
|
public boolean getSupportJSR77() {
return _supportJSR77;
}
|
public synchronized boolean getUnpackWars() {
return _unpackWars;
}
|
public synchronized String getWebDefaultResource() {
return _webDefaultResource;
}
|
public boolean isDeployed(String warUrl) {
return (_deployed.get(warUrl)!=null);
}
|
public HttpContext service(HttpRequest request,
HttpResponse response) throws IOException, HttpException {
try
{
return super.service(request,response);
}
finally
{
// Moved to JBossUserRealm.deAuthenticate(UserPrincipal);
// SecurityAssociation.setPrincipal(null);
// SecurityAssociation.setCredential(null);
}
}
Override service method to allow ditching of security info
after a request has been processed |
public void setConfigurationElement(Element configElement) {
// convert to an xml string to pass into Jetty's normal
// configuration mechanism
_configElement = configElement;
try
{
DOMSource source = new DOMSource(configElement);
CharArrayWriter writer = new CharArrayWriter();
StreamResult result = new StreamResult (writer);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform (source, result);
_xmlConfigString = writer.toString();
// get rid of the first line, as this will be prepended by
// the XmlConfiguration
int index = _xmlConfigString.indexOf("? >");
if ( index >= 0)
{
index += 2;
while ((_xmlConfigString.charAt(index) == '\n")
||
(_xmlConfigString.charAt(index) == '\r"))
index++;
}
_xmlConfigString = _xmlConfigString.substring(index);
if (_log.isDebugEnabled()) _log.debug ("Passing xml config to jetty:\n"+_xmlConfigString);
setXMLConfiguration (_xmlConfigString);
}
catch (TransformerConfigurationException tce)
{
_log.error ("Can't transform config Element - > xml:", tce);
}
catch (TransformerException te)
{
_log.error ("Can't transform config Element - > xml:", te);
}
catch (Exception e)
{
_log.error("Unexpected exception converting configuration Element - > xml", e);
}
}
|
public void setDistributableSessionManagerPrototype(Manager manager) {
_distributableSessionManagerPrototype=manager;
}
|
public void setForceDistributable(boolean distributable) {
_forceDistributable=distributable;
}
|
public synchronized void setJava2ClassLoadingCompliance(boolean loaderCompliance) {
_loaderCompliance = loaderCompliance;
}
|
public void setStopWebApplicationsGracefully(boolean graceful) {
_stopWebApplicationsGracefully=graceful;
}
|
public synchronized void setSubjectAttributeName(String subjectAttributeName) {
_subjectAttributeName=subjectAttributeName;
}
|
public void setSupportJSR77(boolean graceful) {
_supportJSR77=graceful;
}
|
public synchronized void setUnpackWars(boolean unpackWars) {
_unpackWars=unpackWars;
}
|
public synchronized void setWebDefaultResource(String webDefaultResource) {
if (webDefaultResource != null)
{
URL webDefaultURL = findResourceInJar(webDefaultResource);
if (webDefaultURL != null)
_webDefaultResource=fixURL(webDefaultURL.toString());
else
{
_webDefaultResource = null;
_log.warn ("Cannot find resource for "+webDefaultResource+": using default");
}
}
else
_webDefaultResource = null;
if (_log.isDebugEnabled()) _log.debug ("webdefault specification is: "+_webDefaultResource);
}
If a webdefault.xml file has been specified in
jboss-service.xml then we try and use that.
If we cannot find it, then we will use the one
shipped as standard with Jetty and issue a warning.
If the jboss-service.xml file does not specify a
custom one, then we again default to the standard one. |
public void undeploy(String warUrl) throws DeploymentException {
// find the WebApp Context in the repository
JBossWebApplicationContext app = (JBossWebApplicationContext)_deployed.get(warUrl);
if (app==null)
{
_log.warn("app ("+warUrl+") not currently deployed");
}
else
{
try
{
app.stop(app.getStopGracefully());
removeContext(app);
app=null;
_log.info("Successfully undeployed "+warUrl);
}
catch (Exception e)
{
throw new DeploymentException(e);
}
}
_deployed.remove(warUrl);
}
|