Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Rest Service POST disagree on InnerClasses attribute

I have a REST service written in Java. I have a GET method which is working perfectly and now I want to implement the POST method.

@POST
@Consumes(MediaType.APPLICATION_JSON)
public void post(String ext){
    System.out.println("In the POST method");
    System.out.println(ext);
} 

Also I have a CORS Filter because I'm working on the localhost and sending stuff on the localhost.

Provider
public class CORSFilter implements ContainerResponseFilter {

@Override
public void filter(final ContainerRequestContext requestContext,
                  final ContainerResponseContext cres) throws IOException {
  cres.getHeaders().add("Access-Control-Allow-Origin", "*");
  cres.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
  cres.getHeaders().add("Access-Control-Allow-Credentials", "true");
  cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
  cres.getHeaders().add("Access-Control-Max-Age", "1209600");
} 
}

As soon as I add a parameter in the POST method I get the following error:

WARNING: HK2 service reification failed for [com.movierestservice.resources.MoviesResource$CORSFilter] with an exception:
MultiException stack 1 of 2
java.lang.IncompatibleClassChangeError: com.movierestservice.resources.MoviesResource and com.movierestservice.resources.MoviesResource$CORSFilter disagree on InnerClasses attribute
at java.lang.Class.getDeclaringClass0(Native Method)
at java.lang.Class.getDeclaringClass(Class.java:1235)
at java.lang.Class.getEnclosingClass(Class.java:1277)
at java.lang.Class.getSimpleBinaryName(Class.java:1443)
at java.lang.Class.isMemberClass(Class.java:1433)

etc ....

When I remove the parameter at the POST method everything is fine. Anybody has an idea how to solve this?

Thanks

like image 766
RSSD Avatar asked Aug 27 '26 07:08

RSSD


1 Answers

That IncompatibleClassChangeError probably means you have stale (old) .class files in your classpath. You need to recompile the project from scratch. Use "Clean project" or "Rebuild project" commands in your IDE or just delete the output directory (build or out or smth. like that).

And make sure you have enabled "make project before run" setting in your IDE.

like image 66
Roman Avatar answered Aug 28 '26 21:08

Roman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!