Websphere liberty 19 как переопределить источники jndi ref, определенные в web.xml - PullRequest
0 голосов
/ 20 октября 2019

У меня есть ухо, и в этом ухе существует две войны.
Я пытался, но не могу переопределить все определенные источники в файле web.xml. Я не хочу, чтобы server.xml был моей основной конфигурацией. Все мои попытки терпят неудачу.

Может кто-нибудь дать мне пример, как переопределить конфигурацию в файлах web.xml и bnd ?

Моя конфигурация:

server.xml

<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
  <keyStore password="{xor}Lz4sLCg7" />
  <!-- Enable features -->
  <featureManager>
    <feature>jndi-1.0</feature>
    <feature>distributedMap-1.0</feature>
    <feature>localConnector-1.0</feature>
    <feature>beanValidation-2.0</feature>
    <feature>json-1.0</feature>
    <feature>adminCenter-1.0</feature>
    <feature>appSecurity-2.0</feature>
    <feature>cdi-2.0</feature>
    <!-- <feature>cdi-2.0</feature -->
    <feature>jsf-2.3</feature>
    <feature>mdb-3.2</feature>
    <feature>ejbHome-3.2</feature>
    <feature>ejbLite-3.2</feature>
    <feature>ejbRemote-3.2</feature>
    <feature>jca-1.7</feature>
    <feature>jms-2.0</feature>
    <feature>ldapRegistry-3.0</feature>
    <feature>jaxrs-2.1</feature>
  </featureManager>
  <authCache initialSize="100" maxSize="50000" timeout="90m" />
  <applicationMonitor dropinsEnabled="false" />
  <distributedMap id="baseCache" memorySizeInMB="500">
  </distributedMap>
  <basicRegistry id="basic" realm="LdapRegistry">
    <user password="{xor}Ozo5Kiw6LQ==" name="defuser" />
    <user password="OO7GVOJC" name="user" id="test" />
  </basicRegistry>
  <remoteFileAccess>
    <writeDir>${server.config.dir}</writeDir>
  </remoteFileAccess>
  <administrator-role>
    <user>user</user>
  </administrator-role>
  <!-- new properties-->


  <jdbcDriver id="DB2_Using_IBM_JCC_Driver" javax.sql.DataSource="com.ibm.db2.jcc.DB2ConnectionPoolDataSource">
    <library>
      <file name="${DB2_JCC_DRIVER_PATH}/db2jcc4.jar" />
      <file name="${UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar" />
      <file name="${DB2_JCC_DRIVER_PATH}/db2jcc_license_cisuz.jar" />
      <file name="${PUREQUERY_PATH}/pdq.jar" />
      <file name="${PUREQUERY_PATH}/pdqmgmt.jar" />
    </library>
  </jdbcDriver>
  <dataSource containerAuthDataRef="DB2USER" id="DEFAULT-DB2" jdbcDriverRef="DB2_Using_IBM_JCC_Driver" jndiName="jdbc/DEFAULT-DB2">
    <properties.db2.jcc databaseName="D0" description="Default DB2 JCC Driver Datasource" name="DEFAULT-DB2" portNumber="50000" serverName="db2connect.dev.intranet.eu" driverType="2" />
    <connectionManager agedTimeout="0" connectionTimeout="180" maxIdleTime="1800" maxPoolSize="10" minPoolSize="1" reapTime="180" />
  </dataSource>



  <!---ENS-->
  <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
  <httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint" />
  <!-- Automatically expand WAR files and EAR files -->
  <applicationManager autoExpand="true" />
  <applicationMonitor updateTrigger="mbean" />


  <enterpriseApplication id="PRE-EAR" location="${server.config.dir}/apps/expanded/PRE-EAR.ear" name="PRE-EAR" type="ear">
    <classloader privateLibraryRef="javassist" commonLibraryRef="javassist" delegation="parentLast" />
    <application-bnd>
      <security-role name="Authenticated">
        <user name="user2" access-id="user2" />
        <run-as userid="user" password="test" />
      </security-role>
    </application-bnd>
  </enterpriseApplication>
  <logging consoleLogLevel="ERROR" traceFormat="ADVANCED" />
  <authData user="TA02113" password="OO7GVOJC" />
</server>

application.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" 
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/application_5.xsd" version="5">
  <display-name>PRE-EAR</display-name>
  <module>
    <ejb>PRE-BF.jar</ejb>
  </module>
  <module>
    <web>
      <web-uri>PRE-WS.war</web-uri>
      <context-root>/PRE-WS</context-root>
    </web>
  </module>
  <module>
    <web>
      <web-uri>PRE-RS.war</web-uri>
      <context-root>/PRE-RS</context-root>
    </web>
  </module>
  <module>
    <web>
      <web-uri>PRE-PF.war</web-uri>
      <context-root>/PRE-PF</context-root>
    </web>
  </module>
  <security-role>
    <role-name>Authenticated</role-name>
  </security-role>
  <security-role>
    <role-name>Guest</role-name>
  </security-role>
  <library-directory>lib</library-directory>
</application>

ibm-application-bnd.xml

<?xml version="1.0" encoding="UTF-8"?>
<application-bnd
    xmlns="http://websphere.ibm.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-application-bnd_1_0.xsd"
    version="1.0">
    <security-role name="Authenticated">
        <special-subject type="ALL_AUTHENTICATED_IN_TRUSTED_REALMS" />
    </security-role>
    <security-role name="Guest">
        <special-subject type="EVERYONE" />
    </security-role>
</application-bnd>

Конфигурация одной из войн

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <display-name>PRE-RS</display-name>

    <servlet>
        <servlet-name>cxf</servlet-name>
        <servlet-class>
            CXFServlet
        </servlet-class>
        <init-param>
        <param-name>javax.ws.rs.Application</param-name>
            <param-value>RestApplicationConfig</param-value>
        </init-param>   
        <init-param>
            <param-name>jaxrs.address</param-name>
            <param-value>/service</param-value>
        </init-param>       
        <init-param>
            <param-name>jaxrs.application.address.ignore</param-name>
            <param-value>false</param-value>
        </init-param>   
        <init-param>
            <param-name>hide-service-list-page</param-name>
            <param-value>false</param-value>
        </init-param>        
        <init-param>
            <param-name>jaxrs.inInterceptors</param-name>
            <param-value>org.apache.cxf.interceptor.LoggingInInterceptor</param-value>
        </init-param>       
        <init-param>
            <param-name>jaxrs.outInterceptors</param-name>
            <param-value>org.apache.cxf.interceptor.LoggingOutInterceptor</param-value>
        </init-param>       
    </servlet>

    <servlet-mapping>
        <servlet-name>cxf</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>


    <security-role>
        <role-name>Authenticated</role-name>
    </security-role>
    <security-role>
        <role-name>Guest</role-name>
    </security-role>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>service</web-resource-name>
            <url-pattern>/service/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
            <http-method>PUT</http-method>
            <http-method>DELETE</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>Authenticated</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>


    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>customRealm</realm-name>        
    </login-config>


    <resource-ref>
        <description />
        <res-ref-name>jdbc/defaultDs</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>


</web-app>

ibm-web-bnd.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-bnd 
    xmlns="http://websphere.ibm.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
    version="1.0">

    <virtual-host name="default_host" />

    <resource-ref name="jdbc/defaultDs" binding-name="jdbc/DEFAULT-DB2" />   

</web-bnd>

Я получаю сообщение об ошибке, что DEFAULT-DB2 не установлен. Я проверил, и нет прямой привязки jndi, ни одна из войн не видит данных в jndi direct jdbc / DEFAULT-DB2, но я не знаю почему.

...