Skip to content

Commit

Permalink
Fix #134 (remove JAX-RS 1.x compatibility work-around)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 20, 2021
1 parent a8216ac commit f58c631
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 137 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@

import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import javax.ws.rs.core.*;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.jaxrs.base.nocontent.JaxRS1NoContentExceptionSupplier;
import com.fasterxml.jackson.jaxrs.base.nocontent.JaxRS2NoContentExceptionSupplier;

import com.fasterxml.jackson.jaxrs.cfg.*;
import com.fasterxml.jackson.jaxrs.util.ClassKey;
import com.fasterxml.jackson.jaxrs.util.LRUMap;
Expand All @@ -40,7 +36,7 @@ public abstract class ProviderBase<

protected final static String CLASS_NAME_NO_CONTENT_EXCEPTION = "javax.ws.rs.core.NoContentException";

protected final NoContentExceptionSupplier noContentExceptionSupplier = _createNoContentExceptionSupplier();
private final static String NO_CONTENT_MESSAGE = "No content (empty input stream)";

/**
* Looks like we need to worry about accidental
Expand Down Expand Up @@ -171,9 +167,6 @@ public abstract class ProviderBase<
protected final LRUMap<AnnotationBundleKey, EP_CONFIG> _writers
= new LRUMap<AnnotationBundleKey, EP_CONFIG>(16, 120);

protected final AtomicReference<IOException> _noContentExceptionRef
= new AtomicReference<IOException>();

/*
/**********************************************************
/* Life-cycle
Expand All @@ -186,9 +179,8 @@ protected ProviderBase(MAPPER_CONFIG mconfig) {
}

/**
* Constructor that is only added to resolve
* issue #10; problems with combination of
* RESTeasy and CDI.
* Constructor that is only added to resolve [jaxrs-providers#10]; problems
* with combination of RESTeasy and CDI.
* Should NOT be used by any code explicitly; only exists
* for proxy support.
*/
Expand Down Expand Up @@ -533,9 +525,8 @@ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotat
// negation: Boolean.TRUE means untouchable -> can not write
return !customUntouchable.booleanValue();
}
/* Ok: looks like we must weed out some core types here; ones that
* make no sense to try to bind from JSON:
*/
// Ok: looks like we must weed out some core types here; ones that
// make no sense to try to bind from JSON:
if (_isIgnorableForWriting(new ClassKey(type))) {
return false;
}
Expand Down Expand Up @@ -730,9 +721,8 @@ public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotati
// negation: Boolean.TRUE means untouchable -> can not write
return !customUntouchable.booleanValue();
}
/* Ok: looks like we must weed out some core types here; ones that
* make no sense to try to bind from JSON:
*/
// Ok: looks like we must weed out some core types here; ones that
// make no sense to try to bind from JSON:
if (_isIgnorableForReading(new ClassKey(type))) {
return false;
}
Expand Down Expand Up @@ -776,14 +766,11 @@ public Object readFrom(Class<Object> type, Type genericType, Annotation[] annota
if (JaxRSFeature.ALLOW_EMPTY_INPUT.enabledIn(_jaxRSFeatures)) {
return null;
}
/* 05-Apr-2014, tatu: Trick-ee. NoContentFoundException only available in JAX-RS 2.0...
* so need bit of obfuscated code to reach it.
*/
IOException fail = _noContentExceptionRef.get();
if (fail == null) {
fail = _createNoContentException();
}
throw fail;
// 05-Apr-2014, tatu: Trick-ee. NoContentFoundException only available in JAX-RS 2.0...
// so need bit of obfuscated code to reach it.

// 20-Jan-2021, tatu: as per [jaxrs-providers#134], simplify
throw _createNoContentException();
}
Class<?> rawType = type;
if (rawType == JsonParser.class) {
Expand Down Expand Up @@ -969,13 +956,9 @@ protected boolean _isIgnorableForWriting(ClassKey typeKey)
{
return _untouchables.contains(typeKey);
}

/**
* @since 2.4
*/
protected IOException _createNoContentException()
{
return noContentExceptionSupplier.createNoContentException();

protected IOException _createNoContentException() {
return new NoContentException(NO_CONTENT_MESSAGE);
}

/*
Expand Down Expand Up @@ -1052,45 +1035,4 @@ protected static void _addSuperTypes(Class<?> cls, Class<?> endBefore, Collectio
private final THIS _this() {
return (THIS) this;
}

/**
* Since class <code>javax.ws.rs.core.NoContentException</code> only exists in
* JAX-RS 2.0, but we want to have 1.x compatibility, need to dynamically select exception supplier
*/
private static NoContentExceptionSupplier _createNoContentExceptionSupplier() {
try {
final Class<?> cls = Class.forName(CLASS_NAME_NO_CONTENT_EXCEPTION, false, getClassLoader());
Constructor<?> ctor;
if (System.getSecurityManager() == null) {
ctor = cls.getDeclaredConstructor(String.class);
} else {
ctor = AccessController.doPrivileged(new PrivilegedAction<Constructor<?>>() {
@Override
public Constructor<?> run() {
try {
return cls.getDeclaredConstructor(String.class);
} catch (NoSuchMethodException ignore) {
return null;
}
}
});
}
if (ctor != null) {
return new JaxRS2NoContentExceptionSupplier();
}
} catch (ClassNotFoundException | NoSuchMethodException ex) { }
return new JaxRS1NoContentExceptionSupplier();
}

private static ClassLoader getClassLoader() {
if (System.getSecurityManager() == null) {
return ProviderBase.class.getClassLoader();
}
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
@Override
public ClassLoader run() {
return ProviderBase.class.getClassLoader();
}
});
}
}

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion base/src/moditect/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
module com.fasterxml.jackson.jaxrs.base {
exports com.fasterxml.jackson.jaxrs.annotation;
exports com.fasterxml.jackson.jaxrs.base;
exports com.fasterxml.jackson.jaxrs.base.nocontent;
exports com.fasterxml.jackson.jaxrs.cfg;
exports com.fasterxml.jackson.jaxrs.util;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static class SimpleResourceApp extends CBORApplicationWithJackson {
public SimpleResourceApp() { super(new SimpleResource()); }
}

private final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };
final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };

