I am using WebLogic 8.1 and I have an enterprise application which
contains a web application. The enterprise application is
packaged in an EAR, which contains a WAR with that web application.
Now, the problem I am facing is that I want to stop the web server from
loading the entire enterprise application (and eventually unload the
context of the application) if at least one exception is thrown when
the
WAR is loaded.
Therefore, the webserver loads the EAR, then it starts loading the WAR.
If this operation generates some startup exception, I would like
to unload the entire enterprise application (or at least make the
server refuse to service any requests made for that enterprise app).
Do you know if that is even possible?
Thanks in advance,
Bogdan.
Dear sir,
Being unix fanatical... I suggest to have a script doing a grep into
the WLS console output nohup, looking for a specific exception and if
found, using the weblogic.Deployer interface to undeploy the entire
application. Kind'a like:
java -cp "%classpath%" weblogic.Deployer -adminurl
http://localhost:7001 -username weblogic -password weblogic -name
application-ear -targets application@server1 -undeploy & pause
you can do it from java code also:
<snip>
else if(topsecurityAction!=null &&
topsecurityAction.equals("undeploy")) {
try {
// Get access to MBeanHome
MBeanHome home = Helper.getAdminMBeanHome(userid,
password, url);
// Get the deployer
DeployerRuntimeMBean deployer =
DeployerRuntime.getDeployerRuntime(home);
// Build the DeploymentData object
DeploymentData info = new DeploymentData();
info.addTarget(server, mods);
deployer.undeploy(name, info, null);
} catch (Exception e) {
deployReply = "unsuccessfull "+topsecurityAction+":
"+e.getMessage();
}
}
<snip>
all according to:
http://e-docs.bea.com/wls/docs81/deployment/tools.html
I doubt you can do it otherwise from within deployment descriptors
alone.
Anyway, I was about to write an articles with full example on
topsecurity.dk about writing your own console manager... But you
know... time...
Always my pleasure to help - if I can - that's what's it's all bout,
right?!
who don't have a contract right now, grrr :-)
you could also just call the servlet url from another process
monitoring the deployment.
Anyway the story is... if you want to do magic with deployment... there
is no way around MBeans...
Example:
package dk.topsecurity;
import java.util.*;
import java.io.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.management.MBeanServer;
import javax.management.Notification;
import javax.management.NotificationFilter;
import weblogic.management.DeploymentNotification;
import weblogic.management.Helper;
import weblogic.management.MBeanHome;
import weblogic.management.RemoteNotificationListener;
import weblogic.management.configuration.ApplicationMBean;
import weblogic.management.deploy.DeploymentData;
import weblogic.management.deploy.DeployerRuntime;
import weblogic.management.runtime.DeployerRuntimeMBean;
import weblogic.management.runtime.DeploymentTaskRuntimeMBean;
/**
*http://e-docs.bea.com/wls/docs81/security/thin_client.html#1046335
*http://www.onjava.com/pub/a/onjava/2001/08/06/webform.html
*/
public class TopsecurityDeployServlet extends HttpServlet
{
String heading = null;
ServletConfig servletConfig = null;
String userid;
String password;
String url;
String name;
String source;
String server;
String[] mods;
public TopsecurityDeployServlet()
{
}
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
servletConfig = config;
heading =
config.getInitParameter("topsecurity_servlet_version");
userid=config.getInitParameter("topsecurity_username");
password=config.getInitParameter("topsecurity_password");
url=config.getInitParameter("topsecurity_adminurl");
name=config.getInitParameter("topsecurity_earname");
source=config.getInitParameter("topsecurity_sourcedir");
server=config.getInitParameter("topsecurity_servername");
mods = new String[1];
mods[0]=config.getInitParameter("topsecurity_modulename");
System.out.println(heading+" init method ok.");
}
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
handleRequest(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse
response)
throws ServletException, IOException
{
handleRequest(request, response);
}
private void handleRequest(HttpServletRequest request,
HttpServletResponse
response)
throws ServletException, IOException
{
String deployReply = null;
try
{
String topsecurityAction =
request.getParameter("topsecurityAction");
if(topsecurityAction!=null &&
topsecurityAction.equals("redeploy")) {
try {
// Get access to MBeanHome
MBeanHome home = Helper.getAdminMBeanHome(userid,
password, url);
// Get the deployer
DeployerRuntimeMBean deployer =
DeployerRuntime.getDeployerRuntime(home);
// Build the DeploymentData object
DeploymentData info = new DeploymentData();
info.addTarget(server, mods);
deployer.redeploy(name, info, null, true);
} catch (Exception e) {
deployReply = "unsuccessfull "+topsecurityAction+":
"+e.getMessage();
}
}
else if(topsecurityAction!=null &&
topsecurityAction.equals("undeploy")) {
try {
// Get access to MBeanHome
MBeanHome home = Helper.getAdminMBeanHome(userid,
password, url);
// Get the deployer
DeployerRuntimeMBean deployer =
DeployerRuntime.getDeployerRuntime(home);
// Build the DeploymentData object
DeploymentData info = new DeploymentData();
info.addTarget(server, mods);
deployer.undeploy(name, info, null);
} catch (Exception e) {
deployReply = "unsuccessfull "+topsecurityAction+":
"+e.getMessage();
}
}
else if(topsecurityAction!=null &&
topsecurityAction.equals("deploy")) {
try {
// Get access to MBeanHome
MBeanHome home = Helper.getAdminMBeanHome(userid,
password, url);
// Get the deployer
DeployerRuntimeMBean deployer =
DeployerRuntime.getDeployerRuntime(home);
// Build the DeploymentData object
DeploymentData info = new DeploymentData();
info.addTarget(server, mods);
deployer.deploy(source, name, null, info, null, true);
} catch (Exception e) {
deployReply = "unsuccessfull "+topsecurityAction+":
"+e.getMessage();
}
} else {
deployReply="Unknown command: "+(topsecurityAction==null ?
"<none>":topsecurityAction);
}
if(deployReply==null)
deployReply="successfull "+topsecurityAction;
Calendar calendar = new GregorianCalendar();
Date date = calendar.getTime();
DateFormat format = new SimpleDateFormat( "yyyy.MM.dd
hh:mm:ss" );
String timeStr = format.format( date );
deployReply =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"+
"<HTML>"+
"<HEAD><TITLE>Sample FORM for issuing POST command</TITLE></HEAD>"+
"<BODY BGCOLOR=\"#FDF5E6\">"+
"<H1 ALIGN=\"CENTER\">Sample FORM for issuing POST command</H1>"+
"<FORM ACTION=\"/topdeploy\""+
" METHOD=\"POST\">"+
" Module Name:"+
" <INPUT TYPE=\"TEXT\" NAME=\"applicationName\"
VALUE=\""+name+"\"><BR>"+
" Weblogic server username:"+
" <INPUT TYPE=\"TEXT\" NAME=\"weblogicUser\"
VALUE=\""+userid+"\"><BR>"+
" Weblogic server password:"+
" <INPUT TYPE=\"PASSWORD\" NAME=\"weblogicPassword\"
VALUE=\""+password+"\"><BR>"+
" Action:<BR>"+
" <INPUT TYPE=\"RADIO\" NAME=\"topsecurityAction\""+
" VALUE=\"undeploy\">undeploy<BR>"+
" <INPUT TYPE=\"RADIO\" NAME=\"topsecurityAction\""+
" VALUE=\"deploy\">deploy<BR>"+
" <INPUT TYPE=\"RADIO\" NAME=\"topsecurityAction\""+
" VALUE=\"redeploy\">redeploy<BR>"+
" Last action result:<BR>"+
" <TEXTAREA NAME=\"actionResult\" ROWS=8
COLS=40>"+timeStr+"\r"+deployReply+"</TEXTAREA><BR>"+
" <CENTER>"+
" <INPUT TYPE=\"SUBMIT\" VALUE=\"Submit Action\">"+
" </CENTER>"+
"</FORM>"+
"</BODY>"+
"</HTML>";
PrintStream out = new
PrintStream(response.getOutputStream());
out.print(deployReply);
out.flush();
}
catch(Exception ex)
{
System.err.println("Topsecurity TimeServlet got Exception: "
+
ex.toString());
ex.printStackTrace();
}
}
}