Package org.simpleframework.http

Examples of org.simpleframework.http.Address


        }
    }

    private URI getBaseUri(Request request) {
        try {
            final Address address = request.getAddress();

            return new URI(
                    address.getScheme(),
                    null,
                    address.getDomain(),
                    address.getPort(),
                    "/",
                    null, null);
        } catch (URISyntaxException ex) {
            throw new IllegalArgumentException(ex);
        }
View Full Code Here


        }
    }

    private URI getBaseUri(final Request request) {
        try {
            final Address address = request.getAddress();

            return new URI(
                    address.getScheme(),
                    null,
                    address.getDomain(),
                    address.getPort(),
                    "/",
                    null, null);
        } catch (final URISyntaxException ex) {
            throw new IllegalArgumentException(ex);
        }
View Full Code Here

      res.setValue("Server", "TUCServer/"+StartMain.version+" (theuchain)");
      res.setDate("Date", time);
      res.setDate("Last-Modified", time);
     
     
      Address a = req.getAddress();
     
      // notes: domain is null
     
     
      String[] seg = a.getPath().getSegments();
      if (seg[0].equalsIgnoreCase("res") || seg[0].equalsIgnoreCase("html")) {
       
        File rf = new File("../" + a.getPath().getPath(0));
       
        if (! rf.exists()) {
          res.setCode(404);
          res.setValue("Content-Type", "text/html");
          body.println("<h2>404</h2><br>The resource was not available. This is not intended to be user-browsed. ");
          body.close();
          return;
        }
       
        String ext = a.getPath().getExtension();
        if (ext.equalsIgnoreCase("png")) {
          res.setValue("Content-Type", "image/png");
        } else if (ext.equalsIgnoreCase("gif")) {
          res.setValue("Content-Type", "image/gif");
        } else if (ext.equalsIgnoreCase("jml")) {
          res.setValue("Content-Type", "text/html");
         
        } else {
          res.setCode(500);
          res.setValue("Content-Type", "text/html");
          body.println("<h2>500 Internal TUC Server Error</h2><br>The resource does not have a known MIME-Type, cannot transfer properly. Extension: " + ext);
          body.close();
          return;
        }
       
        // a resource was called!
        // the resources are usually binary files, so we can't copy them
        // as text
       
        // but we will do this with text files anyway, for simplicity
       
        // Get a Stream from the file
        FileInputStream reader = new FileInputStream(rf);
       
            byte[] buffer = new byte[153600];
            int bytesRead = 0;
    
            while ((bytesRead = reader.read(buffer)) > 0)
            { 
              // copy the bytes from the filein stream to the httpout stream
              body.write(buffer, 0, bytesRead);
              buffer = new byte[153600];
            }
           
            body.close(); // Close Stream
            reader.close(); // Close Stream
            return; // Exit from HTTP Processing
      }
     
      String addr = a.toString();
      if (addr.equalsIgnoreCase("/ser")) {
        Player p = new Player("slm", "AUser", 1);
        p.save();
        body.println("Serializing player");
        stdOut.println("Stopping the server...");
View Full Code Here

public class FileIndexerTest extends TestCase {
  
   public void testFileIndexer() {
      FileIndexer indexer = new FileIndexer(new File("."));
      Address address = new AddressParser("/path/index.html");
     
      assertEquals(indexer.getContentType(address), "text/html");
      assertEquals(indexer.getPath(address).getName(), "index.html");
      assertEquals(indexer.getPath(address).getExtension(), "html");
      assertEquals(indexer.getPath(address).getDirectory(), "/path/");
View Full Code Here

        }
    }

    private URI getBaseUri(Request request) {
        try {
            final Address address = request.getAddress();

            return new URI(
                    address.getScheme(),
                    null,
                    address.getDomain(),
                    address.getPort(),
                    "/",
                    null, null);
        } catch (URISyntaxException ex) {
            throw new IllegalArgumentException(ex);
        }
View Full Code Here

       }
    }

    private URI getBaseUri(Request request) {
        try {
            final Address address = request.getAddress();

            return new URI(
                    address.getScheme(),
                    null,
                    address.getDomain(),
                    address.getPort(),
                    "/",
                    null, null);
        } catch (URISyntaxException ex) {
            throw new IllegalArgumentException(ex);
        }
View Full Code Here

TOP

Related Classes of org.simpleframework.http.Address

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.