Skip to content

Commit

Permalink
Break out XmlModule
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed May 15, 2020
1 parent eb514fe commit cf6d3c9
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 9 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@ Proteus Changelog.
## Unreleased
### No issue

**Incorrect File.sep() use - broken on Windows.**

* On Windows:
* ```
* GET /v1/openapi/* [*/*] [*/*] (OpenAPIService._)
* GET /v1/openapi/redoc [*/*] [text/html] (OpenAPIService._)
* GET /v1\openapi.yaml [*/*] [text/yaml] (OpenAPIService._)
* ```
[bea9fd3de5d1d4d](https://github.com/noboomu/proteus/commit/bea9fd3de5d1d4d) nich0s *2020-05-01 13:35:04*
**Better error logs.**
[aad21cfa3e050d3](https://github.com/noboomu/proteus/commit/aad21cfa3e050d3) Joshua Bauer *2020-04-28 16:04:11*
**Update README.md**
[e3fac1fd8f268ef](https://github.com/noboomu/proteus/commit/e3fac1fd8f268ef) JL Bauer *2020-04-02 02:11:17*
**Added multipart/form-data media type.**
[544668fabf96683](https://github.com/noboomu/proteus/commit/544668fabf96683) Joshua Bauer *2020-03-30 23:14:29*
## v0.4.5
### No issue
**Set version to 4.5 for release**
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<undertow.version>2.0.20.Final</undertow.version>
<undertow.version>2.1.0.Final</undertow.version>
<jackson.version>2.9.8</jackson.version>
<guava.version>28.1-jre</guava.version>
<guice.version>4.2.2</guice.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,7 @@ public ApplicationModule(Config config)
*/
public void bindMappers()
{
JacksonXmlModule xmlModule = new JacksonXmlModule();

xmlModule.setDefaultUseWrapper(false);

XmlMapper xmlMapper = new XmlMapper(xmlModule);

xmlMapper.enable(ToXmlGenerator.Feature.WRITE_XML_DECLARATION);

this.bind(XmlMapper.class).toInstance(xmlMapper);

try {

Expand All @@ -79,6 +71,28 @@ public void bindMappers()

}

try {

String className = config.getString("application.xmlModule");

log.info("Installing XmlModule " + className);

Class<? extends AbstractModule> clazz = (Class<? extends AbstractModule>) Class.forName(className);

AbstractModule module = clazz.newInstance();

install(module);

} catch (Exception e) {

this.binder().addError(e);

log.error(e.getMessage(), e);

install(new XmlModule());

}

this.requestStaticInjection(Extractors.class);
this.requestStaticInjection(ServerResponse.class);
this.requestStaticInjection(JsonViewWrapper.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.sinistral.proteus.modules;

import com.ctc.wstx.api.WstxInputProperties;
import com.ctc.wstx.api.WstxOutputProperties;
import com.ctc.wstx.stax.WstxInputFactory;
import com.ctc.wstx.stax.WstxOutputFactory;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.xml.XmlFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import com.google.inject.AbstractModule;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;

public class XmlModule extends AbstractModule {

@Override
protected void configure() {

XMLInputFactory inputFactory = new WstxInputFactory();
inputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, 32000);

bind(XMLInputFactory.class).toInstance(inputFactory);

XMLOutputFactory outputFactory = new WstxOutputFactory();
outputFactory.setProperty(WstxOutputProperties.P_OUTPUT_CDATA_AS_TEXT, true);

bind(XMLOutputFactory.class).toInstance(outputFactory);

XmlFactory xmlFactory = new XmlFactory(inputFactory, outputFactory);

XmlMapper xmlMapper = new XmlMapper(xmlFactory);
xmlMapper.registerModule(new JavaTimeModule())
.registerModule(new ParameterNamesModule())
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

xmlMapper.enable(ToXmlGenerator.Feature.WRITE_XML_DECLARATION);

bind(XmlMapper.class).toInstance(xmlMapper);

}
}
1 change: 1 addition & 0 deletions proteus-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ application {
defaultResponseListener = "io.sinistral.proteus.server.handlers.ServerDefaultResponseListener"

jacksonModule = "io.sinistral.proteus.modules.JacksonModule"
xmlModule = "io.sinistral.proteus.modules.XmlModule"

tmpdir = ${java.io.tmpdir}/${application.name}

Expand Down

0 comments on commit cf6d3c9

Please sign in to comment.