Skip to content

Commit aa67a42

Browse files
committed
no to deploy in prod, investigate spring local invoker service context corruption
1 parent 62d3a65 commit aa67a42

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

core/src/main/java/jeeves/server/context/ServiceContext.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ public class ServiceContext extends BasicContext {
6767
private JeevesServlet _servlet;
6868
private boolean _startupError = false;
6969
private Map<String, String> _startupErrors;
70+
71+
public static InheritableThreadLocal<Broken> broken = new InheritableThreadLocal<Broken>();
72+
73+
public static class Broken {
74+
public ServiceContext corrupted;
75+
public StackTraceElement callingFrame;
76+
77+
public Broken setBroken(ServiceContext srvContext) {
78+
this.corrupted = srvContext;
79+
return this;
80+
}
81+
}
7082
/**
7183
* Property to be able to add custom response headers depending on the code (and not the xml of
7284
* Jeeves)
@@ -96,6 +108,7 @@ public ServiceContext(final String service, final ConfigurableApplicationContext
96108
setResponseHeaders(new HashMap<String, String>());
97109
}
98110

111+
99112
/**
100113
* ServiceManager sets the service context thread local when dispatch is called. this method
101114
* will return null or the service context
@@ -104,6 +117,9 @@ public ServiceContext(final String service, final ConfigurableApplicationContext
104117
*/
105118
@CheckForNull
106119
public static ServiceContext get() {
120+
if (broken.get() != null && broken.get().corrupted != null) {
121+
new Throwable("someone use a corrupted context").printStackTrace(System.err);
122+
}
107123
return THREAD_LOCAL_INSTANCE.get();
108124
}
109125

core/src/main/java/jeeves/xlink/Processor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private static Element resolveXLink(String uri, String idSearch, ServiceContext
186186
if (uri.startsWith(XLink.LOCAL_PROTOCOL)) {
187187
SpringLocalServiceInvoker springLocalServiceInvoker = srvContext.getBean(SpringLocalServiceInvoker.class);
188188
remoteFragment = (Element)springLocalServiceInvoker.invoke(uri);
189-
srvContext.setAsThreadLocal();
189+
ServiceContext.broken.set(new ServiceContext.Broken().setBroken(srvContext));
190190
} else {
191191
// Avoid references to filesystem
192192
if (uri.toLowerCase().startsWith("file://")) {

0 commit comments

Comments
 (0)