Skip to content

Commit

Permalink
Update readme.
Browse files Browse the repository at this point in the history
Improvements to JsonViewWrapper.

Cleanup JsonViewWrapper.

More JSON work.
  • Loading branch information
noboomu committed Jan 31, 2020
1 parent e713dcd commit 594682f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ Proteus Changelog.
## Unreleased
### No issue

**Cleanup JsonViewWrapper.**


[dc95a16a710813a](https://github.com/noboomu/proteus/commit/dc95a16a710813a) Joshua Bauer *2020-01-31 01:04:26*

**Improvements to JsonViewWrapper.**


[ead870ae6ad73d9](https://github.com/noboomu/proteus/commit/ead870ae6ad73d9) Joshua Bauer *2020-01-31 01:02:12*

**Update readme.**


[7bfd78a09ba642d](https://github.com/noboomu/proteus/commit/7bfd78a09ba642d) Joshua Bauer *2020-01-31 00:39:35*

**Improve JSON view handling.**


[e713dcdbaa67453](https://github.com/noboomu/proteus/commit/e713dcdbaa67453) Joshua Bauer *2020-01-31 00:20:00*

**Improve OpenAPI preprocessing.**


[82a22bcbe66f93f](https://github.com/noboomu/proteus/commit/82a22bcbe66f93f) Joshua Bauer *2020-01-30 23:30:24*

**Allow byte arrays in response bodies.**


Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ An extremely __lightweight, flexible, and high performance__ [Undertow](http://u
- JAX-RS compliant
- Easy on the developer and the metal
- Blazing fast!!!
[The latest Techempower benchmarks](https://www.techempower.com/benchmarks/) demonstrate __proteus__ outperforming 99% of all other web frameworks
[The latest Techempower benchmarks](https://www.techempower.com/benchmarks/) demonstrate __proteus__ outperforming the top Java web frameworks

![Top 5 in Java Frameworks for Fortunes](https://github.com/noboomu/proteus-example/blob/master/src/main/resources/images/benchmark1.png?raw=true)
![Top in Java Frameworks for JSON](https://github.com/noboomu/proteus-example/blob/master/src/main/resources/images/benchmark1.png?raw=true)

![Top 5 in Java Frameworks for JSON](https://github.com/noboomu/proteus-example/blob/master/src/main/resources/images/benchmark2.png?raw=true)
![Top in Java Frameworks for Plaintext](https://github.com/noboomu/proteus-example/blob/master/src/main/resources/images/benchmark2.png?raw=true)

TL;DR
---------------
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@

</pluginManagement>



</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sinistral.proteus.wrappers;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.util.AttachmentKey;
Expand All @@ -12,45 +13,51 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

@Singleton
public class JsonViewWrapper implements HandlerWrapper
{
public static AttachmentKey<Class> JSON_VIEW_KEY = AttachmentKey.create(Class.class);
public static AttachmentKey<Class<?>> JSON_VIEW_KEY = AttachmentKey.create(Class.class);

private static final Logger logger = LoggerFactory.getLogger(JsonViewWrapper.class.getName());

@Named("jackson.jsonView.className")
@Inject(optional = true)
private static String VIEW_CLASS_NAME;
private static String VIEW_CLASS_NAME = null;

@Named("jackson.jsonView.defaultViewClass")
@Inject(optional = true)
private static String DEFAULT_VIEW_CLASS = null;
private static String DEFAULT_VIEW_CLASS_NAME = null;

@Named("jackson.jsonView.queryParameterName")
@Inject(optional = true)
private static String QUERY_PARAMETER_NAME = "context";

private static Map<String, Class> CLASS_MAP;
private Map<String, Class> CLASS_MAP = new ConcurrentHashMap<>();

private Class<?> defaultViewClass = null;

public JsonViewWrapper()
{
super();

if (CLASS_MAP == null && VIEW_CLASS_NAME != null) {
if ( VIEW_CLASS_NAME != null) {

try {

Class clazz = Class.forName(VIEW_CLASS_NAME);

CLASS_MAP = new HashMap<>();
Class<?> clazz = Class.forName(VIEW_CLASS_NAME);

final Class[] contexts = clazz.getClasses();
final Class<?>[] contexts = clazz.getClasses();

for (Class c : contexts) {
for (Class<?> c : contexts) {
CLASS_MAP.put(c.getSimpleName().toLowerCase(), c);
}

if(DEFAULT_VIEW_CLASS_NAME != null)
{
defaultViewClass = Class.forName(DEFAULT_VIEW_CLASS_NAME);
}


} catch (Exception e) {
Expand All @@ -69,17 +76,17 @@ public HttpHandler wrap(HttpHandler handler)

String className = Optional.ofNullable(exchange.getQueryParameters().get(QUERY_PARAMETER_NAME))
.filter(q -> q.size() > 0)
.map(Deque::getFirst)
.orElse(DEFAULT_VIEW_CLASS);

.map(Deque::getFirst).orElse(null);

if(className != null) {
Class viewClass = CLASS_MAP.get(className.toLowerCase());
Class<?> viewClass = CLASS_MAP.getOrDefault(className, defaultViewClass);

exchange.putAttachment(JSON_VIEW_KEY, viewClass);
}


else if(defaultViewClass != null)
{
exchange.putAttachment(JSON_VIEW_KEY, defaultViewClass);
}
}

handler.handleRequest(exchange);
Expand Down

0 comments on commit 594682f

Please sign in to comment.