Decouple RestfulService and ServerConformanceProvider to avoid cycle in

Spring wiring
This commit is contained in:
bdenton 2015-07-31 13:33:30 -07:00 committed by jamesagnew
parent ab2129d651
commit daedf63c46
5 changed files with 66 additions and 3 deletions

View File

@ -33,4 +33,12 @@ public interface IServerConformanceProvider<T extends IBaseResource> {
*/
public abstract T getServerConformance(HttpServletRequest theRequest);
/**
* This setter is needed in implementation classes (along with
* a no-arg constructor) to avoid reference cycles in the
* Spring wiring of a RestfulServer instance.
*
* @param theRestfulServer
*/
public void setRestfulServer (RestfulServer theRestfulServer);
}

View File

@ -1086,6 +1086,19 @@ public class RestfulServer extends HttpServlet {
if (myStarted) {
throw new IllegalStateException("Server is already started");
}
// call the setRestfulServer() method to point the Conformance
// Provider to this server instance. This is done to avoid
// passing the server into the constructor. Having that sort
// of cross linkage causes reference cycles in Spring wiring
try {
Method setRestfulServer = theServerConformanceProvider.getClass().getMethod("setRestfulServer", new Class[]{RestfulServer.class});
if (setRestfulServer != null) {
setRestfulServer.invoke(theServerConformanceProvider, new Object[]{this});
}
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
ourLog.warn("Error calling IServerConformanceProvider.setRestfulServer", e);
}
myServerConformanceProvider = theServerConformanceProvider;
}

View File

@ -77,11 +77,25 @@ public class ServerConformanceProvider implements IServerConformanceProvider<Con
private boolean myCache = true;
private volatile Conformance myConformance;
private String myPublisher = "Not provided";
private final RestfulServer myRestfulServer;
private RestfulServer myRestfulServer;
public ServerConformanceProvider(RestfulServer theRestfulServer) {
myRestfulServer = theRestfulServer;
}
/*
* Add a no-arg constructor and seetter so that the
* ServerConfirmanceProvider can be Spring-wired with
* the RestfulService avoiding the potential reference
* cycle that would happen.
*/
public ServerConformanceProvider () {
super();
}
public void setRestfulServer (RestfulServer theRestfulServer) {
myRestfulServer = theRestfulServer;
}
/**
* Gets the value of the "publisher" that will be placed in the generated conformance statement. As this

View File

@ -93,11 +93,25 @@ public class ServerConformanceProvider implements IServerConformanceProvider<Con
private IdentityHashMap<OperationMethodBinding, String> myOperationBindingToName;
private HashMap<String, List<OperationMethodBinding>> myOperationNameToBindings;
private String myPublisher = "Not provided";
private final RestfulServer myRestfulServer;
private RestfulServer myRestfulServer;
public ServerConformanceProvider(RestfulServer theRestfulServer) {
myRestfulServer = theRestfulServer;
}
/*
* Add a no-arg constructor and seetter so that the
* ServerConfirmanceProvider can be Spring-wired with
* the RestfulService avoiding the potential reference
* cycle that would happen.
*/
public ServerConformanceProvider () {
super();
}
public void setRestfulServer (RestfulServer theRestfulServer) {
myRestfulServer = theRestfulServer;
}
private void checkBindingForSystemOps(Rest rest, Set<SystemRestfulInteractionEnum> systemOps, BaseMethodBinding<?> nextMethodBinding) {
if (nextMethodBinding.getSystemOperationType() != null) {

View File

@ -94,11 +94,25 @@ public class ServerConformanceProvider implements IServerConformanceProvider<Con
private IdentityHashMap<OperationMethodBinding, String> myOperationBindingToName;
private HashMap<String, List<OperationMethodBinding>> myOperationNameToBindings;
private String myPublisher = "Not provided";
private final RestfulServer myRestfulServer;
private RestfulServer myRestfulServer;
public ServerConformanceProvider(RestfulServer theRestfulServer) {
myRestfulServer = theRestfulServer;
}
/*
* Add a no-arg constructor and seetter so that the
* ServerConfirmanceProvider can be Spring-wired with
* the RestfulService avoiding the potential reference
* cycle that would happen.
*/
public ServerConformanceProvider () {
super();
}
public void setRestfulServer (RestfulServer theRestfulServer) {
myRestfulServer = theRestfulServer;
}
private void checkBindingForSystemOps(ConformanceRestComponent rest, Set<SystemRestfulInteraction> systemOps, BaseMethodBinding<?> nextMethodBinding) {
if (nextMethodBinding.getSystemOperationType() != null) {