Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.restlet.ext.freemarker;

import static freemarker.template.Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -43,7 +44,7 @@ void testTemplate() throws Exception {
fw.write("Value=${value}");
fw.close();

final Configuration fmc = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
final Configuration fmc = new Configuration(DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
fmc.setDirectoryForTemplateLoading(testDir);
final Map<String, Object> map = Map.of("value", "myValue");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public GsonRepresentation(T object) {
*/
protected GsonBuilder createBuilder() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setDateFormat(DateFormat.FULL);
gsonBuilder.setDateFormat(DateFormat.FULL, DateFormat.FULL);
return gsonBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static <T> T doAsPriviledged(ClientInfo clientInfo, PrivilegedAction<T> a
* @param acc the AccessControlContext to be tied to the specified subject and action.
* @return the value returned by the action.
*/
@SuppressWarnings("removal")
public static <T> T doAsPriviledged(
ClientInfo clientInfo, PrivilegedAction<T> action, AccessControlContext acc) {
Subject subject = JaasUtils.createSubject(clientInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ protected ObjectWriter createObjectWriter() {
CsvSchema csvSchema = createCsvSchema(csvMapper);
result = csvMapper.writer(csvSchema);
} else {
result = getObjectMapper().writerWithType(getObjectClass());
result = getObjectMapper().writerFor(getObjectClass());
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ void testXmlBomb() {
Undeclared general entity "lol10"
at [row,col {unknown-source}]: [14,31]
at [Source: (BufferedInputStream); line: 14, column: 32]""";
Assertions.assertEquals(expected, exception.getMessage());
Assertions.assertEquals(
normalizeLineEndings(expected), normalizeLineEndings(exception.getMessage()));
}

@Test
Expand Down Expand Up @@ -203,4 +204,8 @@ protected void assertEquals(MyException me1, MyException me2) {
Assertions.assertEquals(me1.getErrorCode(), me2.getErrorCode());
assertEquals(me1.getCustomer(), me2.getCustomer());
}

private String normalizeLineEndings(String text) {
return text.replace("\r\n", "\n").replace('\r', '\n');
}
}
4 changes: 0 additions & 4 deletions org.restlet.ext.json/src/main/java/org/restlet/JSON.gwt.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public JsonRepresentation(Map<String, Object> map) {
* @see org.json.JSONObject#JSONObject(Object)
*/
public JsonRepresentation(Object bean) {
this(new JSONObject(bean)); // TODO Should be called if Android edition
this(new JSONObject(bean));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@

import io.swagger.v3.oas.integration.GenericOpenApiContext;
import io.swagger.v3.oas.integration.api.OpenAPIConfiguration;
import io.swagger.v3.oas.integration.api.OpenApiContext;
import io.swagger.v3.oas.integration.api.OpenApiReader;
import org.apache.commons.lang3.StringUtils;
import org.restlet.routing.Router;

public class RestletOpenApiContext extends GenericOpenApiContext<RestletOpenApiContext>
implements OpenApiContext {
public class RestletOpenApiContext extends GenericOpenApiContext<RestletOpenApiContext> {
private final Router router;

public RestletOpenApiContext(Router router) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.restlet.resource.ServerResource;
import org.restlet.routing.Router;

@SuppressWarnings("unused")
public class LibraryExample {
private static final List<Book> BOOKS =
List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.NonNull;

/**
* An alternative to {@link SpringFinder} which uses Spring's BeanFactory mechanism to load a
Expand Down Expand Up @@ -54,7 +55,7 @@ public SpringBeanFinder() {}
* @param beanFactory The Spring bean factory.
* @param beanName The bean name.
*/
public SpringBeanFinder(Router router, BeanFactory beanFactory, String beanName) {
public SpringBeanFinder(Router router, @NonNull BeanFactory beanFactory, String beanName) {
this.router = router;
setBeanFactory(beanFactory);
setBeanName(beanName);
Expand All @@ -63,10 +64,11 @@ public SpringBeanFinder(Router router, BeanFactory beanFactory, String beanName)
@Override
public ServerResource create() {
final Object resource = findBean();
String requiredBeanName = getRequiredBeanName();

if (!(resource instanceof ServerResource)) {
throw new ClassCastException(
getBeanName()
requiredBeanName
+ " does not resolve to an instance of "
+ org.restlet.resource.ServerResource.class.getName());
}
Expand All @@ -75,20 +77,29 @@ public ServerResource create() {
}

private Object findBean() {
String requiredBeanName = getRequiredBeanName();
if (getBeanFactory() == null && getApplicationContext() == null) {
throw new IllegalStateException(
"Either a beanFactory or an applicationContext is required for SpringBeanFinder.");
} else if (getApplicationContext() != null
&& getApplicationContext().containsBean(getBeanName())) {
return getApplicationContext().getBean(getBeanName());
} else if (getBeanFactory() != null && getBeanFactory().containsBean(getBeanName())) {
return getBeanFactory().getBean(getBeanName());
&& getApplicationContext().containsBean(requiredBeanName)) {
return getApplicationContext().getBean(requiredBeanName);
} else if (getBeanFactory() != null && getBeanFactory().containsBean(requiredBeanName)) {
return getBeanFactory().getBean(requiredBeanName);
} else {
throw new IllegalStateException(
String.format("No bean named %s present.", getBeanName()));
String.format("No bean named %s present.", requiredBeanName));
}
}

@NonNull private String getRequiredBeanName() {
String currentBeanName = getBeanName();
if (currentBeanName == null) {
throw new IllegalStateException("beanName");
}
return currentBeanName;
}

/**
* Returns the parent application context.
*
Expand Down Expand Up @@ -135,7 +146,7 @@ public Router getRouter() {
*
* @param applicationContext The parent context.
*/
public void setApplicationContext(ApplicationContext applicationContext) {
public void setApplicationContext(@NonNull ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}

Expand All @@ -144,7 +155,7 @@ public void setApplicationContext(ApplicationContext applicationContext) {
*
* @param beanFactory The parent bean factory.
*/
public void setBeanFactory(BeanFactory beanFactory) {
public void setBeanFactory(@NonNull BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.NonNull;

/**
* Restlet {@link Router} which behaves like Spring's {@link
Expand Down Expand Up @@ -136,7 +137,7 @@ protected void attachResource(String uri, String beanName, BeanFactory beanFacto
* @param beanFactory The Spring bean factory.
*/
protected void attachRestlet(String uri, String beanName, BeanFactory beanFactory) {
attach(uri, (Restlet) beanFactory.getBean(beanName));
attach(uri, (Restlet) requiredBeanFactory(beanFactory).getBean(requiredBeanName(beanName)));
}

/**
Expand All @@ -147,7 +148,8 @@ protected void attachRestlet(String uri, String beanName, BeanFactory beanFactor
* @see #attachResource
*/
protected Finder createFinder(BeanFactory beanFactory, String beanName) {
return new SpringBeanFinder(this, beanFactory, beanName);
return new SpringBeanFinder(
this, requiredBeanFactory(beanFactory), requiredBeanName(beanName));
}

/**
Expand All @@ -169,8 +171,12 @@ protected Map<String, String> getAttachments() {
private String[] getBeanNamesByType(Class<?> beanClass, ListableBeanFactory beanFactory) {
return isFindingInAncestors()
? BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
beanFactory, beanClass, true, true)
: beanFactory.getBeanNamesForType(beanClass, true, true);
requiredListableBeanFactory(beanFactory),
requiredBeanClass(beanClass),
true,
true)
: requiredListableBeanFactory(beanFactory)
.getBeanNamesForType(requiredBeanClass(beanClass), true, true);
}

/**
Expand Down Expand Up @@ -202,19 +208,19 @@ public boolean isFindingInAncestors() {
* @param beanFactory The Spring bean factory.
* @see #setAttachments
*/
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
public void postProcessBeanFactory(@NonNull ConfigurableListableBeanFactory beanFactory)
throws BeansException {

ListableBeanFactory source =
this.applicationContext == null ? beanFactory : this.applicationContext;
this.applicationContext == null ? beanFactory : requiredApplicationContext();
attachAllResources(source);
attachAllRestlets(source);

if (getAttachments() != null) {
for (Map.Entry<String, String> attachment : getAttachments().entrySet()) {
String uri = attachment.getKey();
String beanName = attachment.getValue();
Class<?> beanType = source.getType(beanName);
String beanName = requiredBeanName(attachment.getValue());
Class<?> beanType = requiredBeanClass(source.getType(beanName));

if (org.restlet.resource.ServerResource.class.isAssignableFrom(beanType)) {
attachResource(uri, beanName, source);
Expand All @@ -239,11 +245,13 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
* @return The alias URI.
*/
protected String resolveUri(String beanName, ListableBeanFactory beanFactory) {
if (isAvailableUri(beanName)) {
return beanName;
String requiredBeanName = requiredBeanName(beanName);
if (isAvailableUri(requiredBeanName)) {
return requiredBeanName;
}

for (final String alias : beanFactory.getAliases(beanName)) {
for (final String alias :
requiredListableBeanFactory(beanFactory).getAliases(requiredBeanName)) {
if (isAvailableUri(alias)) {
return alias;
}
Expand All @@ -257,10 +265,47 @@ protected String resolveUri(String beanName, ListableBeanFactory beanFactory) {
*
* @param applicationContext The context.
*/
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
public void setApplicationContext(@NonNull ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
}

@NonNull private String requiredBeanName(String beanName) {
if (beanName == null) {
throw new IllegalStateException("beanName");
}
return beanName;
}

@NonNull private BeanFactory requiredBeanFactory(BeanFactory beanFactory) {
if (beanFactory == null) {
throw new IllegalStateException("beanFactory");
}
return beanFactory;
}

@NonNull private ListableBeanFactory requiredListableBeanFactory(ListableBeanFactory beanFactory) {
if (beanFactory == null) {
throw new IllegalStateException("beanFactory");
}
return beanFactory;
}

@NonNull private Class<?> requiredBeanClass(Class<?> beanClass) {
if (beanClass == null) {
throw new IllegalStateException("beanClass");
}
return beanClass;
}

@NonNull private ApplicationContext requiredApplicationContext() {
ApplicationContext currentApplicationContext = this.applicationContext;
if (currentApplicationContext == null) {
throw new IllegalStateException("applicationContext");
}
return currentApplicationContext;
}

/**
* Sets an explicit mapping of URI templates to bean IDs to use in addition to the usual bean
* name mapping behavior. If a URI template appears in both this mapping and as a bean name, the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public List<String> getXmlConfigRefs() {
}

@Override
@SuppressWarnings("deprecation")
public void refresh() {
// If this context hasn't been loaded yet, read all the configurations
// registered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.restlet.engine.util.SystemUtils;
import org.restlet.representation.Representation;
import org.springframework.core.io.AbstractResource;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;

/**
* Spring Resource based on a Restlet Representation. DON'T GET CONFUSED, Spring's notion of
Expand All @@ -23,7 +25,7 @@
*/
public class SpringResource extends AbstractResource {
/** The description. */
private final String description;
@NonNull private final String description;

/** Indicates if the representation has already been read. */
private volatile boolean read = false;
Expand All @@ -46,7 +48,7 @@ public SpringResource(Representation representation) {
* @param representation The description.
* @param description The description.
*/
public SpringResource(Representation representation, String description) {
public SpringResource(Representation representation, @Nullable String description) {
if (representation == null) {
throw new IllegalArgumentException("Representation must not be null");
}
Expand All @@ -57,7 +59,7 @@ public SpringResource(Representation representation, String description) {

/** {@inheritDoc} */
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
Expand All @@ -79,7 +81,7 @@ public boolean exists() {
* @return The description.
*/
@Override
public String getDescription() {
@NonNull public String getDescription() {
return this.description;
}

Expand All @@ -88,14 +90,18 @@ public String getDescription() {
* multiple times.
*/
@Override
public InputStream getInputStream() throws IOException, IllegalStateException {
@NonNull public InputStream getInputStream() throws IOException, IllegalStateException {
if (this.read && this.representation.isTransient()) {
throw new IllegalStateException(
"Representation has already been read and is transient.");
}

this.read = true;
return this.representation.getStream();
InputStream stream = this.representation.getStream();
if (stream == null) {
throw new IllegalStateException("representation stream");
}
return stream;
}

/** This implementation returns the hash code of the underlying InputStream. */
Expand Down
Loading
Loading