javajax-rsibm-mobilefirstmobilefirst-adapters

mobilefirst - Response type in Java adapters


I have a class (stored in server/java) that returns a Response type object and I want to use it in adapters.

public class CorsResponse {
public static Response build() {
    return Response
            .ok()
            .header("Access-Control-Allow-Origin", "*")
            .header("Access-Control-Allow-Methods", "GET, POST")
            .header("Access-Control-Allow-Headers", "accept, origin, content-type")
            .header("Access-Control-Max-Age", "1728000")
            .build();
}

If I use this class in an adapter's method, I get an exception:

javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: loader (instance of com/ibm/ws/classloading/internal/AppClassLoader) previously initiated loading for a different type with name "javax/ws/rs/core/Response" ...

Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of com/ibm/ws/classloading/internal/AppClassLoader) previously initiated loading for a different type with name "javax/ws/rs/core/Response"

How can I set which Response type to load?


Solution

  • I have managed to create an external project, put the class there, compile it to a jar file and include it in the adapters/adapter_name/lib folder (added to build path also).