Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StaticServer fails while running on windows #34

Closed
ashertarno opened this issue Jan 18, 2015 · 5 comments
Closed

StaticServer fails while running on windows #34

ashertarno opened this issue Jan 18, 2015 · 5 comments

Comments

@ashertarno
Copy link

static files are allocated using vertx-core's FileResolver which in its turn uses java's Path.resolve().
on windows, WindowsPath.resolve() implementation returns a path with slashes (vs backslashes on linux). while used by URL class, slashes become urlencoded and are turning into %5C. as a result of it in FileResolver line 111 a NoSuchFileException is thrown in attempt to allocate a file with a path like webroot%5Cweb%5Cindex.html

@purplefox
Copy link
Contributor

Thanks. Do you have a reproducer?

@ashertarno
Copy link
Author

not something to copy paste in here, but any attempt to use StaticServer.staticServer() handler on windows should fail due to this.

@purplefox
Copy link
Contributor

If you could put together a simple test that exhibits the issue it would be a lot easier for me to track this down.

@ashertarno
Copy link
Author

ok. below is a simple server for static files handling. the static server reads files from /webRoot/web/
trying to call localhost:8888/web/example.html
on linux all works good, the static file is returned as expected. on windows i get 500, while debugging i see the exception the follows the code.

//==================

package just.playing.vertx;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.ext.apex.addons.Favicon;
import io.vertx.ext.apex.addons.StaticServer;
import io.vertx.ext.apex.core.FailureRoutingContext;
import io.vertx.ext.apex.core.Router;
import io.vertx.ext.apex.core.RoutingContext;

public class ApexVerticle extends AbstractVerticle {

public void start( Future<Void> startFuture ) {

    Router router = Router.router( vertx );

    router.route()
          .handler( Favicon.favicon() );

    router.routeWithRegex( "/web/*" )
          .handler( StaticServer.staticServer()
                                .setDirectoryListing( false ) )
          .failureHandler( ( FailureRoutingContext context ) -> {

              context.response()
                     .setStatusCode( 404 )
                     .end();
          } );

    router.route()
          .handler( ( RoutingContext context ) -> {

              context.fail( 404 );
          } );


    //server
    vertx.createHttpServer( new HttpServerOptions().setPort( 8888 ) )
         .requestHandler( router::accept )
         .listen( ( AsyncResult<HttpServer> event ) -> {
             System.out.println( "Server is up" );
         } );
}

}

//=====

on windows machine only:

java.nio.file.NoSuchFileException: C:\Users\atarno\apex-files\webroot%5cweb%5cexample.html
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileCopy.copy(WindowsFileCopy.java:99)
at sun.nio.fs.WindowsFileSystemProvider.copy(WindowsFileSystemProvider.java:278)
at java.nio.file.Files.copy(Files.java:1274)
at io.vertx.core.impl.FileResolver.unpackFromFileURL(FileResolver.java:107)
at io.vertx.core.impl.FileResolver.resolveFile(FileResolver.java:89)
at io.vertx.core.impl.VertxImpl.resolveFile(VertxImpl.java:603)
at io.vertx.core.file.impl.FileSystemImpl$6.perform(FileSystemImpl.java:517)
at io.vertx.core.file.impl.FileSystemImpl$6.perform(FileSystemImpl.java:514)
at io.vertx.core.file.impl.FileSystemImpl.propsBlocking(FileSystemImpl.java:150)
at io.vertx.ext.apex.addons.impl.StaticServerImpl.getFileProps(StaticServerImpl.java:203)
at io.vertx.ext.apex.addons.impl.StaticServerImpl.handle(StaticServerImpl.java:160)
at io.vertx.ext.apex.addons.impl.StaticServerImpl.handle(StaticServerImpl.java:51)
at io.vertx.ext.apex.core.impl.RouteImpl.handleContext(RouteImpl.java:174)
at io.vertx.ext.apex.core.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:69)
at io.vertx.ext.apex.core.impl.RoutingContextImpl.next(RoutingContextImpl.java:94)
at io.vertx.ext.apex.addons.impl.FaviconImpl.handle(FaviconImpl.java:161)
at io.vertx.ext.apex.addons.impl.FaviconImpl.handle(FaviconImpl.java:33)
at io.vertx.ext.apex.core.impl.RouteImpl.handleContext(RouteImpl.java:174)
at io.vertx.ext.apex.core.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:69)
at io.vertx.ext.apex.core.impl.RoutingContextImpl.next(RoutingContextImpl.java:94)
at io.vertx.ext.apex.core.impl.RouterImpl.accept(RouterImpl.java:56)
...
at io.vertx.core.http.impl.ServerConnection.handleRequest(ServerConnection.java:253)
at io.vertx.core.http.impl.ServerConnection.processMessage(ServerConnection.java:355)
at io.vertx.core.http.impl.ServerConnection.handleMessage(ServerConnection.java:129)
at io.vertx.core.http.impl.HttpServerImpl$ServerHandler.createConnAndHandle(HttpServerImpl.java:569)
at io.vertx.core.http.impl.HttpServerImpl$ServerHandler.doMessageReceived(HttpServerImpl.java:495)
at io.vertx.core.http.impl.HttpServerImpl$ServerHandler.doMessageReceived(HttpServerImpl.java:429)
at io.vertx.core.http.impl.VertxHttpHandler.channelRead(VertxHttpHandler.java:76)
at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:131)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:161)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
at io.vertx.core.http.impl.cgbystrom.FlashPolicyHandler.channelRead(FlashPolicyHandler.java:69)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
at java.lang.Thread.run(Thread.java:745)

@purplefox
Copy link
Contributor

Ok, thanks. This should be fixed now (in vertx-core).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants