Tag: Plan.xml

Changing the context-param values of web.xml using plan.xml

Ravish Mody

Here we are going to see how we can change the “<context-param>”  child tag values using plan.xml file. Many times we see that the values are not getting changed or reflected by plan.xml file updates even if every step looks correct.

NOTE: The plan.xml feature works on Xpath and which is applicable on the XSD based xml files. So it would not work for DTD based web.xml file.  So make sure that you use the weblogic.DDConverter utility to convert the web.xml to use the latest XSD based deployment descriptors. To get more information on it do have a look at this post How to use the weblogic.DDConverter tool ?

Steps To change the context-param values of web.xml using plan.xml

Step1).  Create a web application  in some location like: (C:/DemoPlan/SampleWebApp)

Step2).  Now create a “web.xml” file like following inside “C:/DemoPlan/SampleWebApp/WEB-INF” directory:

<!---------------- DO NOT use the DTDs inside your XML file if you want to use plan.xml------------------
<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <context-param id="one">
        <param-name>TokenGroup</param-name>
        <param-value>oldvalue</param-value>
    </context-param>
</web-app>
-----------------------Please ignore the above web.xml content -------------------------------------------->

<?xml version='1.0' encoding='WINDOWS-1252'?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <context-param id="one">
    <param-name>TokenGroup</param-name>
    <param-value>oldvalue</param-value>
  </context-param>
</web-app>

Step3).  Now we need to create a “index.jsp” inside “C:/DemoPlan/SampleWebApp” like following to read the context-param values defined inside the “web.xml” file.

<html>
<head><title>Hi</title><head>
<body bgcolor=maroon text=white>

<%
     String param = application.getInitParameter("TokenGroup");
     out.println("<h3>TokenGroup : "+param);
     System.out.println("ntTokenGroup : "+param);
%>

</body>
</html>

Step4).  Now write the following kind of “plan.xml” file inside any directory like “C:/DemoPlan/”
NOTE: you need to make sure that the  <config-root>Should contain a valid directory path which contains the plan.xml file.</config-root>

<?xml version='1.0' encoding='UTF-8'?>
<deployment-plan xmlns="http://www.bea.com/ns/weblogic/deployment-plan" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/deployment-plan http://www.bea.com/ns/weblogic/deployment-plan/1.0/deployment-plan.xsd" global-variables="false">
  <application-name>SimpleWebApp</application-name>

  <variable-definition>
      <variable>
          <name>newVariable</name>
          <value>Key123456</value>
      </variable>
  </variable-definition>

  <module-override>
    <module-name>SimpleWebApp</module-name>
    <module-type>war</module-type>

    <module-descriptor external="false">
      <root-element>web-app</root-element>
      <uri>WEB-INF/web.xml</uri>
      <variable-assignment>
         <name>newVariable</name>
         <xpath>/web-app/context-param/[param-name="TokenGroup"]/param-value</xpath>
         <operation>add</operation>
      </variable-assignment>
    </module-descriptor>

  </module-override>
  <config-root>C:/DemoPlan/</config-root>
</deployment-plan>

Step5). Now just to simplify the deployment and un-deployment task we can write the build.xml file  to make the things automated.

<project name="webservices-hello_world" default="deploy">
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic" />
<property name="wls.hostname" value="10.10.10.10" />
<property name="wls.port" value="7001" />
<property name="admin.server.name" value="AdminServer" />
<property name="deploy.target" value="AdminServer" />

<property name="deploy.name" value="SimpleWebApp" />
<property name="deploy.source" value="SimpleWebApp" />
<property name="plan.xml.path" value="C:/DemoPlan//plan.xml" />

<!-- Setting TaskDefinition -->
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
<classpath>
<pathelement location="C:/bea103/wlserver_10.3/server/lib/weblogic.jar"/>
</classpath>
</taskdef>

<!-- Deploying Applications  -->
<target name="deploy">
<wldeploy action="deploy"
          name="${deploy.name}"
          source="${deploy.source}"
          user="${wls.username}"
          nostage="true"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

<target name="redeployWithPlan">
<wldeploy action="redeploy"
          name="${deploy.name}"
          plan="${plan.xml.path}"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

<!-- Redeploying Applications  -->
<target name="redeploy">
<wldeploy action="redeploy"
          name="${deploy.name}"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

<!-- Uneploying Applications  -->
<target name="undeploy">
<wldeploy action="undeploy"
          name="${deploy.name}"
          failonerror="false"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>
</project>

Step6). Now deploy your application after running the setWLSEnv.cmd in the command prompt like following:

ant deploy

Step7). Now access the application like http://hostName:port/SampleWebApp/index.jsp   you will notice that the  page displays the value of TokenGroup as “oldvalue” which is defined in the web.xml .

Step8). Now again redeploy your application using the plan.xml file  which is specified in the  “build.xml” file as following:

ant redeployWithPlan

Step9).  Now as soon as you will hit your application “http://hostName:port/SampleWebApp/index.jsp” you will see that the page displays the value of TokenGroup as “Key123456

Thanks
Ravish Mody

Comments Off on Changing the context-param values of web.xml using plan.xml more...

Changing Session-timeout using plan.xml

Hi,

Jay SenSharma

Jay SenSharma

As a WebLogic Administrator Many times we want to make some changes in the application provided by the Development team. But it is not good for a WebLogic Administrator to make changes in the application archieve provided by the Application Development team. But to fulfill some environmental requirements the Administartor has to make some changes in the application.

