Skip to content

Commit

Permalink
Support BeanParam annotation on collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Jun 14, 2018
1 parent 87ec289 commit 04f5d34
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 48 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.sinistral</groupId>
<artifactId>proteus-core</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.2.1-SNAPSHOT</version>
<name>proteus core</name>
<description>Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow.</description>
<url>http://github.com/noboomu/proteus</url>
Expand Down
31 changes: 17 additions & 14 deletions src/main/java/io/sinistral/proteus/server/Extractors.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,27 @@ public static java.util.Optional<JsonIterator> jsonIterator(final HttpServerExch

public static <T> java.util.Optional<T> model(final HttpServerExchange exchange, final TypeLiteral<T> type )
{
if( ServerPredicates.JSON_PREDICATE.resolve(exchange) )
if( ServerPredicates.XML_PREDICATE.resolve(exchange) )
{
return jsonModel(exchange,type);

return xmlModel(exchange,type);
}
else
{
return xmlModel(exchange,type);
return jsonModel(exchange,type);
}
}

public static <T> java.util.Optional<T> model(final HttpServerExchange exchange, final Class<T> type )
{
if( ServerPredicates.JSON_PREDICATE.resolve(exchange) )
if( ServerPredicates.XML_PREDICATE.resolve(exchange) )
{
return jsonModel(exchange,type);

return xmlModel(exchange,type);
}
else
{
return xmlModel(exchange,type);
return jsonModel(exchange,type);
}
}

Expand Down Expand Up @@ -273,7 +275,7 @@ public static <T> T jsonModel(final HttpServerExchange exchange, final TypeLite
}
catch( Exception e )
{
throw new IllegalArgumentException("Invalid JSON");
throw new IllegalArgumentException("Invalid JSON: " + new String(exchange.getAttachment(ServerRequest.BYTE_BUFFER_KEY).array()) );
}
}

Expand All @@ -285,7 +287,7 @@ public static <T> T jsonModel(final HttpServerExchange exchange, final Class<T>
}
catch( Exception e )
{
throw new IllegalArgumentException("Invalid JSON");
throw new IllegalArgumentException("Invalid JSON: " + new String(exchange.getAttachment(ServerRequest.BYTE_BUFFER_KEY).array()) );

}
}
Expand Down Expand Up @@ -413,25 +415,26 @@ public static Boolean booleanValue(final HttpServerExchange exchange, final Str

public static <T> T model(final HttpServerExchange exchange, final TypeLiteral<T> type ) throws IllegalArgumentException
{
if( ServerPredicates.JSON_PREDICATE.resolve(exchange) )
if( ServerPredicates.XML_PREDICATE.resolve(exchange) )
{
return jsonModel(exchange,type);
return xmlModel(exchange,type);
}
else
{
return xmlModel(exchange,type);
return jsonModel(exchange,type);
}
}

public static <T> T model(final HttpServerExchange exchange, final Class<T> type ) throws IllegalArgumentException
{
if( ServerPredicates.JSON_PREDICATE.resolve(exchange) )
if( ServerPredicates.XML_PREDICATE.resolve(exchange) )
{
return jsonModel(exchange,type);

return xmlModel(exchange,type);
}
else
{
return xmlModel(exchange,type);
return jsonModel(exchange,type);
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/io/sinistral/proteus/server/ServerRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.Map;
import java.util.concurrent.Executor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xnio.channels.StreamSourceChannel;

import io.sinistral.proteus.server.predicates.ServerPredicates;
Expand All @@ -35,6 +37,8 @@ public class ServerRequest
{
public static final AttachmentKey<ByteBuffer> BYTE_BUFFER_KEY = AttachmentKey.create(ByteBuffer.class);

private static Logger log = LoggerFactory.getLogger(ServerRequest.class.getCanonicalName());

protected static final String CHARSET = "UTF-8";
protected static final String TMP_DIR = System.getProperty("java.io.tmpdir");

Expand Down Expand Up @@ -69,11 +73,11 @@ public ServerRequest(HttpServerExchange exchange) throws IOException
if (this.contentType != null )
{
if ( ServerPredicates.URL_ENCODED_FORM_PREDICATE.resolve(exchange) )
{
{
this.parseEncodedForm();
}
else if ( ServerPredicates.MULTIPART_PREDICATE.resolve(exchange) )
{
{
this.parseMultipartForm();
}
else if ( ServerPredicates.STRING_BODY_PREDICATE.resolve(exchange) )
Expand Down Expand Up @@ -143,6 +147,7 @@ public SecurityContext getSecurityContext()

private void extractBytes() throws IOException
{
//log.debug("start extracting bytes!");

this.exchange.startBlocking();

Expand All @@ -165,6 +170,10 @@ private void extractBytes() throws IOException

System.arraycopy(buf.array(), 0, buffer.array(), 0, pos);

buffer.rewind();

//log.debug("buffer " + new String(buffer.array()));

exchange.putAttachment(BYTE_BUFFER_KEY, buffer);

break;
Expand Down
Loading

0 comments on commit 04f5d34

Please sign in to comment.