Search code examples
javaweblogicwarweblogic12cwiremock

Validation problem while deploying Wiremock to Weblogic as a war


I need to deploy Wiremock as a WAR to Weblogic 12.2.1.2 but during the deployment I get the a long exception. I use web.xml file from the sample-war project from git.

In my pom.xml I only use the following dependency:

<dependency>
    <groupId>com.github.tomakehurst</groupId>
    <artifactId>wiremock</artifactId>
    <version>2.19.0</version>
</dependency>

I can deploy my WAR to Tomcat 9.x and everything works fine. But I need to use Weblogic and the same WAR does not work there. This is the beginning of the long exception I get:

####<oct 16, 2018, 10:03:26,646 DU CEST> <Error> <Munger> <mylinux> <AdminServer> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <weblogic> <> <00dcc5b7-e294-4d36-943a-2d6d188fdd23-00000013> <1539720206646> <[severity-value: 8] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-2156200> <Unable to load descriptor /home/user/servers/oracle/weblogic/12.2.1.2.0/user_projects/domains/base_domain/servers/AdminServer/tmp/.appmergegen_1539720205648_wire-mock-demo-1.0-SNAPSHOT.war/WEB-INF/web.xml of module wire-mock-demo-1.0-SNAPSHOT.war. The error is weblogic.descriptor.DescriptorException: VALIDATION PROBLEMS WERE FOUND
  <7:11> problem: cvc-complex-type.2.4b: Element not allowed: description@http://xmlns.jcp.org/xml/ns/javaee in element listener@http://xmlns.jcp.org/xml/ns/javaee
at weblogic.descriptor.internal.MarshallerFactory$1.evaluateResults(MarshallerFactory.java:245)
at weblogic.descriptor.internal.MarshallerFactory$1.evaluateResults(MarshallerFactory.java:231)
at weblogic.descriptor.internal.MarshallerFactory$1.createDescriptor(MarshallerFactory.java:155)
at weblogic.descriptor.BasicDescriptorManager.createDescriptor(BasicDescriptorManager.java:345)
at weblogic.descriptor.BasicDescriptorManager.createDescriptor(BasicDescriptorManager.java:307)
at weblogic.application.descriptor.AbstractDescriptorLoader2.getDescriptorBeanFromReader(AbstractDescriptorLoader2.java:870)
at weblogic.application.descriptor.AbstractDescriptorLoader2.createDescriptorBean(AbstractDescriptorLoader2.java:445)
at weblogic.application.descriptor.AbstractDescriptorLoader2.loadDescriptorBeanWithoutPlan(AbstractDescriptorLoader2.java:832)
at weblogic.application.descriptor.AbstractDescriptorLoader2.loadDescriptorBean(AbstractDescriptorLoader2.java:841)
at weblogic.servlet.internal.WebAppDescriptor.getWebAppBean(WebAppDescriptor.java:145)
at weblogic.servlet.utils.WarUtils.getWebAppBean(WarUtils.java:201)
at weblogic.servlet.tools.WARModule.loadDescriptors(WARModule.java:451)
at weblogic.servlet.tools.WARModule.merge(WARModule.java:520)
at weblogic.application.compiler.ToolsModuleWrapper.merge(ToolsModuleWrapper.java:96)
at weblogic.application.utils.CustomModuleManager.merge(CustomModuleManager.java:78)
at weblogic.application.compiler.flow.SingleModuleMergeFlow.proecessModule(SingleModuleMergeFlow.java:27)
at weblogic.application.compiler.flow.SingleModuleFlow.compile(SingleModuleFlow.java:64)
at weblogic.application.compiler.FlowDriver$FlowStateChange.next(FlowDriver.java:70)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)

I have checked the mentioned web.xm file but this totally okay. I have tried to use web.xml v3.0 and 3.1 as well. Both of them not working. It seems that the real problem is not with web.xml file. It comes from listener: com.github.tomakehurst.wiremock.servlet.WireMockWebContextListener

Is there any idea what is wrong here and how to fix it?


Solution

  • The following steps need to be performed in order to have a working WAR file with WireMock 2.19.0:

    Issue (1):

    Element not allowed: description@http://xmlns.jcp.org/xml/ns/javaee in element listener@http://xmlns.jcp.org/xml/ns/javaee

    Solution: Remove description tag from the listener section of the web.xml file.

    Issue (2):

    java.lang.NullPointerException at com.github.tomakehurst.wiremock.common.ServletContextFileSource.getRootFile(ServletContextFileSource.java:35)

    Solution 1: Weblogic admin console > Domain > Web Applications > click the checkbox "Archived Real Path Enabled"

    Solution 2: add weblogic.xml file to WEB_INF dirrectory, content:

    <weblogic-web-app>
        <container-descriptor>
            <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
        </container-descriptor>
    </weblogic-web-app>
    

    Issue (3):

    Classpath conflicts

    Add prefer-application-packages to WEB_INF/weblogic.xml file:

    <prefer-application-packages>
        <package-name>com.fasterxml.jackson.*</package-name>
        <package-name>com.google.common.*</package-name>
        <package-name>com.google.thirdparty.*</package-name>
        <package-name>net.minidev.json.*</package-name>
    </prefer-application-packages>
    

    Issue (4):

    Change the mapping URL of the WireMockHandlerDispatchingServlet:

    <servlet>
        <servlet-name>wiremock-mock-service-handler-servlet</servlet-name>
        ...
        <init-param>
            <param-name>mappedUnder</param-name>
            <param-value>/mapping</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>wiremock-mock-service-handler-servlet</servlet-name>
        <url-pattern>/mapping/*</url-pattern>
    </servlet-mapping>
    

    Issue (5):

    Exclude Jetty related dependencies:

    <dependency>
        <groupId>com.github.tomakehurst</groupId>
        <artifactId>wiremock</artifactId>
        <version>2.19.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-server</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-servlet</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-servlets</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-webapp</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    

    +1

    Remove WireMock admin service.

    Delete wiremock-admin-handler-servlet servlet and its servlet-mapping configuration from WEB_INF/weblogic.xml file.

    With steps above you can build a WAR which is deployable to Weblogic 12.2.x server.