Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2258 in ITERATE/cyberduck from bugfix/TRAC-11515 …
…to master * commit '0197dd65426f8ac4f1ebb6c6d4ed0f5f2388c25f': Formatting. New custom module with Jackson feature to override with higher priority default registered module `org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable` which uses `DefaultJacksonJaxbJsonProvider` that always registers modules using service loader in object mapper that breaks in IKVM. Fix #11515. Update dependency. Add to dependency management possible transient dependency. Exclude module not required.
- Loading branch information
Showing
12 changed files
with
360 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 23 additions & 29 deletions
52
dracoon/src/main/java/ch/cyberduck/core/sds/io/swagger/client/JSON.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,36 @@ | ||
package ch.cyberduck.core.sds.io.swagger.client; | ||
|
||
import ch.cyberduck.core.jersey.CustomJacksonObjectMapper; | ||
|
||
import javax.ws.rs.ext.ContextResolver; | ||
import java.text.DateFormat; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.datatype.joda.JodaModule; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
|
||
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2020-10-15T15:35:23.522373+02:00[Europe/Zurich]")public class JSON implements ContextResolver<ObjectMapper> { | ||
private ObjectMapper mapper; | ||
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2020-10-15T15:35:23.522373+02:00[Europe/Zurich]") | ||
public class JSON implements ContextResolver<ObjectMapper> { | ||
private ObjectMapper mapper; | ||
|
||
public JSON() { | ||
mapper = new ObjectMapper(); | ||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false); | ||
mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true); | ||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | ||
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); | ||
mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); | ||
mapper.setDateFormat(new RFC3339DateFormat()); | ||
mapper.registerModule(new JavaTimeModule()); | ||
mapper.registerModule(new JodaModule()); | ||
} | ||
public JSON() { | ||
mapper = new CustomJacksonObjectMapper(); | ||
mapper.setDateFormat(new RFC3339DateFormat()); | ||
mapper.registerModule(new JavaTimeModule()); | ||
mapper.registerModule(new JodaModule()); | ||
} | ||
|
||
/** | ||
* Set the date format for JSON (de)serialization with Date properties. | ||
* @param dateFormat Date format | ||
*/ | ||
public void setDateFormat(DateFormat dateFormat) { | ||
mapper.setDateFormat(dateFormat); | ||
} | ||
/** | ||
* Set the date format for JSON (de)serialization with Date properties. | ||
* | ||
* @param dateFormat Date format | ||
*/ | ||
public void setDateFormat(DateFormat dateFormat) { | ||
mapper.setDateFormat(dateFormat); | ||
} | ||
|
||
@Override | ||
public ObjectMapper getContext(Class<?> type) { | ||
return mapper; | ||
} | ||
@Override | ||
public ObjectMapper getContext(Class<?> type) { | ||
return mapper; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2002-2020 iterate GmbH. All rights reserved. | ||
~ https://cyberduck.io/ | ||
~ | ||
~ This program is free software; you can redistribute it and/or modify | ||
~ it under the terms of the GNU General Public License as published by | ||
~ the Free Software Foundation, either version 3 of the License, or | ||
~ (at your option) any later version. | ||
~ | ||
~ This program is distributed in the hope that it will be useful, | ||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
~ GNU General Public License for more details. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>parent</artifactId> | ||
<groupId>ch.cyberduck</groupId> | ||
<version>7.7.3-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>jersey</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>ch.cyberduck</groupId> | ||
<artifactId>core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-client</artifactId> | ||
</dependency> | ||
<!-- add support for Apache HTTP client --> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.connectors</groupId> | ||
<artifactId>jersey-apache-connector</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.media</groupId> | ||
<artifactId>jersey-media-json-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.media</groupId> | ||
<artifactId>jersey-media-multipart</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.inject</groupId> | ||
<artifactId>jersey-hk2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.jaxrs</groupId> | ||
<artifactId>jackson-jaxrs-base</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jsr310</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.jaxrs</groupId> | ||
<artifactId>jackson-jaxrs-json-provider</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-joda</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>joda-time</groupId> | ||
<artifactId>joda-time</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.brsanthu</groupId> | ||
<artifactId>migbase64</artifactId> | ||
<version>2.2</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
45 changes: 45 additions & 0 deletions
45
jersey/src/main/java/ch/cyberduck/core/jersey/CustomContextResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ch.cyberduck.core.jersey; | ||
|
||
/* | ||
* Copyright (c) 2002-2020 iterate GmbH. All rights reserved. | ||
* https://cyberduck.io/ | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
import javax.ws.rs.ext.ContextResolver; | ||
import java.text.DateFormat; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class CustomContextResolver implements ContextResolver<ObjectMapper> { | ||
|
||
private final ObjectMapper mapper; | ||
|
||
public CustomContextResolver() { | ||
mapper = new CustomJacksonObjectMapper(); | ||
} | ||
|
||
/** | ||
* Set the date format for JSON (de)serialization with Date properties. | ||
* | ||
* @param dateFormat Date format | ||
*/ | ||
public void setDateFormat(DateFormat dateFormat) { | ||
mapper.setDateFormat(dateFormat); | ||
} | ||
|
||
@Override | ||
public ObjectMapper getContext(Class<?> type) { | ||
return mapper; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
jersey/src/main/java/ch/cyberduck/core/jersey/CustomJacksonAutoDiscoverable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ch.cyberduck.core.jersey; | ||
|
||
/* | ||
* Copyright (c) 2002-2020 iterate GmbH. All rights reserved. | ||
* https://cyberduck.io/ | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
import org.glassfish.jersey.internal.spi.AutoDiscoverable; | ||
|
||
import javax.annotation.Priority; | ||
import javax.ws.rs.core.FeatureContext; | ||
|
||
@Priority(1) | ||
public class CustomJacksonAutoDiscoverable implements AutoDiscoverable { | ||
|
||
@Override | ||
public void configure(final FeatureContext context) { | ||
if(!context.getConfiguration().isRegistered(CustomJacksonFeature.class)) { | ||
context.register(CustomJacksonFeature.class); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
jersey/src/main/java/ch/cyberduck/core/jersey/CustomJacksonFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ch.cyberduck.core.jersey; | ||
|
||
/* | ||
* Copyright (c) 2002-2020 iterate GmbH. All rights reserved. | ||
* https://cyberduck.io/ | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
import org.glassfish.jersey.CommonProperties; | ||
import org.glassfish.jersey.internal.InternalProperties; | ||
import org.glassfish.jersey.internal.util.PropertiesHelper; | ||
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.base.JsonMappingExceptionMapper; | ||
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.base.JsonParseExceptionMapper; | ||
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider; | ||
|
||
import javax.annotation.Priority; | ||
import javax.ws.rs.core.Configuration; | ||
import javax.ws.rs.core.Feature; | ||
import javax.ws.rs.core.FeatureContext; | ||
import javax.ws.rs.ext.MessageBodyReader; | ||
import javax.ws.rs.ext.MessageBodyWriter; | ||
|
||
@Priority(1) | ||
public class CustomJacksonFeature implements Feature { | ||
|
||
private static final String JSON_FEATURE = CustomJacksonFeature.class.getSimpleName(); | ||
|
||
@Override | ||
public boolean configure(final FeatureContext context) { | ||
final Configuration config = context.getConfiguration(); | ||
|
||
final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), | ||
InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class); | ||
// Other JSON providers registered. | ||
if(!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) { | ||
return false; | ||
} | ||
|
||
// Disable other JSON providers. | ||
context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), | ||
JSON_FEATURE); | ||
|
||
// Register Jackson. | ||
if(!config.isRegistered(JacksonJaxbJsonProvider.class)) { | ||
// add the default Jackson exception mappers | ||
context.register(JsonParseExceptionMapper.class); | ||
context.register(JsonMappingExceptionMapper.class); | ||
context.register(JacksonJaxbJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class); | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.