WebSphere Application Server & Liberty

 View Only
Expand all | Collapse all

Access Custom Properties of a Web Application from Code

  • 1.  Access Custom Properties of a Web Application from Code

    Posted Tue April 12, 2022 05:35 AM
    Hello IBM Folks,

    it is possible to define custom application propertes in the WebSphere console under Enterprise Applications > MyApplication > Custom properties. Now the following questions arise:

    1. How can I access these properties from the application code?
    2. Is it possible to pre-define these  properites in a deployment descriptor with default values?
    Kind regards
    Thomas

    ------------------------------
    Thomas Mayr
    ------------------------------


  • 2.  RE: Access Custom Properties of a Web Application from Code

    Posted Wed April 13, 2022 05:46 AM
    Hi, App custom properties act like any other System property and can be retrieved in the application the same way, System.getProperty("propertyName"); .

    If you are using the Eclipse tooling then you should be able to add the property to the deployment.xml.  Example of my deployment.xml where I have "my.hair.colour":

    <?xml version="1.0" encoding="UTF-8"?>
    <appdeployment:Deployment xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:appdeployment="http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi" xmi:id="Deployment_1648758360938">
    <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1648758360938" deploymentId="0" startingWeight="1" binariesURL="$(APP_INSTALL_ROOT)/paskinoCell/modresorts-1_0_war.ear" useMetadataFromBinaries="false" enableDistribution="true" createMBeansForResources="true" reloadEnabled="false" appContextIDForSecurity="href:paskinoCell/modresorts-1_0_war" filePermission=".*\.dll=755#.*\.so=755#.*\.a=755#.*\.sl=755" allowDispatchRemoteInclude="false" allowServiceRemoteInclude="false" asyncRequestDispatchType="DISABLED" standaloneModule="true" enableClientModule="false">
    <targetMappings xmi:id="DeploymentTargetMapping_1648758360938" enable="true" target="ServerTarget_1648758360938"/>
    <classloader xmi:id="Classloader_1648758360938" mode="PARENT_FIRST"/>
    <modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_1648758360938" deploymentId="1" startingWeight="10000" uri="modresorts-1.0.war" containsEJBContent="0">
    <targetMappings xmi:id="DeploymentTargetMapping_1648758360939" target="ServerTarget_1648758360938"/>
    <classloader xmi:id="Classloader_1648758360939"/>
    </modules>
    <properties xmi:id="Property_1648758360938" name="metadata.complete" value="false"/>
    <properties xmi:id="Property_1649842716335" name="my.hair.colour" value="bald" required="false"/>
    </deployedObject>
    <deploymentTargets xmi:type="appdeployment:ServerTarget" xmi:id="ServerTarget_1648758360938" name="server1" nodeName="paskinoNode"/>
    </appdeployment:Deployment>

    ------------------------------
    Brian S Paskin
    Sr. Cloud Engineer
    IBM Cloud Engineering
    ------------------------------



  • 3.  RE: Access Custom Properties of a Web Application from Code

    Posted Wed April 13, 2022 09:21 AM
    Hello Brian,

    sorry, but this doesn't work! I defined the property "OpenAMBaseURL" here:

    But in the code I get null from System.getProperty():


    I also wonder where (in which folder) I should add the deployment.xml to the EAR. I downloaded the EAR from Websphere and found this file in META-INF/ibmconfig/cells/defaultCell/applications/defaultApp/deployments/defaultApp. Is this the right path? Further I wonder if I have to specify all these XML entries in this file. Are the all mandatory? Is there a documentation (XSD) of this XML structure? I'd like to understand what I'm doing.

    Kind regards
    Thomas

    ------------------------------
    Thomas Mayr
    ------------------------------



  • 4.  RE: Access Custom Properties of a Web Application from Code

    Posted Wed April 13, 2022 10:30 AM
    Hi, let me try the System properties again a bit later.  I have not done that in years.  Yes you have the correct path, and no the entries are not mandatory.  I believe that tWAS will infuse the other values during deploy time.

    Brian

    ------------------------------
    Brian S Paskin
    Sr. Cloud Engineer
    IBM Cloud Engineering
    ------------------------------



  • 5.  RE: Access Custom Properties of a Web Application from Code

    Posted Wed April 13, 2022 12:53 PM
    Ok, I did some more digging.  Those properties are used during deploy time/startup, but not at runtime, which makes them not useable for the application.  The appdeployment XSD does not look like it is available as a single XSD, but part of application.xsl.

    Brian

    ------------------------------
    Brian S Paskin
    Sr. Cloud Engineer
    IBM Cloud Engineering
    ------------------------------



  • 6.  RE: Access Custom Properties of a Web Application from Code

    Posted Thu April 14, 2022 02:42 AM
    Thank you Brian!

    But in this case these properties are useless for me,

    Also the the deployment.xsd is not helpful if I have to place it untder this directory path, which is deployment dependent.

    I saw that the following class loader property is defined in this file:

    <classloader xmi:id="Classloader_1649780608092" mode="PARENT_LAST"/>

    Is there a way to define this property in a "standard" WebSphere deployment descriptor (e.g. ibm-application-bnd.xml)? It is rather annoying to set this property every time after the deployment manually.

    Kind regards
    Thomas

    ------------------------------
    Thomas Mayr
    ------------------------------



  • 7.  RE: Access Custom Properties of a Web Application from Code

    Posted Thu April 14, 2022 02:04 PM
    The only way to do this without the file would be via Jython/JACL scripting.

    Brian

    ------------------------------
    Brian S Paskin
    Sr. Cloud Engineer
    IBM Cloud Engineering
    ------------------------------



  • 8.  RE: Access Custom Properties of a Web Application from Code

    IBM Champion
    Posted Tue April 19, 2022 01:59 AM
    Just an additional note to @Brian S Paskin last update - there are also Java Admin APIs/SPIs ( https://www.ibm.com/docs/en/was/9.0.5?topic=environment-managing-applications-through-programming ) for WebSphere Application Server available which could be used to retrieve the same info which you get via Jython/JACL scripting.


    ------------------------------
    Hermann Huebler
    2innovate IT Consulting GmbH
    Vienna
    Austria

    #IBMChampion
    ------------------------------



  • 9.  RE: Access Custom Properties of a Web Application from Code

    Posted Wed April 20, 2022 12:12 PM
    Hello Hermann,

    thank's for this link! But the sample shows how to access the properties in an application from outside the WebSphere. This is not what I want to do. I need a way to access these custom application properties from the deployed application itself (inside the WebSphere).

    Kind regards
    Thomas

    ------------------------------
    Thomas Mayr
    ------------------------------



  • 10.  RE: Access Custom Properties of a Web Application from Code

    IBM Champion
    Posted Wed April 20, 2022 12:21 PM
    Hello @Thomas Mayr,
    not sure I understand your concerns correctly but what prevents you from using the Management APIs with the application itself? The https://www.ibm.com/docs/en/was/9.0.5?topic=programming-accessing-application-management-function states as well "... The com.ibm.websphere.management.application.AppManagementProxy class provides uniform access to application management functionality, regardless of whether the functionality is accessed from the server process, administrative client process, or a stand-alone Java™ program in the absence of WebSphere® Application Server ...".


    ------------------------------
    Hermann Huebler
    2innovate IT Consulting GmbH
    Vienna
    Austria

    #IBMChampion
    ------------------------------



  • 11.  RE: Access Custom Properties of a Web Application from Code

    Posted Wed April 27, 2022 06:04 AM
    Hello Hermann,

    good to know, that this is possible! I have to negotiate this solution with the deployment department and I'll try this if they agree.

    Kind regards
    Thomas

    ------------------------------
    Thomas Mayr
    ------------------------------