Skip to content

Commit

Permalink
Restore latest undertow version.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Sep 21, 2017
1 parent 1e3fc55 commit 9f83467
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.jackson>2.8.8.1</version.jackson>
<version.maven-shade-plugin>3.0.0</version.maven-shade-plugin>
<version.undertow>1.2.5.Final</version.undertow>
<version.undertow>1.4.13.Final</version.undertow>
</properties>

<build>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/sinistral/proteus/server/Extractors.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public static Path filePath(final HttpServerExchange exchange, final String nam
{
try
{
return exchange.getAttachment(FormDataParser.FORM_DATA).get(name).getFirst().getFile().toPath();
return exchange.getAttachment(FormDataParser.FORM_DATA).get(name).getFirst().getPath();
} catch(NullPointerException e)
{
throw new IllegalArgumentException("Missing parameter " + name, e);
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/io/sinistral/proteus/server/ServerRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,16 @@ private void extractBytes() throws IOException

ByteBuffer buffer = ByteBuffer.allocate(pos);

ByteBuffer src = buf.duplicate();
src.position(0);
src.limit(0 + pos);
buffer.put(src);
int nTransfer = Math.min(buffer.remaining(), buf.remaining());
if (nTransfer > 0)
{
buffer.put(buf.array(),
buf.arrayOffset()+buf.position(),
nTransfer);
buf.position(buf.position()+nTransfer);
}

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

exchange.putAttachment(BYTE_BUFFER_KEY, buffer);

Expand All @@ -188,7 +192,7 @@ private void parseMultipartForm() throws IOException

this.exchange.startBlocking();
final FormDataParser formDataParser = new MultiPartParserDefinition()
.setTempFileLocation(new File(TMP_DIR))
.setTempFileLocation(new File(TMP_DIR).toPath())
.setDefaultEncoding(CHARSET)
.create(this.exchange);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.sinistral.proteus.server.predicates.ServerPredicates;
import io.undertow.server.DefaultResponseListener;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.AttachmentKey;
import io.undertow.util.Headers;
import io.undertow.util.StatusCodes;

Expand All @@ -34,8 +33,6 @@ public class ServerDefaultResponseListener implements DefaultResponseListener
private static Logger log = LoggerFactory.getLogger(ServerDefaultResponseListener.class.getCanonicalName());


public static AttachmentKey<Throwable> EXCEPTION = AttachmentKey.create(Throwable.class);

@Inject
protected XmlMapper xmlMapper;

Expand All @@ -47,9 +44,9 @@ public boolean handleDefaultResponse(HttpServerExchange exchange)
return false;
}

if (exchange.getResponseCode() >= 400) {
if (exchange.getStatusCode() >= 400) {

Throwable throwable = exchange.getAttachment(EXCEPTION);
Throwable throwable = exchange.getAttachment(DefaultResponseListener.EXCEPTION);

if( throwable == null )
{
Expand All @@ -70,7 +67,7 @@ public boolean handleDefaultResponse(HttpServerExchange exchange)

if(throwable instanceof IllegalArgumentException )
{
exchange.setResponseCode(StatusCodes.BAD_REQUEST);
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
}

if( ServerPredicates.ACCEPT_XML_EXCLUSIVE_PREDICATE.resolve(exchange) )
Expand Down
21 changes: 3 additions & 18 deletions src/main/java/io/sinistral/proteus/services/AssetsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import com.typesafe.config.Config;

import io.sinistral.proteus.server.endpoints.EndpointInfo;
import io.undertow.predicate.Predicate;
import io.undertow.server.HttpServerExchange;
import io.undertow.predicate.TruePredicate;
import io.undertow.server.RoutingHandler;
import io.undertow.server.handlers.resource.FileResourceManager;
import io.undertow.server.handlers.resource.ResourceHandler;
Expand All @@ -25,21 +24,7 @@
*/
public class AssetsService extends BaseService implements Supplier<RoutingHandler>
{
private static class TruePredicate implements Predicate {

public static final TruePredicate INSTANCE = new TruePredicate();

public static TruePredicate instance() {
return INSTANCE;
}

@Override
public boolean resolve(final HttpServerExchange value) {
return true;
}

}

@Inject
@Named("registeredEndpoints")
protected Set<EndpointInfo> registeredEndpoints;
Expand All @@ -66,9 +51,9 @@ public RoutingHandler get()
final String assetsDirectoryName = serviceConfig.getString("dir") ;
final Integer assetsCacheTime = serviceConfig.getInt("cache.time");

final FileResourceManager fileResourceManager = new FileResourceManager(Paths.get(assetsDirectoryName).toFile(),1024l);
final FileResourceManager fileResourceManager = new FileResourceManager(Paths.get(assetsDirectoryName).toFile());

router.add(Methods.GET, assetsPath + "/*", io.undertow.Handlers.rewrite("regex['" + assetsPath + "/(.*)']", "/$1", getClass().getClassLoader(), new ResourceHandler(fileResourceManager)
router.add(Methods.GET, assetsPath + "/*", io.undertow.Handlers.rewrite("regex('" + assetsPath + "/(.*)')", "/$1", getClass().getClassLoader(), new ResourceHandler(fileResourceManager)
.setCachable(TruePredicate.instance())
.setCacheTime(assetsCacheTime)
));
Expand Down

0 comments on commit 9f83467

Please sign in to comment.