@Path("/raw")
public static class RawResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;

import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -52,6 +53,7 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;

public abstract class SimpleEndpointTestBase extends ResourceTestBase
Expand Down Expand Up @@ -152,8 +154,8 @@ protected PageImpl() {
this.links = new ArrayList<>();
}

public void addEntities(E... entitities) {
Collections.addAll(this.entities, entitities);
public void addEntities(E... entities) {
Collections.addAll(this.entities, entities);
}

public void addLinks(Link... links) {
Expand Down
2 changes: 1 addition & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Sub-modules:

2.13.0 (not yet released)

No changes since 2.12
#134: Remove work-around for JAX-RS 1.x wrt JAX-RS 2 type `NoContentException`

2.12.1 (08-Jan-2021)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static class SimpleResourceApp extends SmileApplicationWithJackson {
public SimpleResourceApp() { super(new SimpleResource()); }
}

private final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };
final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };

@Path("/raw")
public static class RawResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.fasterxml.jackson.databind.SerializationFeature;

import com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures;
import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;

/**
* Tests for [Issue-2], Addition of {@link JacksonFeatures}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.ws.rs.core.MediaType;

import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;

public class TestJsonView extends JaxrsTestBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;

public class TestRootType
extends JaxrsTestBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;

import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;

/**
* Unit tests for verifying that certain JDK base types will be
* ignored by default Jackson JAX-RS conversion provider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider;

public class TestXMLVersions extends JaxrsTestBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static class SimpleResourceApp extends XMLApplicationWithJackson {
public SimpleResourceApp() { super(new SimpleResource()); }
}

private final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };
final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };

@Path("/raw")
public static class RawResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public MultiMediaTypeResourceApp() {
}
}

private final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };
final static byte[] UNTOUCHABLE_RESPONSE = new byte[] { 1, 2, 3, 4 };

@Path("/raw")
public static class RawResource
Expand Down

0 comments on commit f58c631

Please sign in to comment.