0

I'm pretty excited about using Netty in the project I'm working on, but under a lot of pressure to come up to speed quickly. I'm an experienced Java programmer but don't have much experience in writing client-server systems.

I'm working thru the netty examples, but find that there is not much documentation on how to properly run them. Admittedly, it is useful digging thru the source code, but I've hit the wall with that approach when I got to the HttpStaticFileServer. The client request presumably is from telnet, but I have no idea what the format is for the file request itself and I have tried a few. The Handler codec doesn't make it at all clear. So in general, it would be nice if there is a set of instructions on how to run the example. I promise I will be watching the entire process in the debugger, so I can follow what exactly is going on. So for the moment, at least, I would appreciate a simple example for the FileServer. The application I want to build will be built from that I suspect. Thanks for the help!

Mariana B.
  • 437
  • 5
  • 14
  • I have also tried using the browser in making my request, selecting the URL: http://127.0.0.1:8080. This gives me a Forbidden 403. Sorry....I feel like this is some kind of initiation ceremony and I guess I've failed. But a simple one line example would REALLY help... – user1470481 Jun 21 '12 at 02:08
  • 1
    I moved on to the HttpUploadServer and was able to figure that one out...so again as a suggestion in the documentation for this example, please add a UploadClient argument example description "HTTP://localhost:8080/ /c:/test.txt" – user1470481 Jun 21 '12 at 02:32

2 Answers2

1

HttpStaticFileServer will serve files from your file system.

See HttpStaticFileServerHandler..sanitizeUri(). This is where it maps the virtual path you enter into a browser into a physical path.

So http://localhost:8080/afile.txt will map to ~/afile.txt. Just put afile.txt there and it should show up in your browser.

You may want to try the Snoop example first. I load netty up in eclipse (remember to use JDK7) and run/debug the example app.

Veebs
  • 2,390
  • 13
  • 10
0

I ran HttpStaticFileServer on Windows with Eclipse.


To test the example follow these simple steps:

  1. run the server
  2. type in a web browser: localhost:8080/file.ext (replace file.ext with your file)

The file should be in the System.getProperty("user.dir")

See the answer on how that works here

For me it points to the eclipse workspace directory. So, ether use the workspace or change the sanitizeUri(String uri) method in the HttpStaticFileServerHandler to return:

 rootPath + File.separator + uri;

instead of

 return System.getProperty("user.dir") + File.separator + uri;

where rootPath is the path to the root directory of the file server.

Community
  • 1
  • 1
Mariana B.
  • 437
  • 5
  • 14