Monday, April 27, 2009

Using the WebLogic deployment plan to change your ear / war for production

With Weblogic you can use a deployment plan to change your environment settings so it works in your production environment. For example if you put your WSDL url of your web service proxy clients as a context parameter in the web.xml then you can change this by using a deployment plan. This plan is a xml file and can be easily changed. You can apply this plan even after deployment.
First let's take a look at the wsdl url parameter in the web.xml, The deployment plan will change this context parameter

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<description>Empty web.xml file for Web Application</description>
<context-param>
<param-name>wsdlUrl</param-name>
<param-value>http://localhost:7001/ws_helloworld/HelloWorldServicePort?WSDL</param-value>
</context-param>


To make this work, we need to generate a deployment plan. We will use your application ear or war file as input for this plan. This is the bat file I used for this.

set BEA_HOME=C:\oracle\MiddlewareJdev11g
call %BEA_HOME%\wlserver_10.3\server\bin\setWLSEnv.cmd
set PATH=%BEA_HOME%\jdk160_05\bin
set planname=HelloWorld.xml
set earfile=C:\projecten\workspace\11g_prod\ws_helloworld\webapp\deploy\helloworld.ear
java weblogic.PlanGenerator -all -plan %planname% %earfile%

This will generate a xml file. Change the deployment xml and add a new variable with the right url

<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>helloworld.ear</application-name>
<variable-definition>
<!-- add the wsdl var -->
<variable>
<name>wsdlUrl</name>
<value>http://localhost:7101/ws_helloworld/HelloWorldServicePort?WSDL</value>
</variable>

Now we can change the web.xml part where we use xpath to find the context parameter and replace the value with the just created variable

<module-descriptor external="false">
<root-element>web-app</root-element>
<uri>WEB-INF/web.xml</uri>

<!-- replace the wsdl url with the deployment url -->
<variable-assignment>
<name>wsdlUrl</name>
<xpath>/web-app/context-param/[param-name="wsdlUrl"]/param-value</xpath>
<operation>replace</operation>
</variable-assignment>
</module-descriptor>
</module-override>
<config-root>C:\DOCUME~1\ebiemond\LOCALS~1\Temp\ebiemond\.\config\deployments\ear.ear\plan</config-root>
</deployment-plan>

The plan is finished and we can use this plan with the deployment. You can apply this plan on an ear in the WLS console or you can use this bat file.

set BEA_HOME=C:\oracle\MiddlewareJdev11g
call %BEA_HOME%\wlserver_10.3\server\bin\setWLSEnv.cmd
set PATH=%BEA_HOME%\jdk160_05\bin
set planname=HelloWorld.xml
set earfile=C:\projecten\workspace\11g_prod\ws_helloworld\webapp\deploy\helloworld.ear
java weblogic.Deployer -adminurl http://localhost:7101 -user weblogic -password weblogic -deploy -name HelloWorld -source %earfile% -targets DefaultServer -stage -plan %planname%

