How to set my CustomRestResponseFactory with spring config

cancel
Showing results for 
Search instead for 
Did you mean: 
ppcchh
Active Member

How to set my CustomRestResponseFactory with spring config

Jump to solution

Hello,

I am trying to make activiti-rest returning process variable of json type.

For this I understood I needed to add a JsonRestVariableConverter and register it in a CustomRestResponseFactory.

I use spring to configure my web application but when I try to override the RestResponseFactory, my class is not found  at server startup, although it is on classpath.

<bean id="restResponseFactory" class="mycompany.activiti.rest.CustomRestResponseFactory" />

I have read a post from 2014 which says :

If you want to customise RestResponseFactory the best way is too clone the REST application and change the RestConfiguration class:

Is it still true, is there no way to configure it via Spring ?

Thank you !

Stephane

1 Solution

Accepted Solutions
jearles
Established Member II

Re: How to set my CustomRestResponseFactory with spring config

Jump to solution

Stephane,

It is possible to 'overwrite' a java class, via including it in the classpath - load ordering depends on the server being used. For Tomcat, the load order is:

  1. Bootstrap classes of your JVM
  2. System class loader classes
  3. /WEB-INF/classes of your web application
  4. /WEB-INF/lib/*.jar of your web application
  5. Common class loader classes

Search around a bit and make sure you're attempting this in the right manner; it's going to vary per server, as I said earlier - and I imagine there are some that it's not possible.

I'm not sure I would recommend this as an approach - although there are plenty of StackOverflow comments and blogs that do similar things. I'm sure it's plausible, but our resources were not able to make this work and moved on to a different method.

The only way I've personally seen this done successfully, is to remove the bean declaration of RestResponseFactory from the RestConfiguration, and establish it elsewhere - which still requires modifying the RestResponseFactory directly. I would recommend this, which is basically an endorsement of the clone+edit method.

Hope this helps,
-JEarles

View solution in original post

2 Replies
jearles
Established Member II

Re: How to set my CustomRestResponseFactory with spring config

Jump to solution

Stephane,

It is possible to 'overwrite' a java class, via including it in the classpath - load ordering depends on the server being used. For Tomcat, the load order is:

  1. Bootstrap classes of your JVM
  2. System class loader classes
  3. /WEB-INF/classes of your web application
  4. /WEB-INF/lib/*.jar of your web application
  5. Common class loader classes

Search around a bit and make sure you're attempting this in the right manner; it's going to vary per server, as I said earlier - and I imagine there are some that it's not possible.

I'm not sure I would recommend this as an approach - although there are plenty of StackOverflow comments and blogs that do similar things. I'm sure it's plausible, but our resources were not able to make this work and moved on to a different method.

The only way I've personally seen this done successfully, is to remove the bean declaration of RestResponseFactory from the RestConfiguration, and establish it elsewhere - which still requires modifying the RestResponseFactory directly. I would recommend this, which is basically an endorsement of the clone+edit method.

Hope this helps,
-JEarles

ppcchh
Active Member

Re: How to set my CustomRestResponseFactory with spring config

Jump to solution

Hello Jonathan,

Thank you for the clear answer, I have done it overriding RestResponseFactory and it works fine.

Thanks !