Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 9a62161

Browse files
author
Marek Potociar
committed
Message ctx. cleanup and server container SPI update.
- Cleaned up code that initializes reader interceptors in InboundMessageContext. - Exposed ApplicationHandler via Container SPI. Change-Id: I2c9689efc72aa1996b103101e56214567e87a794 Signed-off-by: Marek Potociar <[email protected]>
1 parent 5186ca4 commit 9a62161

File tree

17 files changed

+196
-164
lines changed

17 files changed

+196
-164
lines changed

containers/grizzly2-http/src/main/java/org/glassfish/jersey/grizzly2/httpserver/GrizzlyHttpContainer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ public void reload(ResourceConfig configuration) {
388388
cacheConfigSetStatusOverSendError();
389389
}
390390

391+
@Override
392+
public ApplicationHandler getApplicationHandler() {
393+
return appHandler;
394+
}
395+
391396
@Override
392397
public void destroy() {
393398
super.destroy();

containers/jdk-http/src/main/java/org/glassfish/jersey/jdkhttp/JdkHttpHandlerContainer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ public void reload(ResourceConfig configuration) {
214214
containerListener.onStartup(this);
215215
}
216216

217+
@Override
218+
public ApplicationHandler getApplicationHandler() {
219+
return appHandler;
220+
}
221+
217222
/**
218223
* Inform this container that the server has been started.
219224
*

containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/ServletContainer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
import org.glassfish.jersey.internal.util.ExtendedLogger;
6666
import org.glassfish.jersey.internal.util.collection.Value;
67+
import org.glassfish.jersey.server.ApplicationHandler;
6768
import org.glassfish.jersey.server.ContainerException;
6869
import org.glassfish.jersey.server.ResourceConfig;
6970
import org.glassfish.jersey.server.ServerProperties;
@@ -583,4 +584,9 @@ public void reload(ResourceConfig configuration) {
583584
logger.log(Level.SEVERE, "Reload failed", ex);
584585
}
585586
}
587+
588+
@Override
589+
public ApplicationHandler getApplicationHandler() {
590+
return webComponent.appHandler;
591+
}
586592
}

containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ public void reload(ResourceConfig configuration) {
398398
cacheConfigSetStatusOverSendError();
399399
}
400400

401+
@Override
402+
public ApplicationHandler getApplicationHandler() {
403+
return appHandler;
404+
}
405+
401406
/**
402407
* Inform this container that the server has been started.
403408
*

containers/simple-http/src/main/java/org/glassfish/jersey/simple/SimpleContainer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ public void reload(ResourceConfig configuration) {
331331
containerListener.onStartup(this);
332332
}
333333

334+
@Override
335+
public ApplicationHandler getApplicationHandler() {
336+
return appHandler;
337+
}
338+
334339
/**
335340
* Inform this container that the server has been started.
336341
*

core-client/src/main/java/org/glassfish/jersey/client/ClientResponse.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161

6262
import org.glassfish.jersey.client.internal.LocalizationMessages;
6363
import org.glassfish.jersey.internal.inject.ServiceLocatorSupplier;
64-
import org.glassfish.jersey.internal.util.collection.Value;
6564
import org.glassfish.jersey.message.internal.InboundMessageContext;
6665
import org.glassfish.jersey.message.internal.OutboundJaxrsResponse;
6766
import org.glassfish.jersey.message.internal.Statuses;
@@ -152,14 +151,6 @@ public ClientResponse(Response.StatusType status, ClientRequest requestContext,
152151
this.requestContext = requestContext;
153152

154153
setWorkers(requestContext.getWorkers());
155-
156-
final Iterable<ReaderInterceptor> readerInterceptors = requestContext.getReaderInterceptors();
157-
setReaderInterceptors(new Value<Iterable<ReaderInterceptor>>() {
158-
@Override
159-
public Iterable<ReaderInterceptor> get() {
160-
return readerInterceptors;
161-
}
162-
});
163154
}
164155

165156
@Override
@@ -467,4 +458,9 @@ public <T> T readEntity(GenericType<T> entityType, Annotation[] annotations)
467458
public ServiceLocator getServiceLocator() {
468459
return getRequestContext().getServiceLocator();
469460
}
461+
462+
@Override
463+
protected Iterable<ReaderInterceptor> getReaderInterceptors() {
464+
return requestContext.getReaderInterceptors();
465+
}
470466
}

core-common/src/main/java/org/glassfish/jersey/message/internal/InboundMessageContext.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575

7676
import org.glassfish.jersey.internal.LocalizationMessages;
7777
import org.glassfish.jersey.internal.PropertiesDelegate;
78-
import org.glassfish.jersey.internal.util.collection.Value;
7978
import org.glassfish.jersey.message.MessageBodyWorkers;
8079

8180
import jersey.repackaged.com.google.common.base.Function;
@@ -85,7 +84,7 @@
8584
*
8685
* @author Marek Potociar (marek.potociar at oracle.com)
8786
*/
88-
public class InboundMessageContext {
87+
public abstract class InboundMessageContext {
8988
private static final InputStream EMPTY = new InputStream() {
9089

9190
@Override
@@ -114,7 +113,6 @@ public boolean markSupported() {
114113
private final EntityContent entityContent;
115114
private final boolean translateNce;
116115
private MessageBodyWorkers workers;
117-
private Value<Iterable<ReaderInterceptor>> readerInterceptors;
118116

119117
/**
120118
* Input stream and its state. State is represented by the {@link Type Type enum} and
@@ -858,7 +856,7 @@ public <T> T readEntity(Class<T> rawType, Type type, Annotation[] annotations, P
858856
headers,
859857
propertiesDelegate,
860858
entityContent.getWrappedStream(),
861-
entityContent.hasContent() ? readerInterceptors.get() : Collections.<ReaderInterceptor>emptyList(),
859+
entityContent.hasContent() ? getReaderInterceptors() : Collections.<ReaderInterceptor>emptyList(),
862860
translateNce);
863861

864862
shouldClose = shouldClose && !(t instanceof Closeable) && !(t instanceof Source);
@@ -912,11 +910,12 @@ public void close() {
912910
}
913911

914912
/**
915-
* Set reader interceptors for reading entity from this context.
913+
* Get reader interceptors bound to this context.
914+
* <p>
915+
* Interceptors will be used when one of the {@code readEntity} methods is invoked.
916+
* </p>
916917
*
917-
* @param readerInterceptors A value that returns reader interceptors in the interceptor execution order.
918+
* @return reader interceptors bound to this context.
918919
*/
919-
public void setReaderInterceptors(Value<Iterable<ReaderInterceptor>> readerInterceptors) {
920-
this.readerInterceptors = readerInterceptors;
921-
}
920+
protected abstract Iterable<ReaderInterceptor> getReaderInterceptors();
922921
}

core-common/src/test/java/org/glassfish/jersey/message/internal/InboundMessageContextTest.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@
4343
import java.net.URISyntaxException;
4444
import java.text.ParseException;
4545
import java.text.SimpleDateFormat;
46+
import java.util.Collections;
4647
import java.util.Date;
4748
import java.util.Locale;
4849
import java.util.Set;
4950

5051
import javax.ws.rs.core.EntityTag;
5152
import javax.ws.rs.core.HttpHeaders;
5253
import javax.ws.rs.core.Link;
54+
import javax.ws.rs.ext.ReaderInterceptor;
5355
import javax.ws.rs.ext.RuntimeDelegate;
5456

5557
import org.glassfish.jersey.internal.TestRuntimeDelegate;
@@ -71,15 +73,24 @@ public InboundMessageContextTest() {
7173
RuntimeDelegate.setInstance(new TestRuntimeDelegate());
7274
}
7375

76+
private static InboundMessageContext createInboundMessageContext() {
77+
return new InboundMessageContext() {
78+
@Override
79+
protected Iterable<ReaderInterceptor> getReaderInterceptors() {
80+
return Collections.emptyList();
81+
}
82+
};
83+
}
84+
7485
@Test
7586
public void testNoLength() {
76-
InboundMessageContext r = new InboundMessageContext();
87+
InboundMessageContext r = createInboundMessageContext();
7788
assertEquals(-1, r.getLength());
7889
}
7990

8091
@Test
8192
public void testRequestCookies() throws URISyntaxException {
82-
InboundMessageContext r = new InboundMessageContext();
93+
InboundMessageContext r = createInboundMessageContext();
8394
r.header(HttpHeaders.COOKIE, "oreo=chocolate");
8495
r.header(HttpHeaders.COOKIE, "nilla=vanilla");
8596
assertEquals(r.getRequestCookies().size(), 2);
@@ -92,7 +103,7 @@ public void testRequestCookies() throws URISyntaxException {
92103

93104
@Test
94105
public void testDate() throws URISyntaxException, ParseException {
95-
InboundMessageContext r = new InboundMessageContext();
106+
InboundMessageContext r = createInboundMessageContext();
96107
r.header(HttpHeaders.DATE, "Tue, 29 Jan 2002 22:14:02 -0500");
97108
SimpleDateFormat f = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
98109
Date date = f.parse("Tue, 29 Jan 2002 22:14:02 -0500");
@@ -101,7 +112,7 @@ public void testDate() throws URISyntaxException, ParseException {
101112

102113
@Test
103114
public void testHeader() throws URISyntaxException, ParseException {
104-
InboundMessageContext r = new InboundMessageContext();
115+
InboundMessageContext r = createInboundMessageContext();
105116
r.header(HttpHeaders.ACCEPT, "application/xml, text/plain");
106117
r.header(HttpHeaders.ACCEPT, "application/json");
107118
r.header("FOO", "");
@@ -114,7 +125,7 @@ public void testHeader() throws URISyntaxException, ParseException {
114125

115126
@Test
116127
public void testHeaderMap() throws URISyntaxException, ParseException {
117-
InboundMessageContext r = new InboundMessageContext();
128+
InboundMessageContext r = createInboundMessageContext();
118129
r.header(HttpHeaders.ACCEPT, "application/xml, text/plain");
119130
r.header(HttpHeaders.ACCEPT, "application/json");
120131
r.header("Allow", "GET, PUT");
@@ -127,7 +138,7 @@ public void testHeaderMap() throws URISyntaxException, ParseException {
127138

128139
@Test
129140
public void testAllowedMethods() throws URISyntaxException {
130-
InboundMessageContext r = new InboundMessageContext();
141+
InboundMessageContext r = createInboundMessageContext();
131142
r.header("Allow", "GET, PUT");
132143
r.header("Allow", "POST");
133144
assertEquals(3, r.getAllowedMethods().size());
@@ -139,7 +150,7 @@ public void testAllowedMethods() throws URISyntaxException {
139150

140151
@Test
141152
public void testResponseCookies() throws URISyntaxException {
142-
InboundMessageContext r = new InboundMessageContext();
153+
InboundMessageContext r = createInboundMessageContext();
143154
r.header(HttpHeaders.SET_COOKIE, "oreo=chocolate");
144155
r.header(HttpHeaders.SET_COOKIE, "nilla=vanilla");
145156
assertEquals(2, r.getResponseCookies().size());
@@ -149,14 +160,14 @@ public void testResponseCookies() throws URISyntaxException {
149160

150161
@Test
151162
public void testEntityTag() throws URISyntaxException {
152-
InboundMessageContext r = new InboundMessageContext();
163+
InboundMessageContext r = createInboundMessageContext();
153164
r.header(HttpHeaders.ETAG, "\"tag\"");
154165
assertEquals(EntityTag.valueOf("\"tag\""), r.getEntityTag());
155166
}
156167

157168
@Test
158169
public void testLastModified() throws URISyntaxException, ParseException {
159-
InboundMessageContext r = new InboundMessageContext();
170+
InboundMessageContext r = createInboundMessageContext();
160171
r.header(HttpHeaders.LAST_MODIFIED, "Tue, 29 Jan 2002 22:14:02 -0500");
161172
SimpleDateFormat f = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
162173
Date date = f.parse("Tue, 29 Jan 2002 22:14:02 -0500");
@@ -165,14 +176,14 @@ public void testLastModified() throws URISyntaxException, ParseException {
165176

166177
@Test
167178
public void testLocation() throws URISyntaxException {
168-
InboundMessageContext r = new InboundMessageContext();
179+
InboundMessageContext r = createInboundMessageContext();
169180
r.header(HttpHeaders.LOCATION, "http://example.org/app");
170181
assertEquals(URI.create("http://example.org/app"), r.getLocation());
171182
}
172183

173184
@Test
174185
public void testGetLinks() {
175-
InboundMessageContext r = new InboundMessageContext();
186+
InboundMessageContext r = createInboundMessageContext();
176187
Link link1 = Link.fromUri("http://example.org/app/link1").param("produces", "application/json").param("method",
177188
"GET").rel("self").build();
178189
Link link2 = Link.fromUri("http://example.org/app/link2").param("produces", "application/xml").param("method",
@@ -186,7 +197,7 @@ public void testGetLinks() {
186197

187198
@Test
188199
public void testGetLink() {
189-
InboundMessageContext r = new InboundMessageContext();
200+
InboundMessageContext r = createInboundMessageContext();
190201
Link link1 = Link.fromUri("http://example.org/app/link1").param("produces", "application/json").param("method",
191202
"GET").rel("self").build();
192203
Link link2 = Link.fromUri("http://example.org/app/link2").param("produces", "application/xml").param("method",
@@ -203,7 +214,7 @@ public void testGetLink() {
203214

204215
@Test
205216
public void testGetAllowedMethods() {
206-
InboundMessageContext r = new InboundMessageContext();
217+
InboundMessageContext r = createInboundMessageContext();
207218
r.header(HttpHeaders.ALLOW, "a,B,CcC,dDd");
208219
final Set<String> allowedMethods = r.getAllowedMethods();
209220
assertEquals(4, allowedMethods.size());

0 commit comments

Comments
 (0)