32 comments:

  1. This sounds awesome!

    I don't get this to work with BEA Weblogic 9.2 tho. The new values that I assign to the context-param just seem to be ignored when I deploy my ear with the modified deployment plan.

    Does this work with 9.2 or is a later version required?

    ReplyDelete
  2. Hi
    did you generate the plan from your wls 9.2 home or from jdeveloper.

    and can you apply this plan in the wls console.

    and test this in wls 10.3.2, maybe you made a mistake.

    thanks

    ReplyDelete
  3. Hi,

    We deploy to the server using JDeveloper in development. Is there any way to have JDeveloper use a plan when it deploys?

    This is a WebService project.

    Thanks and EXCELLENT blog!

    ReplyDelete
  4. Hi,

    when you use ant or wlst to deploy your ears then you can provide the plan.

    thanks Edwin

    ReplyDelete
  5. We are using the built in functionality to deploy to the application server from JDeveloper in dev. On test then we are using the scripting tool.

    Is there ant way to specify a plan using the built in menus in JDeveloper when you say "Deploy to Application Server" and it drives you through the wizard?

    Thanks!!

    ReplyDelete
  6. Hi,

    first i think dev should always work and you don't need a plan. probably you got your reasons.

    you can make your plugin, soa deployment has a plan support. This can be hard.

    or make a cmd script and add this to your jdev menu.

    thanks Edwin

    ReplyDelete
  7. Hi, I'm using ADF 11g and my requirement is while deploying the app ear , i need to change the data source references. Since an ADF app stores the data sources at two files like web.xml and bc4j.xcfg , can i use a plan. xml to override these files.

    Note: The same ear file needs to be deployed against seven data sources.

    ganesh

    ReplyDelete
  8. Hi,

    you have to change the Application module configuration so it uses a datasource. and in the application deployment disable jdbc connection deployment.

    now you only need to make the right datasource on every wls and then deploy the ears.

    that should work

    ReplyDelete
  9. Thanks for your response Edwin. I did all you mentioned. I shall explain in details. My requirement is i have to deploy the same EAR file against seven data sources.

    I made the Application module configuration to use the custom data source . So the bc4j.xcfg file will have an element "<Custom JDBCDataSource="java:comp/env/jdbc/XXXDS>".

    In the deployment the option "Auto generate and Synchronize weblogic-jdbc.xml descriptors during deployment". is disabled.

    During deployment in a weblogic instance , i have to create a data source with the same name as in the bc4j.xcfg and in webl.xml.

    For the first time deployment i can do this matching the data source name as XXXDS.

    Say if i want to deploy the same EAR with data source name as XXXDS in the bc4j.xcfg and in web.xml, i have to create a data source in the server with the same name as XXXDS which is not possible.

    So to deploy the same ear in the same server , i need to change the Data source name in the bc4j.xcfg and web.xml at the time of deployment.

    Could you point me how to do this.

    Thanks again for your time .

    ReplyDelete
  10. Hi,

    I don't really understand it. I only need to create a datasource once and I can deploy it many times.

    if I was you I would create on the wls a datasource with jdbc/XXXDS and use this as datasource in the bc4j.cfg not java:env...

    do you mean that you need to deploy this ear , 7 seven times on the same wls and use 7 different datasources.

    I know you can change the datasource after the deployment in the enterprise manager console. ( adf connections )

    thanks

    ReplyDelete
  11. Yes .. i need to deploy the same EAR file , in a single managed server for seven times and each pointing to different Data Source.

    ReplyDelete
  12. Ok,

    Deployment plan won't work, the only thing you can is a custom ant deployment where you change the files and make a war/ ear

    or you can take a look at this
    http://4.bp.blogspot.com/_earSixbe3dw/SlCIWeMAgdI/AAAAAAAACms/UN20O5icQI4/s1600-h/adf_em_11.png

    in the em site. part of this http://biemond.blogspot.com/2009/07/adf-web-applications-and-oracle.html

    and you can use wlst and try to lookup the right mbeans and change the datasource after deployment.

    thanks

    ReplyDelete
  13. Thanks Edvin. Will try the options. Thanks again for your time and ideas.

    ReplyDelete
  14. A concise article to learn, thanks.

    Another simpler method to generate a deployment plan:
    using console, go to the configuration tab for your application, change one of the property there then click save. The console will create a deployment plan (you can specify the location & name) if the deployment plan doesn't exist yet.

    You can install the deployment plan also via console by redeploy your application while specifying the deployment plan.

    Caveat: if you have a non-dynamic properties in your deployment plan, updating will give you an exception "Non-dynamic properties were found to be updated", so you need to be sure to select "redeploy" instead of "update" on Update Application Assistant.

    ReplyDelete
  15. Hi Edwin,

    In my SOA Application i had used a database adapter to write data into a table.and the JNDI of the outbound connection pool of the Database was : eis/DB/Target1
    . but for some requirements i have to change the location of database and my new outbound connection pool of the Database is : eis/DB/Target2

    [Server is same but database location is diiferent]

    I had generate the configuration file of the composite but unable to locate/change the JNDI of the Database in the Configuration file.

    Is it possible to change JNDI of tha database using configuration file?
    If possible please help.

    Thanks in Advance.

    ReplyDelete
  16. Hi,

    the jndi location of the resource adapter is located in the wsdl of the database adapter.

    include this wsdl in your plan and changit.

    you can also overrule the datasource of the old resource adapter, by using the assign properties in the mediator or bpel.

    thanks

    ReplyDelete
  17. Hi Edwin,

    Thanks for your reply.
    I had tried the 2nd option and working fine. But can you please tell me the way to include the .wsdl file into the plan(configuration.xml)file.


    Thanks in advance.

    ReplyDelete
  18. Is it possible to change wsdl urls using deployment plan generated ?

    ReplyDelete
    Replies
    1. Hi,

      you probably have a servlet definition in the web.xml , in the web.xml you can change the url-pattern for example. Everything you can put in the web.xml can be changed.

      thanks

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
      <servlet>
      <display-name>CalculatorService</display-name>
      <servlet-name>CalculatorService</servlet-name>
      <servlet-class>
      org.apache.geronimo.samples.jws.CalculatorService
      </servlet-class>
      </servlet>

      <servlet-mapping>
      <servlet-name>CalculatorService</servlet-name>
      <url-pattern>/calculator</url-pattern>
      </servlet-mapping>

      .....
      </web-app>

      Delete
  19. Is it possible to change web service data control wsdl url using this method. I saw the post where you can change the wsdl and write to MDS but we are not on ps5 so cannot use that solution. Is there a way to have a context parameter and refer to it in webservice data control ?

    ReplyDelete
    Replies
    1. Hi,

      No you can't but you can generate a ws proxy on which you can generate a datacontrol. In the webservice ref you can do what you want.

      like I do here http://biemond.blogspot.com/2011/10/working-with-human-worklist-api-and.html
      where I load a property file or read a java parameter

      and here I set this on the webservice ref
      http://biemond.blogspot.com/2009/04/changing-wsdl-url-endpoint-in-jax-ws.html


      thanks

      Delete
  20. Hi Biemond,

    I have a war file which will trigger my bpel process in every 5 mins. This war seems to work when i deployed using jdeveloper in Dev Env and change endpoints manually and deploy into the Test Env using Jdeveloper and working as expected. But if i go with Plan.xml and followed the process as explained by you and end result by service never got triggered.
    I generated deployment plan in same weblogic server and installed it through weblogic deployment screen and this one also giving the same result. So my doubt is do it taking the context params which i defined in web.xml or not. How to debug it? even i don't see valid information from the logs. Could you please help me?

    Here is the problem i post in oracle forum.. pleas help me.....

    https://forums.oracle.com/forums/message.jspa?messageID=10648703#10648703

    Regards,
    Tarak

    ReplyDelete
    Replies
    1. Hi,

      was your problem in the schedular code or in the plan, maybe you can deploy it as an exploded war and see the changes.

      thanks.

      Delete
  21. This comment has been removed by the author.

    ReplyDelete
  22. Hi Edwin,

    we developed quartz scheduler to trigger BPEL process.

    We followed the below link for developing scheduler and the scheduling is working fine
    http://www.oracle.com/technetwork/middleware/soasuite/learnmore/soascheduler-186798.pdf

    As part of scheduling option, we have mentioned the scheduling times as Init parameter in web.xml.
    we are reading this init param in java code to schedule the bpel process.
    In future if we want to change the scheduling time we can use plan.xml as deployment plan in weblogic console to change the scheduling time. so that we dont have to build the war file, when ever we need to change the scheduling time.

    Below is the content of web.xml

    <?xml version = "1.0" encoding = "windows-1252"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" (http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd%27)
    version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
    <servlet>
    <servlet-name>SOASchedulerServlet</servlet-name>
    <servlet-class>saks.oracle.otn.soascheduler.SOASchedulerServlet</servlet-class>
    <init-param>
    <param-name>cronExpr</param-name>
    <param-value>0 0,5,10,15,20,25,30,35,40,45,50,55 * * * ?</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>SOASchedulerServlet</servlet-name>
    <url-pattern>/soaschedulerservlet</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>/soaschedulerservlet</welcome-file>
    </welcome-file-list>
    </web-app>


    and the plan.xml which is used to change the init parameter of web.xml


    <?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>SOAScheduler</application-name>

    <variable-definition>
    <variable>
    <name>NewValue</name>
    <value>0 0/5 14,18 * * ?</value>
    </variable>
    </variable-definition>

    <module-override>
    <module-name>SOAScheduler</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>NewValue</name>
    <xpath>/web-app/init-param/[param-name="cronExpr"]/param-value</xpath>
    <>
    </variable-assignment>
    </module-descriptor>

    </module-override>
    <config-root&gt/u01/Oracle/Middleware/user_projects/domains/soa_domain/servers/AdminServer/upload/SOAScheduler/app/</config-root>
    </deployment-plan>


    from weblogic console when I try to redeploy the war with deployment plan as plan.xml, as mentioned above.
    I am getting errors like

    Error Errors occured while loading the deployment plan.
    Error $Proxy304 incompatible with weblogic.management.configuration.WLDFSystemResourceMBean


    and the init parameter is not changed..

    could you please help me on this....

    ReplyDelete
    Replies
    1. Hi,

      How do did you generate this plan, I think there is something wrong with version , namespace etc.
      can you try to use OEPE and use the wizard to generate a plan with the help of the pluging
      http://docs.oracle.com/cd/E15315_09/help/oracle.eclipse.tools.weblogic.doc/html/deploymentPlanEditor.html

      how this can help you.

      Thanks

      Delete
  23. Hi Mak,
    Did you get solution for overiding init-params defined in web.xml?
    I tried, It changes config-params but I am not able to override web.xml using Plan.xml.
    Any suggestion how to override init-param in web.xml?

    ReplyDelete
  24. Hi,

    I will try to make an OEPE demo workspace with an ear plus a war together with some plans

    Thanks

    ReplyDelete
  25. I need to proxy from a web server via the WLS plugin to multiple ADF apps on multiple wls servers. I do this by using the ppath attribute of the plugin (e.g. ppath='/wls/em/*') and the PathTrim directive (e.g. PathTrim='/wls') to strip off the leading /wls since the context root of the app is simply "/em" on WLS. I am using the Fusion Middleware Console webapp as a proof-of-concept.

    When I configure the plugin to delegate the requests to WLS it forwards to the server but the EM app login page is not displayed. Looking at the page source, I see that it returns a reference to the absolute URIs like "/em/adf/..." which are not accurate since we need to prefix all paths with /wls.

    Is it possible to use a deployment plan to change the URI of the ADF libraries themselves? I generated a deployment plan for em.ear, and it's a little overwhelming (1800+ lines). I see lots of variable assignments that look like this:

    /weblogic-application/library-ref/[context-root="null",library-name="adf.oracle.domain"]/specification-version

    I'm wondering if simply changing context-root="null" to context-root="/wls" would resolve this.

    Any thoughts would be appreciated.

    ReplyDelete
    Replies
    1. hi,

      you can add this to the weblogic.xml of the war and use this
      weblogic-web-app -> session-descriptor -> context-root

      don't know if you can do this in the ear and the weblogic-application.xml

      thanks

      Delete
  26. Hi,
    Thanks for your great article regarding this deployment plan, just one question:
    is it possible to use this mechanism to modify property value?? for example, inside persistence.xml, can I modify value of "eclipselink.target-database" property to MySQL?


    org.eclipse.persistence.jpa.PersistenceProvider
    datasource1




    Thanks~!

    ReplyDelete
    Replies
    1. Hi,

      Don't think so cause it mostly in a jar inside the web-inf/lib folder and I also think it can only change JEE or WebLogic deployment descriptors

      Thanks

      Delete