WebLogic provides a best way for the WebLogic Administrators to alter the different Tags present inside the Application deployment descriptors like adding a new Tag or replacing a value of a Tag mentioned in the “web.xml” or in “weblogic.xml” or in any of the deployment descriptor like “weblogic-ejb-jar.xml”,”application.xml”, “weblogic-application.xml”…etc.

In this example we are going to see how can we change the <session-timeout> of a Web Application without even altering the “web.xml” physically…On the fly

Step1). Deploy your Application as it is at present on the Server. Suppose your Web Application name is “SessionTimeoutWebApp” (I am assuming it as a Exploded WAR file you can work with Archived WAR file as well in the same way)

Step2). Anywhere in your file system Just paste the following “plan.xml” file: (Suppose Location is “F:SessionTimeout_PlanDemo” )

<?xml version='1.0' encoding='UTF-8'?>
<deployment-plan xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-deployment-plan.xsd" global-variables="false">

   <application-name>SessionTimeoutWebApp</application-name>     <!-- You need to change this Line and Put your Web Application Name -->
	<variable-definition>
		<variable>
			<name>NewSessionValue</name>
			<value>100000</value>
		</variable>
	</variable-definition>

   <module-override>
	<module-name>SessionTimeoutWebApp</module-name>      <!-- You need to change this Line and Put your Web Application Name -->
	<module-type>war</module-type>
	<module-descriptor external="true">
		<root-element>web-app</root-element>
		<uri>WEB-INF/web.xml</uri>
		<variable-assignment>
			<name>NewSessionValue</name>
			<xpath>/web-app/session-config/session-timeout</xpath>
		</variable-assignment>
	</module-descriptor>
    </module-override>
    <config-root>F:SessionTimeout_PlanDemo</config-root>  <!-- You need to change this Line and Put the location of plan.xml file wherever u have pasted it -->
</deployment-plan>

Step3). Login to AdminConsole and goto deployments page—-> the select your Application (After Pressing Lock & Edit Button) –> update (click this button)—> browse your “plan.xml” file location and then finish.
Once the changes will be activated ….Next time your will see that your <session-timeout> value is changed  from the AdminConsole or through any other technique like JMX or WLST.

.
.
Thanks
Jay SenSharma


How to Edit web.xml Using Plan.xml

Hi,

Jay SenSharma

Jay SenSharma

As a WebLogic Administrator Many times we want to make some changes in the application provided by the Development team. But it is not good for a WebLogic Administrator to make changes in the application archieve provided by the Application Development team. But to fulfill some environmental requirements the Administartor has to make some changes in the application.

WebLogic provides a best way for the WebLogic Administrators to alter the different Tags present inside the Application deployment descriptors like adding a new Tag or replacing a value of a Tag mentioned in the “web.xml” or in “weblogic.xml” or in any of the deployment descriptor like “weblogic-ejb-jar.xml”,”application.xml”, “weblogic-application.xml”…etc.

Here we are going to see a very simple demonstration on adding a WelCome Page to our Application.

Why We need Welcome Page?

Suppose Users  access my application’s welcome page like following : “http://someHost:7001/MTestApp/login.htm”

But i don’t want to display the “login.htm”  in the URL rather i want as soon as the user enters the following URL:   “http://someHost:7001/MTestApp” the “login.htm” Page content should automatically appear in the webPage.

For example if we have the following kind of “web.xml” file inside our application :

<?xml version="1.0? encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<!--   We don't have any welcome page defined here -->

</web-app>

And if we want to add the <welcome-file-list> Tag set in the above “web.xml” file without physically editing the WAR file or the “web.xml” file as below, then we can do it using “plan.xml” file

<?xml version="1.0? encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<welcome-file-list>
<welcome-file>login.htm</welcome-file>
</welcome-file-list>

</web-app>

Step1). We assume that already your application is deployed on the WebLogic Server.

Step2). Suppose your WAR name is “TestWelcomePage” (i am considering it as an exploded WAR…you can use it with Archieved WAR file as well).

Step3). Anywhere in your file system Just paste the following “plan.xml” file: (Suppose Location is “F:WelcomePage_PlanDemo” )

<?xml version='1.0' encoding='UTF-8'?>
<deployment-plan xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-deployment-plan.xsd" global-variables="false">

<application-name>TestWelcomePage</application-name> <!-- You need to change this Line and Put your Web Application Name -->

<variable-definition>
<variable>
<name>welcomeFileName</name>
<value>login.htm</value>
</variable>
</variable-definition>

<module-override>
     <module-name>TestWelcomePage</module-name> <!-- You need to change this Line and Put your Web Application Name -->
     <module-type>war</module-type>
     <module-descriptor external="true">
          <root-element>web-app</root-element>
          <uri>WEB-INF/web.xml</uri>
          <variable-assignment>
                    <name>welcomeFileName</name>
                    <xpath>/web-app/welcome-file-list/welcome-file</xpath>
          </variable-assignment>
     </module-descriptor>
</module-override>
<config-root>F:WelcomePage_PlanDemo</config-root> <!-- You need to change this Line and Put the location of plan.xml file wherever u have pasted it -->
</deployment-plan>

Step4). Login to AdminConsole and goto deployments page—-> the select your Application (After Pressing Lock & Edit Button) –> update (click this button)—> browse your “plan.xml” file location and then finish.

Once the changes will be activated ….Next time your will see that your Welcome page is changed.

Note: you won’t see any changes in the Actual WAR file (inside the application), this entry in plan.xml will be used by weblogic apart from the Actual application archieve. This is the biggest advantage of using plan.xml feature of weblogic.
.

.

Thanks

Jay SenSharma


Copyright © 2010-2012 Middleware Magic. All rights reserved. |