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

Commit 85826a9

Browse files
Michal GajdosGerrit Code Review
authored andcommitted
Merge "Jersey server-side request routing refactoring."
2 parents df9cdeb + e0c725b commit 85826a9

31 files changed

+813
-1007
lines changed

core-server/src/main/java/org/glassfish/jersey/server/ApplicationHandler.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
import org.glassfish.jersey.model.internal.RankedComparator;
9797
import org.glassfish.jersey.model.internal.RankedComparator.Order;
9898
import org.glassfish.jersey.model.internal.RankedProvider;
99+
import org.glassfish.jersey.process.internal.ChainableStage;
99100
import org.glassfish.jersey.process.internal.Stage;
100101
import org.glassfish.jersey.process.internal.Stages;
101102
import org.glassfish.jersey.server.internal.ConfigHelper;
@@ -108,15 +109,11 @@
108109
import org.glassfish.jersey.server.internal.monitoring.MonitoringContainerListener;
109110
import org.glassfish.jersey.server.internal.process.ReferencesInitializer;
110111
import org.glassfish.jersey.server.internal.process.RequestProcessingContext;
111-
import org.glassfish.jersey.server.internal.routing.RoutedInflectorExtractorStage;
112-
import org.glassfish.jersey.server.internal.routing.Router;
113-
import org.glassfish.jersey.server.internal.routing.RoutingStage;
114-
import org.glassfish.jersey.server.internal.routing.RuntimeModelBuilder;
112+
import org.glassfish.jersey.server.internal.routing.Routing;
115113
import org.glassfish.jersey.server.model.ComponentModelValidator;
116114
import org.glassfish.jersey.server.model.ModelProcessor;
117115
import org.glassfish.jersey.server.model.ModelValidationException;
118116
import org.glassfish.jersey.server.model.Resource;
119-
import org.glassfish.jersey.server.model.ResourceMethodInvoker;
120117
import org.glassfish.jersey.server.model.ResourceModel;
121118
import org.glassfish.jersey.server.model.internal.ModelErrors;
122119
import org.glassfish.jersey.server.monitoring.ApplicationEvent;
@@ -162,7 +159,6 @@
162159
* @author Jakub Podlesak (jakub.podlesak at oracle.com)
163160
* @author Marek Potociar (marek.potociar at oracle.com)
164161
* @author Libor Kramolis (libor.kramolis at oracle.com)
165-
*
166162
* @see ResourceConfig
167163
* @see javax.ws.rs.core.Configuration
168164
* @see org.glassfish.jersey.server.spi.ContainerProvider
@@ -446,7 +442,9 @@ private void initialize() {
446442

447443
if (extScopes.length == 1) {
448444
for (final ComponentProvider p : componentProviders) {
449-
if (p.bind(extScopes[0], new HashSet<Class<?>>(){{add(ExternalRequestScope.class);}})) {
445+
if (p.bind(extScopes[0], new HashSet<Class<?>>() {{
446+
add(ExternalRequestScope.class);
447+
}})) {
450448
extScopesFound = true;
451449
break;
452450
}
@@ -463,7 +461,7 @@ private void initialize() {
463461

464462
if (!extScopesFound) {
465463
final DynamicConfiguration configuration = Injections.getConfiguration(locator);
466-
final ScopedBindingBuilder<ExternalRequestScope> binder = Injections.newBinder((ExternalRequestScope)ServerRuntime.NOOP_EXTERNAL_REQ_SCOPE).to(ExternalRequestScope.class);
464+
final ScopedBindingBuilder<ExternalRequestScope> binder = Injections.newBinder((ExternalRequestScope) ServerRuntime.NOOP_EXTERNAL_REQ_SCOPE).to(ExternalRequestScope.class);
467465
Injections.addBinding(binder, configuration);
468466
configuration.commit();
469467
}
@@ -474,7 +472,7 @@ private void initialize() {
474472
}
475473

476474
final Iterable<ApplicationEventListener> appEventListeners = Providers.getAllProviders(locator,
477-
ApplicationEventListener.class, new RankedComparator<ApplicationEventListener>());
475+
ApplicationEventListener.class, new RankedComparator<ApplicationEventListener>());
478476

479477
if (appEventListeners.iterator().hasNext()) {
480478
compositeListener = new CompositeApplicationEventListener(appEventListeners);
@@ -520,25 +518,20 @@ private void initialize() {
520518

521519
msgBodyWorkers = locator.getService(MessageBodyWorkers.class);
522520

523-
final RuntimeModelBuilder runtimeModelBuilder = new RuntimeModelBuilder(locator, runtimeConfig, msgBodyWorkers,
524-
locator.getService(ResourceMethodInvoker.Builder.class));
525-
runtimeModelBuilder.setProcessingProviders(processingProviders);
526-
527521
// assembly request processing chain
528-
/**
529-
* Root hierarchical request matching acceptor.
530-
* Invoked in a single linear stage as part of the main linear accepting chain.
531-
*/
532-
final Router resourceRoutingRoot = runtimeModelBuilder.buildModel(resourceModel.getRuntimeResourceModel(), false);
533-
534522
final ReferencesInitializer referencesInitializer = locator.createAndInitialize(ReferencesInitializer.class);
535523
final ContainerFilteringStage preMatchRequestFilteringStage = new ContainerFilteringStage(
536524
processingProviders.getPreMatchFilters(),
537525
processingProviders.getGlobalResponseFilters());
538-
final RoutingStage routingStage = new RoutingStage(resourceRoutingRoot);
539-
final ContainerFilteringStage resourceFilteringStage = new ContainerFilteringStage(
540-
processingProviders.getGlobalRequestFilters(), null);
541-
final RoutedInflectorExtractorStage routedInflectorExtractorStage = new RoutedInflectorExtractorStage();
526+
final ChainableStage<RequestProcessingContext> routingStage = Routing.forModel(resourceModel.getRuntimeResourceModel())
527+
.locator(locator)
528+
.resourceContext(jerseyResourceContext)
529+
.configuration(runtimeConfig)
530+
.entityProviders(msgBodyWorkers)
531+
.processingProviders(processingProviders)
532+
.buildStage();
533+
final ContainerFilteringStage resourceFilteringStage =
534+
new ContainerFilteringStage(processingProviders.getGlobalRequestFilters(), null);
542535
/**
543536
* Root linear request acceptor. This is the main entry point for the whole request processing.
544537
*/
@@ -547,7 +540,7 @@ private void initialize() {
547540
.to(preMatchRequestFilteringStage)
548541
.to(routingStage)
549542
.to(resourceFilteringStage)
550-
.build(routedInflectorExtractorStage);
543+
.build(Routing.matchedEndpointExtractor());
551544
this.runtime = locator.createAndInitialize(ServerRuntime.Builder.class)
552545
.build(rootStage, compositeListener, processingProviders);
553546

core-server/src/main/java/org/glassfish/jersey/server/ContainerRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -366,7 +366,7 @@ Iterable<WriterInterceptor> getWriterInterceptors() {
366366
}
367367

368368
private Inflector<RequestProcessingContext, ContainerResponse> getInflector() {
369-
return uriRoutingContext.getInflector();
369+
return uriRoutingContext.getEndpoint();
370370
}
371371

372372
private static <T> Iterable<T> emptyIfNull(Iterable<T> iterable) {

core-server/src/main/java/org/glassfish/jersey/server/internal/routing/AbstractRouteToPathBuilder.java

Lines changed: 0 additions & 162 deletions
This file was deleted.
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -55,7 +55,7 @@
5555
* @author Jakub Podlesak
5656
* @author Miroslav Fuksa (miroslav.fuksa at oracle.com)
5757
*/
58-
class CombinedClientServerMediaType {
58+
final class CombinedMediaType {
5959

6060
private static int wildcardsMatched(MediaType clientMt, EffectiveMediaType serverMt) {
6161
return b2i(clientMt.isWildcardType() ^ serverMt.isWildcardType())
@@ -71,10 +71,12 @@ private static int m2i(MediaType mt) {
7171
}
7272

7373
private MediaType combinedMediaType;
74-
private int q, qs, d;
75-
private static final CombinedClientServerMediaType NO_MATCH = new CombinedClientServerMediaType();
74+
private int q;
75+
private int qs;
76+
private int d;
77+
private static final CombinedMediaType NO_MATCH = new CombinedMediaType();
7678

77-
private CombinedClientServerMediaType() {
79+
private CombinedMediaType() {
7880
}
7981

8082
/**
@@ -84,12 +86,12 @@ private CombinedClientServerMediaType() {
8486
* @param serverMt server-side media type.
8587
* @return combined client/server media type.
8688
*/
87-
public static CombinedClientServerMediaType create(MediaType clientMt, EffectiveMediaType serverMt) {
89+
public static CombinedMediaType create(MediaType clientMt, EffectiveMediaType serverMt) {
8890
if (!clientMt.isCompatible(serverMt.getMediaType())) {
8991
return NO_MATCH;
9092
}
9193

92-
CombinedClientServerMediaType result = new CombinedClientServerMediaType();
94+
CombinedMediaType result = new CombinedMediaType();
9395

9496
result.combinedMediaType = MediaTypes.stripQualityParams(MediaTypes.mostSpecific(clientMt, serverMt.getMediaType()));
9597
result.d = wildcardsMatched(clientMt, serverMt);
@@ -108,13 +110,13 @@ public int compare(MediaType o1, MediaType o2) {
108110

109111

110112
/**
111-
* Comparator used to compare {@link CombinedClientServerMediaType}. The comparator sorts the elements of list
113+
* Comparator used to compare {@link CombinedMediaType}. The comparator sorts the elements of list
112114
* in the ascending order from the least appropriate to the most appropriate {@link MediaType media type}.
113115
*/
114-
final static Comparator<CombinedClientServerMediaType> COMPARATOR = new Comparator<CombinedClientServerMediaType>() {
116+
final static Comparator<CombinedMediaType> COMPARATOR = new Comparator<CombinedMediaType>() {
115117

116118
@Override
117-
public int compare(CombinedClientServerMediaType c1, CombinedClientServerMediaType c2) {
119+
public int compare(CombinedMediaType c1, CombinedMediaType c2) {
118120
int partialComparison = partialOrderComparator.compare(c1.combinedMediaType, c2.combinedMediaType);
119121

120122
if (partialComparison > 0) {
@@ -257,10 +259,7 @@ public boolean equals(Object o) {
257259

258260
EffectiveMediaType that = (EffectiveMediaType) o;
259261

260-
if (derived != that.derived) return false;
261-
if (!mediaType.equals(that.mediaType)) return false;
262-
263-
return true;
262+
return derived == that.derived && mediaType.equals(that.mediaType);
264263
}
265264

266265
@Override
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@
4242
import org.glassfish.jersey.server.model.ResourceModel;
4343

4444
/**
45-
* A pair of resource model (for sub-resource locators) and a corresponding model router.
45+
* A pair of sub-resource locator model and a corresponding model router.
4646
*
4747
* @author Michal Gajdos (michal.gajdos at oracle.com)
4848
*/
49-
final class LocatorAcceptorPair {
49+
final class LocatorRouting {
5050

5151
/**
5252
* Sub-resource locator model.
5353
*/
54-
final ResourceModel model;
54+
final ResourceModel locator;
5555

5656
/**
5757
* Sub-resource locator router.
@@ -61,11 +61,11 @@ final class LocatorAcceptorPair {
6161
/**
6262
* Create a new instance.
6363
*
64-
* @param model sub-resource locator model.
64+
* @param locator sub-resource locator model.
6565
* @param router router that is needed to execute the {@code model}.
6666
*/
67-
LocatorAcceptorPair(final ResourceModel model, final Router router) {
68-
this.model = model;
67+
LocatorRouting(final ResourceModel locator, final Router router) {
68+
this.locator = locator;
6969
this.router = router;
7070
}
7171
}

0 commit comments

Comments
 (0)