Skip to content

Commit 9ab8439

Browse files
author
Marek Potociar
committed
Resolved issue JERSEY-1482.
- added support for disabling resource model validation (root and sub resources) - added support for disabling deployment failure on invalid resource model. - added new unit test to cover this. Extras: - configuration property renames to fit a common scheme. - updated javadoc of some properties. Change-Id: Ie958f0eab2a1782d765caa53cb0cce3e9d829905
1 parent 4754ecf commit 9ab8439

File tree

49 files changed

+476
-266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+476
-266
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private ClientRuntime initRuntime() {
353353

354354
// AutoDiscoverable.
355355
if (!PropertiesHelper.getValue(runtimeConfig.getProperties(), RuntimeType.CLIENT,
356-
CommonProperties.FEATURE_DISABLE_AUTO_DISCOVERY, Boolean.FALSE, Boolean.class)) {
356+
CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, Boolean.FALSE, Boolean.class)) {
357357
runtimeConfig.configureAutoDiscoverableProviders(locator);
358358
}
359359

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public final class ClientProperties {
164164
* If {@code true} then disable auto-discovery on the client.
165165
* <p>
166166
* By default auto-discovery on client is automatically enabled if global property
167-
* {@value org.glassfish.jersey.CommonProperties#FEATURE_DISABLE_AUTO_DISCOVERY} is not disabled. If set then the client
167+
* {@value org.glassfish.jersey.CommonProperties#FEATURE_AUTO_DISCOVERY_DISABLE} is not disabled. If set then the client
168168
* property value overrides the global property value.
169169
* <p>
170170
* The default value is {@code false}.
@@ -173,15 +173,15 @@ public final class ClientProperties {
173173
* The name of the configuration property is <tt>{@value}</tt>.
174174
* </p>
175175
*
176-
* @see org.glassfish.jersey.CommonProperties#FEATURE_DISABLE_AUTO_DISCOVERY
176+
* @see org.glassfish.jersey.CommonProperties#FEATURE_AUTO_DISCOVERY_DISABLE
177177
*/
178-
public static final String FEATURE_DISABLE_AUTO_DISCOVERY = CommonProperties.FEATURE_DISABLE_AUTO_DISCOVERY + ".client";
178+
public static final String FEATURE_AUTO_DISCOVERY_DISABLE = CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE + ".client";
179179

180180
/**
181181
* If {@code true} then disable registration of Json Processing (JSR-353) feature on client.
182182
* <p>
183183
* By default Json Processing on client is automatically enabled if global property
184-
* {@value org.glassfish.jersey.CommonProperties#FEATURE_DISABLE_JSON_PROCESSING} is not disabled. If set then the client
184+
* {@value org.glassfish.jersey.CommonProperties#JSON_PROCESSING_FEATURE_DISABLE} is not disabled. If set then the client
185185
* property value overrides the global property value.
186186
* <p>
187187
* The default value is {@code false}.
@@ -190,9 +190,9 @@ public final class ClientProperties {
190190
* The name of the configuration property is <tt>{@value}</tt>.
191191
* </p>
192192
*
193-
* @see org.glassfish.jersey.CommonProperties#FEATURE_DISABLE_JSON_PROCESSING
193+
* @see org.glassfish.jersey.CommonProperties#JSON_PROCESSING_FEATURE_DISABLE
194194
*/
195-
public static final String FEATURE_DISABLE_JSON_PROCESSING = CommonProperties.FEATURE_DISABLE_JSON_PROCESSING + ".client";
195+
public static final String JSON_PROCESSING_FEATURE_DISABLE = CommonProperties.JSON_PROCESSING_FEATURE_DISABLE + ".client";
196196

197197
private ClientProperties() {
198198
// prevents instantiation

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void setAsynchronous(boolean async) {
397397
/**
398398
* Enable a buffering of serialized entity. The buffering will be configured from runtime configuration
399399
* associated with this request. The property determining the size of the buffer
400-
* is {@link org.glassfish.jersey.CommonProperties#CONTENT_LENGTH_BUFFER}.
400+
* is {@link org.glassfish.jersey.CommonProperties#OUTBOUND_CONTENT_LENGTH_BUFFER}.
401401
* <p/>
402402
* The buffering functionality is by default disabled and could be enabled by calling this method. In this case
403403
* this method must be called before first bytes are written to the {@link #getEntityStream() entity stream}.

core-client/src/test/java/org/glassfish/jersey/client/AutoDiscoverableClientTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ private void _test(final String response, final Boolean globalDisable, final Boo
148148
config.property(PROPERTY, true);
149149

150150
if (globalDisable != null) {
151-
config.property(CommonProperties.FEATURE_DISABLE_AUTO_DISCOVERY, globalDisable);
151+
config.property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, globalDisable);
152152
}
153153
if (clientDisable != null) {
154-
config.property(ClientProperties.FEATURE_DISABLE_AUTO_DISCOVERY, clientDisable);
154+
config.property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, clientDisable);
155155
}
156156

157157
final Client client = ClientBuilder.newClient(config);

core-common/src/main/java/org/glassfish/jersey/CommonProperties.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
public final class CommonProperties {
4949

5050
/**
51-
* If {@code true} then disable auto discovery on client/server.
51+
* If {@code true} then disable feature auto discovery globally on client/server.
5252
* <p>
5353
* By default auto discovery is automatically enabled. The value of this property may be overridden by the client/server
5454
* variant of this property.
@@ -59,7 +59,7 @@ public final class CommonProperties {
5959
* The name of the configuration property is <tt>{@value}</tt>.
6060
* </p>
6161
*/
62-
public static final String FEATURE_DISABLE_AUTO_DISCOVERY = "jersey.config.disableAutoDiscovery";
62+
public static final String FEATURE_AUTO_DISCOVERY_DISABLE = "jersey.config.disableAutoDiscovery";
6363

6464
/**
6565
* If {@code true} then disable registration of Json Processing (JSR-353) feature.
@@ -73,26 +73,26 @@ public final class CommonProperties {
7373
* The name of the configuration property is <tt>{@value}</tt>.
7474
* </p>
7575
*/
76-
public static final String FEATURE_DISABLE_JSON_PROCESSING = "jersey.config.disableJsonProcessing";
76+
public static final String JSON_PROCESSING_FEATURE_DISABLE = "jersey.config.disableJsonProcessing";
7777

7878
/**
79-
* An integer value that defines the buffer size used to buffer the outbound response entity in order to
79+
* An integer value that defines the buffer size used to buffer the outbound message entity in order to
8080
* determine its size and set the value of HTTP <tt>{@value javax.ws.rs.core.HttpHeaders#CONTENT_LENGTH}</tt> header.
8181
* <p>
8282
* If the entity size exceeds the configured buffer size, the buffering would be cancelled and the entity size
8383
* would not be determined. Value less or equal to zero disable the buffering of the entity at all.
8484
* </p>
8585
* The value of this property may be overridden by the client/server variant of this property by defining the suffix
86-
* to this property "<code>.server</code>" or "<code>.client</code>"
87-
* (<tt>{@value}</tt><code>.server</code> or <tt>{@value}</tt><code>.client</code>).
86+
* to this property "<tt>.server</tt>" or "<tt>.client</tt>"
87+
* (<tt>{@value}.server</tt> or <tt>{@value}.client</tt>).
8888
* <p>
8989
* The default value is <tt>{@value org.glassfish.jersey.message.internal.CommittingOutputStream#DEFAULT_BUFFER_SIZE}</tt>.
9090
* </p>
9191
* <p>
9292
* The name of the configuration property is <tt>{@value}</tt>.
9393
* </p>
9494
*/
95-
public static final String CONTENT_LENGTH_BUFFER = "jersey.config.contentLength.buffer";
95+
public static final String OUTBOUND_CONTENT_LENGTH_BUFFER = "jersey.config.contentLength.buffer";
9696

9797
/**
9898
* Prevent instantiation.

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

+76-29
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@
3939
*/
4040
package org.glassfish.jersey.internal;
4141

42+
import java.util.ArrayDeque;
4243
import java.util.ArrayList;
44+
import java.util.Collection;
4345
import java.util.Collections;
46+
import java.util.Deque;
4447
import java.util.List;
4548
import java.util.concurrent.Callable;
4649
import java.util.logging.Logger;
@@ -117,36 +120,72 @@ public static void hint(final Object source, final String message) {
117120
getInstance().issues.add(new ErrorMessage(source, message, Severity.HINT));
118121
}
119122

120-
private static List<ErrorMessage> processErrors(final boolean throwException) {
121-
final List<ErrorMessage> messages = new ArrayList<ErrorMessage>(errors.get().issues);
123+
/**
124+
* Log errors and throw an exception if there are any fatal issues detected and
125+
* the {@code throwException} flag has been set to {@code true}.
126+
*
127+
* @param throwException if set to {@code true}, any fatal issues will cause a {@link ErrorMessagesException}
128+
* to be thrown.
129+
*/
130+
private static void processErrors(final boolean throwException) {
131+
final List<ErrorMessage> errors = new ArrayList<ErrorMessage>(Errors.errors.get().issues);
132+
boolean isFatal = logErrors(errors);
133+
if (throwException && isFatal) {
134+
throw new ErrorMessagesException(errors);
135+
}
136+
}
137+
138+
/**
139+
* Log errors and return a status flag indicating whether a fatal issue has been found
140+
* in the error collection.
141+
* <p>
142+
* The {@code afterMark} flag indicates whether only those issues should be logged that were
143+
* added after a {@link #mark() mark has been set}.
144+
* </p>
145+
*
146+
* @param afterMark if {@code true}, only issues added after a mark has been set are returned,
147+
* if {@code false} all issues are returned.
148+
* @return {@code true} if there are any fatal issues present in the collection, {@code false}
149+
* otherwise.
150+
*/
151+
public static boolean logErrors(final boolean afterMark) {
152+
return logErrors(getInstance()._getErrorMessages(afterMark));
153+
}
154+
155+
/**
156+
* Log supplied errors and return a status flag indicating whether a fatal issue has been found
157+
* in the error collection.
158+
*
159+
* @param errors a collection of errors to be logged.
160+
* @return {@code true} if there are any fatal issues present in the collection, {@code false}
161+
* otherwise.
162+
*/
163+
private static boolean logErrors(final Collection<ErrorMessage> errors) {
122164
boolean isFatal = false;
123165

124-
if (!messages.isEmpty()) {
125-
StringBuilder errors = new StringBuilder("\n");
166+
if (!errors.isEmpty()) {
167+
StringBuilder fatals = new StringBuilder("\n");
126168
StringBuilder warnings = new StringBuilder();
127169
StringBuilder hints = new StringBuilder();
128170

129-
for (final ErrorMessage issue : messages) {
130-
switch (issue.getSeverity()) {
171+
for (final ErrorMessage error : errors) {
172+
switch (error.getSeverity()) {
131173
case FATAL:
132174
isFatal = true;
133-
errors.append(LocalizationMessages.ERROR_MSG(issue.getMessage())).append('\n');
175+
fatals.append(LocalizationMessages.ERROR_MSG(error.getMessage())).append('\n');
134176
break;
135177
case WARNING:
136-
warnings.append(LocalizationMessages.WARNING_MSG(issue.getMessage())).append('\n');
178+
warnings.append(LocalizationMessages.WARNING_MSG(error.getMessage())).append('\n');
137179
break;
138180
case HINT:
139-
warnings.append(LocalizationMessages.HINT_MSG(issue.getMessage())).append('\n');
181+
warnings.append(LocalizationMessages.HINT_MSG(error.getMessage())).append('\n');
140182
break;
141183
}
142184
}
143185

144186
if (isFatal) {
145-
LOGGER.severe(LocalizationMessages.ERRORS_AND_WARNINGS_DETECTED(errors.append(warnings)
187+
LOGGER.severe(LocalizationMessages.ERRORS_AND_WARNINGS_DETECTED(fatals.append(warnings)
146188
.append(hints).toString()));
147-
if (throwException) {
148-
throw new ErrorMessagesException(messages);
149-
}
150189
} else {
151190
if (warnings.length() > 0) {
152191
LOGGER.warning(LocalizationMessages.WARNINGS_DETECTED(warnings.toString()));
@@ -158,9 +197,10 @@ private static List<ErrorMessage> processErrors(final boolean throwException) {
158197
}
159198
}
160199

161-
return messages;
200+
return isFatal;
162201
}
163202

203+
164204
/**
165205
* Check whether a fatal error is present in the list of all messages.
166206
*
@@ -310,9 +350,10 @@ public static List<ErrorMessage> getErrorMessages() {
310350

311351
/**
312352
* Get the list of error messages.
313-
* <p/>
353+
* <p>
314354
* The {@code afterMark} flag indicates whether only those issues should be returned that were
315355
* added after a {@link #mark() mark has been set}.
356+
* </p>
316357
*
317358
* @param afterMark if {@code true}, only issues added after a mark has been set are returned,
318359
* if {@code false} all issues are returned.
@@ -337,9 +378,8 @@ public static void unmark() {
337378
}
338379

339380
/**
340-
* Removes all issues that have been added since the last marked position.
341-
* <p/>
342-
* If no mark has been set in the errors list, the method call is ignored.
381+
* Removes all issues that have been added since the last marked position as well as
382+
* removes the last mark.
343383
*/
344384
public static void reset() {
345385
getInstance()._reset();
@@ -350,21 +390,23 @@ public static void reset() {
350390
private Errors() {
351391
}
352392

353-
private int mark = -1;
393+
private Deque<Integer> mark = new ArrayDeque<Integer>(4);
354394
private int stack = 0;
355395

356396
private void _mark() {
357-
mark = issues.size();
397+
mark.addLast(issues.size());
358398
}
359399

360400
private void _unmark() {
361-
mark = -1;
401+
mark.pollLast();
362402
}
363403

364404
private void _reset() {
365-
if (mark >= 0 && mark < issues.size()) {
366-
issues.subList(mark, issues.size()).clear();
367-
_unmark();
405+
final Integer _pos = mark.pollLast(); // also performs "unmark" functionality
406+
final int markedPos = (_pos == null) ? -1 : _pos;
407+
408+
if (markedPos >= 0 && markedPos < issues.size()) {
409+
issues.subList(markedPos, issues.size()).clear();
368410
}
369411
}
370412

@@ -387,11 +429,16 @@ private void postProcess(boolean throwException) {
387429
}
388430

389431
private List<ErrorMessage> _getErrorMessages(final boolean afterMark) {
390-
if (afterMark && mark >= 0 && mark < issues.size()) {
391-
return Collections.unmodifiableList(new ArrayList<ErrorMessage>(issues.subList(mark, issues.size())));
392-
} else {
393-
return Collections.unmodifiableList(new ArrayList<ErrorMessage>(issues));
432+
if (afterMark) {
433+
final Integer _pos = mark.peekLast();
434+
final int markedPos = (_pos == null) ? -1 : _pos;
435+
436+
if (markedPos >= 0 && markedPos < issues.size()) {
437+
return Collections.unmodifiableList(new ArrayList<ErrorMessage>(issues.subList(markedPos, issues.size())));
438+
} // else return all errors
394439
}
440+
441+
return Collections.unmodifiableList(new ArrayList<ErrorMessage>(issues));
395442
}
396443

397444
/**
@@ -433,7 +480,7 @@ private ErrorMessage(final Object source, final String message, Severity severit
433480
/**
434481
* Get {@link Severity}.
435482
*
436-
* @return severity of current {@link ErrorMessage}.
483+
* @return severity of current {@code ErrorMessage}.
437484
*/
438485
public Severity getSeverity() {
439486
return severity;

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

+17-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
* A base class for implementing JAXB-based readers and writers.
7474
*
7575
* @param <T> Java type supported by the provider.
76-
*
7776
* @author Paul Sandoz
7877
* @author Marek Potociar (marek.potociar at oracle.com)
7978
*/
@@ -163,7 +162,8 @@ protected final Unmarshaller getUnmarshaller(Class type, MediaType mt) throws JA
163162
}
164163
}
165164

166-
return getJAXBContext(type, mt).createUnmarshaller();
165+
final JAXBContext ctx = getJAXBContext(type, mt);
166+
return (ctx == null) ? null : ctx.createUnmarshaller();
167167
}
168168

169169
private Unmarshaller getUnmarshaller(Class type) throws JAXBException {
@@ -175,7 +175,8 @@ private Unmarshaller getUnmarshaller(Class type) throws JAXBException {
175175
}
176176
}
177177

178-
return getJAXBContext(type).createUnmarshaller();
178+
final JAXBContext ctx = getJAXBContext(type);
179+
return (ctx == null) ? null : ctx.createUnmarshaller();
179180
}
180181

181182
protected final Marshaller getMarshaller(Class type, MediaType mt) throws JAXBException {
@@ -191,7 +192,12 @@ protected final Marshaller getMarshaller(Class type, MediaType mt) throws JAXBEx
191192
}
192193
}
193194

194-
Marshaller m = getJAXBContext(type, mt).createMarshaller();
195+
final JAXBContext ctx = getJAXBContext(type, mt);
196+
if (ctx == null) {
197+
return null;
198+
}
199+
200+
Marshaller m = ctx.createMarshaller();
195201
if (formattedOutput.get()) {
196202
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formattedOutput.get());
197203
}
@@ -208,7 +214,12 @@ private Marshaller getMarshaller(Class type) throws JAXBException {
208214
}
209215
}
210216

211-
Marshaller m = getJAXBContext(type).createMarshaller();
217+
final JAXBContext ctx = getJAXBContext(type);
218+
if (ctx == null) {
219+
return null;
220+
}
221+
222+
Marshaller m = ctx.createMarshaller();
212223
if (formattedOutput.get()) {
213224
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formattedOutput.get());
214225
}
@@ -252,7 +263,7 @@ protected JAXBContext getStoredJaxbContext(Class type) throws JAXBException {
252263
}
253264

254265
protected static SAXSource getSAXSource(SAXParserFactory spf,
255-
InputStream entityStream) throws JAXBException {
266+
InputStream entityStream) throws JAXBException {
256267
try {
257268
return new SAXSource(
258269
spf.newSAXParser().getXMLReader(),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ public void setEntityStream(OutputStream outputStream) {
781781

782782
/**
783783
* Enable a buffering of serialized entity. The buffering will be configured from configuration. The property
784-
* determining the size of the buffer is {@link CommonProperties#CONTENT_LENGTH_BUFFER}.
784+
* determining the size of the buffer is {@link CommonProperties#OUTBOUND_CONTENT_LENGTH_BUFFER}.
785785
* </p>
786786
* The buffering functionality is by default disabled and could be enabled by calling this method. In this case
787787
* this method must be called before first bytes are written to the {@link #getEntityStream() entity stream}.
@@ -790,7 +790,7 @@ public void setEntityStream(OutputStream outputStream) {
790790
*/
791791
public void enableBuffering(Configuration configuration) {
792792
final Integer bufferSize = PropertiesHelper.getValue(configuration.getProperties(),
793-
configuration.getRuntimeType(), CommonProperties.CONTENT_LENGTH_BUFFER, Integer.class);
793+
configuration.getRuntimeType(), CommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, Integer.class);
794794
if (bufferSize != null) {
795795
committingOutputStream.enableBuffering(bufferSize);
796796
} else {

0 commit comments

Comments
 (0)