Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. public static void main ( String argv [] ) throws Exception
  2.     {
  3.         String send;
  4.         String rec;
  5.  
  6.         ProtocolResponser protResp = new ProtocolResponser ( "1.1" );
  7.  
  8.         System.out.println ( protResp.formResponse ( 200 ) );
  9.     }
  10.  
  11.  
  12. package nothing;
  13.  
  14. import java.util.Date;
  15. import java.util.HashMap;
  16. import java.util.Map;
  17.  
  18. public class ProtocolResponser
  19. {
  20.     private String version;
  21.     private String server;
  22.  
  23.     private Map < Integer, String >statusCode;
  24.  
  25.     public ProtocolResponser ( String version, String server )
  26.     {
  27.         this.version    = version;
  28.         this.server     = server;
  29.         this.statusCode = new HashMap( );
  30.  
  31.         this.statusCode.put ( 200, "OK" );
  32.         this.statusCode.put ( 202, "Accepted" );
  33.         this.statusCode.put ( 400, "Bad Request" );
  34.     }
  35.  
  36.     public String formResponse ( int code )
  37.     {
  38.         String main = this.formHeaderMain ( code );
  39.         String date = this.formHeaderDate ( );
  40.  
  41.         String resp = main + "\n" +
  42.             date + "\n";
  43.  
  44.         return resp;
  45.     }
  46.  
  47.     private String formHeaderMain ( int code )
  48.     {
  49.         return "HTTP/" + this.version + " " + this.getStatusCode ( code );
  50.     }
  51.  
  52.     private String formHeaderDate ( )
  53.     {
  54.         return "Date: " + new Date ( ).toString ( );
  55.     }
  56.  
  57.     private String formHeaderServer ( )
  58.     {
  59.         return "Server: " + this.server;
  60.     }
  61.  
  62.     private String getStatusCode ( int code )
  63.     {
  64.         return code + " " + this.statusCode.get ( code );
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement