Weblogic 12.2.1.3 from Moxy to Jackson

落爺英雄遲暮 提交于 2019-12-08 08:16:39

问题


I would like to change the JSON parser from Moxy to Jackson, and I have followed the shared library approach, but without any result, Moxy is still used.

Note: the shared library is not necessary!!!

The shared library

I have created a maven project with the following dependencies and descriptors.

pom.xml

 <properties>
    <jackson.annotations.release>2.8.6</jackson.annotations.release>
    <jersey.version>2.22.4</jersey.version>
 </properties>

 <dependencies>
    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-jaxb-annotations</artifactId>
        <version>${jackson.annotations.release}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
        <version>${jackson.annotations.release}</version>
    </dependency>

    <!-- Jersey dependencies -->
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
        <version>${jersey.version}</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>${jersey.version}</version>
    </dependency>
</dependency>

weblogic.xml

 <container-descriptor>
    <prefer-application-packages>
        <!-- apis -->
        <package-name>javax.ws.rs.*</package-name>

        <!-- guava -->
        <package-name>com.google.common.*</package-name>

        <!-- jersey providers -->
        <package-name>org.glassfish.jersey.*</package-name>
        <package-name>jersey.repackaged.*</package-name>

        <!-- hk2 -->
        <package-name>org.jvnet.hk2.*</package-name>
        <package-name>org.jvnet.hk2.tiger_types.*</package-name>
        <package-name>org.glassfish.hk2.*</package-name>
        <package-name>javassist.*</package-name>

        <!-- media providers -->
        <!--<package-name>org.eclipse.persistence.jaxb.rs.*</package-name>-->
        <package-name>com.fasterxml.jackson.*</package-name>

        <!-- wls -->
        <package-name>weblogic.jaxrs.api.client.*</package-name>
        <package-name>weblogic.jaxrs.internal.api.client.*</package-name>
        <package-name>weblogic.jaxrs.dispatch.*</package-name>
        <package-name>weblogic.jaxrs.monitoring.util.*</package-name>
    </prefer-application-packages>
</container-descriptor>

MANIFEST.MF

Manifest-Version: 1.0
Implementation-Title: Jackson Weblogic
Implementation-Version: 1.0
Specification-Title: Jackson Weblogic
Extension-Name: jackson-weblogic
Specification-Version: 1.0

Web Application

I add the web.xml and the weblogic.xml.

web.xml

<servlet>
    <servlet-name>com.dummy.MyApplication</servlet-name>
        <init-param>
            <param-name>jersey.config.server.provider.classnames</param-name>
            <param-value>com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider</param-value>
        </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>com.dummy.MyApplication</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

weblogic.xml

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
    <library-ref>
        <library-name>jstl</library-name>
        <specification-version>1.2</specification-version>
        <implementation-version>1.2</implementation-version>
        <exact-match>false</exact-match>
    </library-ref>
    <library-ref>
        <library-name>jackson-weblogic</library-name>
        <specification-version>1.0</specification-version>
        <exact-match>false</exact-match>
    </library-ref>
</weblogic-web-app>

Then I reference in the weblogic.xml the shared library, but Moxy is still used. Have I done something wrong?

Update: I have added the web.xml and the weblogic.xml of the web application.

Solution

I have checked the folder oracle_common\modules and I have found all the Jackson dependencies needed. So I have preferred to configure Jersey to disable the use of MOXy as follows:

import javax.ws.rs.core.Application;
public class MyApplication extends Application
{
    @Override
    public Map<String, Object> getProperties()
    {
        Map<String, Object> proprties = new HashMap<>();
        proprties.put("jersey.config.server.disableMoxyJson", true);

        return proprties;
    }
}

Pay attention:

  • that the method getProperties() comes with javax.ws.rs 2.0;
  • no specific shared library is necessary for Jackson, but just for jstl and jax-rs 2.0;
  • no info inside web.xml is required;
  • as reported by @abbas JAX-RS 2.0 comes by default with Weblogic 12.2.1.3.0 in my case I has a transitive dependency on javax.ws.rs:jsr311-api so the method getProperties() was not invoked.

Final weblogic.xml

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">

    <context-root>/web-app</context-root>
    <container-descriptor>
        <prefer-application-packages>
            <package-name>org.apache.commons.net.*</package-name>
        </prefer-application-packages>
    </container-descriptor>

    <library-ref>
        <library-name>jstl</library-name>
        <specification-version>1.2</specification-version>
        <implementation-version>1.2</implementation-version>
        <exact-match>false</exact-match>
    </library-ref>
</weblogic-web-app>

回答1:


Mention JAX-RS 2.0 as a dependency in your pom.xml

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0.1</version>
    <scope>provided</scope>
</dependency>

In WebLogic 12.2.1 you do not need to deploy it as a shared library.



来源:https://stackoverflow.com/questions/46813309/weblogic-12-2-1-3-from-moxy-to-jackson

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!