Message Boards

Liferay 7.2 Rest Service module not working, but same code module

Vishal Shah, modified 4 Years ago.

Liferay 7.2 Rest Service module not working, but same code module

Junior Member Posts: 33 Join Date: 2/1/12 Recent Posts
Hi,I created the Liferay 7.1 rest service module based on the Liferay module rest template, and build and deploy in Liferay 7.1 properly working code. But not I am the same module code move to Liferay 7.2 and new build generate and deployed in Liferay 7.2 CE server.
But code not woking asking for "javax.activation" dependencies related error throwing. so I am adding 2 more dependencies related to asking "javax.activation" related. Evenafter adding dependencies throwing an error as below :

Error :::2019-10-22 06:46:44.906 WARN  [http-nio-9870-exec-1][PhaseInterceptorChain:88] Application {http://application.rest.sample.com/}SampleApplication has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "javax/activation/DataHandler"
Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "javax/activation/DataHandler"
2019-10-22 06:46:44.920 WARN  [http-nio-9870-exec-1][PhaseInterceptorChain:88] Exception in handleFault on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSDefaultFaultOutInterceptor@57a470f1
org.apache.cxf.interceptor.Fault: loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "javax/activation/DataHandler"

What kind of changes done in Liferay 7.1 and Liferay 7.2 for Rest Service building??
BUILD.GRADLE
dependencies {
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
    compileOnly group: "javax.ws.rs", name: "javax.ws.rs-api"
    compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations"
    compileOnly group: "org.osgi", name: "org.osgi.service.jaxrs"
    //compileOnly group: "javax.servlet", name: "javax.servlet-api"
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.8'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.8'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.8'
    
    compile group: 'org.apache.tika', name: 'tika-core', version: '1.20'
    compileOnly group: 'org.apache.tika', name: 'tika-parsers', version: '1.20'
    
    compile group: 'com.sun.jersey', name: 'jersey-core', version: '1.19'
    compile group: 'com.sun.jersey.contribs', name: 'jersey-multipart', version: '1.19'
    compile group: 'org.jvnet.mimepull', name: 'mimepull', version: '1.9.3'
    compile group: 'com.sun.jersey', name: 'jersey-server', version: '1.19'
    
    compile group: 'org.json', name: 'json', version: '20180813'
    
    compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.1'
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5'
    compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5'
    
    compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.3'
    compile group: 'commons-io', name: 'commons-io', version: '2.2'
    compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
    //compileOnly group: 'commons-logging', name: 'commons-logging', version: '1.2'
    //compileOnly group: 'commons-codec', name: 'commons-codec', version: '1.12'
    
    compileOnly group: "com.liferay", name: "com.liferay.petra.string", version: "2.0.0"
    //compile group: 'javax.activation', name: 'activation', version: '1.1'
    compile group: 'javax.activation', name: 'javax.activation-api', version: '1.2.0'
    compile group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'
}


BND.BND
Bundle-Name: sample-rest
Bundle-SymbolicName: com.sample.rest
Bundle-Version: 1.0.0
Include-Resource:\
                @jackson-core-2.9.8.jar,\
                @jackson-databind-2.9.8.jar,\
                @jackson-annotations-2.9.8.jar,\
                @json-20180813.jar,\
                @jersey-core-1.19.jar,\
                @jersey-multipart-1.19.jar,\
                @mimepull-1.9.3.jar,\
                @jersey-server-1.19.jar,\
                @httpcore-4.4.1.jar,\
                @httpclient-4.5.jar,\
                @httpmime-4.5.jar,\
                @commons-fileupload-1.3.3.jar,\
                @commons-io-2.2.jar,\
                @commons-lang-2.6.jar,\
                @tika-core-1.20.jar,\
                @javax.activation-api-1.2.0.jar,\
                @javax.activation-1.2.0.jar
                
                
Import-Package: \
    !com.beust.jcommander,\
    !com.beust.jcommander.validators,\
    !com.sun.net.httpserver,\
    !sun.security.action,\
    *
SampleApplication.java
@Component(property = { "auth.verifier.guest.allowed=true",
        "liferay.access.control.disable=true",
        JaxrsWhiteboardConstants.JAX_RS_APPLICATION_BASE + "=/sample",
        JaxrsWhiteboardConstants.JAX_RS_NAME + "=sample.rest" }, service = Application.class)
public class SampleApplication extends Application{
//MY Code}

As per Liferay 7.2 - https://portal.liferay.dev/docs/7-2/frameworks/-/knowledge_base/f/jax-rs
Public Rest Service create for DEV enviornment: "auth.verifier.guest.allowed=true",
        "liferay.access.control.disable=true",
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Liferay 7.2 Rest Service module not working, but same code module

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Vishal Shah:

org.apache.cxf.interceptor.Fault: loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "javax/activation/DataHandler"

BND.BND
...
Include-Resource:\
                @jackson-core-2.9.8.jar,\
                @jackson-databind-2.9.8.jar,\
                @jackson-annotations-2.9.8.jar,\
                @json-20180813.jar,\
                @jersey-core-1.19.jar,\
                @jersey-multipart-1.19.jar,\
                @mimepull-1.9.3.jar,\
                @jersey-server-1.19.jar,\
                @httpcore-4.4.1.jar,\
                @httpclient-4.5.jar,\
                @httpmime-4.5.jar,\
                @commons-fileupload-1.3.3.jar,\
                @commons-io-2.2.jar,\
                @commons-lang-2.6.jar,\
                @tika-core-1.20.jar,\
                @javax.activation-api-1.2.0.jar,\
                @javax.activation-1.2.0.jar
Sounds like this big impressive list of Include-Resource directives includes stuff that you shouldn't include. It's basically the equivalent of compileInclude, which you should avoid if possible - precisely for this reason (and for bloated jar sizes). Depend on the code coming from the OSGi runtime,  instead of bringing it all along. You might find different versions available, but you can cater for that. Check this OSGi Basics chapter for compileInclude mechanics (requires free registration).
Vishal Shah, modified 4 Years ago.

RE: Liferay 7.2 Rest Service module not working, but same code module

Junior Member Posts: 33 Join Date: 2/1/12 Recent Posts
After changing
BUILD.GRADLEdependencies {
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
    compileOnly group: "javax.ws.rs", name: "javax.ws.rs-api"
    compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations"
    compileOnly group: "org.osgi", name: "org.osgi.service.jaxrs", version: "1.0.0"
    compileOnly group: "javax.servlet", name: "javax.servlet-api"
    compileInclude group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.8'
    compileInclude group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.8'
    compileInclude group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.8'
    
    compileInclude group: 'org.apache.tika', name: 'tika-core', version: '1.20'
    compileOnly group: 'org.apache.tika', name: 'tika-parsers', version: '1.20'
    
    compileInclude group: 'com.sun.jersey', name: 'jersey-core', version: '1.19'
    compileInclude group: 'com.sun.jersey.contribs', name: 'jersey-multipart', version: '1.19'
    compileInclude group: 'org.jvnet.mimepull', name: 'mimepull', version: '1.9.3'
    compileInclude group: 'com.sun.jersey', name: 'jersey-server', version: '1.19'
    
    compileInclude group: 'org.json', name: 'json', version: '20180813'
    
    compileInclude group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.1'
    compileInclude group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5'
    compileInclude group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5'
    
    compileInclude group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.3'
    compileInclude group: 'commons-io', name: 'commons-io', version: '2.2'
    compileInclude group: 'commons-lang', name: 'commons-lang', version: '2.6'
    //compileOnly group: 'commons-logging', name: 'commons-logging', version: '1.2'
    //compileOnly group: 'commons-codec', name: 'commons-codec', version: '1.12'
    
    compileOnly group: "com.liferay", name: "com.liferay.petra.string", version: "2.0.0"
    compileInclude group: 'javax.activation', name: 'javax.activation-api', version: '1.2.0'
    compileInclude group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'
    compileInclude group: 'javax.activation', name: 'activation', version: '1.1.1'
}
BND.BND
Bundle-Name: nas-opentext-rest
Bundle-SymbolicName: com.sample.rest
Bundle-Version: 1.0.0
Liferay-Configuration-Path: /configurationImport-Package: \
    !com.beust.jcommander,\
    !com.beust.jcommander.validators,\
    !com.sun.net.httpserver,\
    !sun.security.action,\
    !org.apache.avalon.framework.logger,\
    !org.apache.log,\
    *
Deploy successfully and Start Component, But when I call service, showing warning message, but not execute my code.
 WARN  [http-nio-9870-exec-8][code_jsp:175] {code="404", msg="ProxyServlet: /sample/upload", uri=/o/sample/upload}

What is exactly missing from my end because I am going to Test in my dev environment as a public URL, don't want to any authentication 
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Liferay 7.2 Rest Service module not working, but same code module

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Vishal Shah:

...   compileInclude group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.8'
    compileInclude group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.8'
    compileInclude group:...
What I meant was not to exchange your Include-Resource with compileInclude, rather go with compile or compileOnly, and deploy all the secondary dependencies to the runtime environment as well (unless they were already available)
Check which of your dependencies are OSGi bundles,  which already are deployed in Liferay (and if their versions match your requirements). If your dependencies are neither deployed already nor OSGi bundles, check if the servicemix project OSGI-ified them already and use those libraries. But don't compileInclude them in bulk. CompileInclude is a last-resort, not a first-responder-tool.