11package javaxt .http ;
22import java .io .*;
33import java .net .*;
4+ import java .util .*;
45import java .text .DateFormat ;
56import java .text .SimpleDateFormat ;
6- import java .util .List ;
7- import java .util .HashMap ;
8- import java .util .ArrayList ;
97import javax .net .ssl .*;
108
119//******************************************************************************
@@ -44,11 +42,11 @@ public class Request {
4442 private String password ;
4543 private String method ;
4644
47- private java . util . Map <String , List <String >> requestHeaders = null ;
45+ private Map <String , List <String >> requestHeaders = null ;
4846 private HashMap <String , List <String >> RequestProperties = new HashMap <>();
4947
5048 //Http response properties
51- private java . util . Map <String , List <String >> headers = null ;
49+ private Map <String , List <String >> headers = null ;
5250 private String protocol ;
5351 private String version ;
5452 private int responseCode ;
@@ -466,14 +464,14 @@ public void write(javaxt.html.Input[] inputs){
466464
467465 //Generate boundary
468466 String boundary = "---------------------------" ;
469- for (int i =0 ; i <14 ; i ++) boundary += new java . util . Random ().nextInt (10 );
467+ for (int i =0 ; i <14 ; i ++) boundary += new Random ().nextInt (10 );
470468 int boundarySize = boundary .length ();
471469
472470 try {
473471
474472 //Compute payload size and generate content metadata for each input
475473 long size = 0 ;
476- java . util . ArrayList <byte []> metadata = new java . util . ArrayList <byte [] >();
474+ ArrayList <byte []> metadata = new ArrayList <>();
477475 for (int i =0 ; i <inputs .length ; i ++){
478476
479477 javaxt .html .Input input = inputs [i ];
@@ -555,7 +553,7 @@ public void write(javaxt.html.Input[] inputs){
555553
556554
557555 public List <String > getHeader (String key ){
558- java . util . Iterator <String > it = RequestProperties .keySet ().iterator ();
556+ Iterator <String > it = RequestProperties .keySet ().iterator ();
559557 while (it .hasNext ()){
560558 String currKey = it .next ();
561559 if (key .equalsIgnoreCase (currKey )){
@@ -573,20 +571,20 @@ public List<String> getHeader(String key){
573571 public void setHeader (String key , String value ){
574572
575573 boolean foundProperty = false ;
576- java . util . Iterator <String > it = RequestProperties .keySet ().iterator ();
574+ Iterator <String > it = RequestProperties .keySet ().iterator ();
577575 while (it .hasNext ()){
578576 String currKey = it .next ();
579577 if (key .equalsIgnoreCase (currKey )){
580578 foundProperty = true ;
581- List <String > values = new ArrayList <String >();
579+ List <String > values = new ArrayList <>();
582580 values .add (value );
583581 RequestProperties .put (currKey , values );
584582 break ;
585583 }
586584 }
587585
588586 if (!foundProperty ){
589- List <String > values = new ArrayList <String >();
587+ List <String > values = new ArrayList <>();
590588 values .add (value );
591589 RequestProperties .put (key , values );
592590 }
@@ -604,13 +602,13 @@ public void addHeader(String key, String value){
604602 }
605603
606604 boolean foundProperty = false ;
607- java . util . Iterator <String > it = RequestProperties .keySet ().iterator ();
605+ Iterator <String > it = RequestProperties .keySet ().iterator ();
608606 while (it .hasNext ()){
609607 String currKey = it .next ();
610608 if (key .equalsIgnoreCase (currKey )){
611609 foundProperty = true ;
612610 List <String > values = RequestProperties .get (currKey );
613- if (values ==null ) values = new ArrayList <String >();
611+ if (values ==null ) values = new ArrayList <>();
614612 values .add (value );
615613 RequestProperties .put (currKey , values );
616614 break ;
@@ -680,14 +678,14 @@ private URLConnection connect(boolean doOutput){
680678
681679 //Set request method as needed
682680 if (method !=null ){
681+ HttpURLConnection con ;
683682 if (ssl ){
684- HttpsURLConnection con = (HttpsURLConnection )conn ;
685- con .setRequestMethod (method );
683+ con = (HttpsURLConnection )conn ;
686684 }
687685 else {
688- HttpURLConnection con = (HttpURLConnection )conn ;
689- con .setRequestMethod (method );
686+ con = (HttpURLConnection )conn ;
690687 }
688+ con .setRequestMethod (method );
691689 }
692690
693691
@@ -729,7 +727,7 @@ private URLConnection connect(boolean doOutput){
729727 String credentials = getCredentials ();
730728 if (credentials !=null ) conn .setRequestProperty ("Authorization" , "Basic " + credentials );
731729
732- java . util . Iterator <String > it = RequestProperties .keySet ().iterator ();
730+ Iterator <String > it = RequestProperties .keySet ().iterator ();
733731 while (it .hasNext ()){
734732 String key = it .next ();
735733 List <String > values = RequestProperties .get (key );
@@ -738,7 +736,7 @@ private URLConnection connect(boolean doOutput){
738736 conn .setRequestProperty (key , values .iterator ().next ());
739737 }
740738 else {
741- java . util . Iterator <String > value = values .iterator ();
739+ Iterator <String > value = values .iterator ();
742740 while (value .hasNext ()){
743741 conn .addRequestProperty (key , value .next ());
744742 }
@@ -858,7 +856,7 @@ private void parseResponse(URLConnection conn){
858856 List status = (List )headers .get (null );
859857 if (status !=null ){
860858
861- java . util . StringTokenizer st = new java . util . StringTokenizer ( (String )(status ).get (0 ) );
859+ StringTokenizer st = new StringTokenizer ( (String )(status ).get (0 ) );
862860 if (st .hasMoreTokens ()) protocol = st .nextToken ().trim ().toUpperCase ();
863861 if (protocol .contains ("/" )) {
864862 String temp = protocol ;
@@ -898,7 +896,7 @@ private Long getExpiration(URLConnection connection, long baseTime) {
898896
899897 String cacheControl = connection .getHeaderField ("Cache-Control" );
900898 if (cacheControl != null ) {
901- java . util . StringTokenizer tok = new java . util . StringTokenizer (cacheControl , "," );
899+ StringTokenizer tok = new StringTokenizer (cacheControl , "," );
902900 while (tok .hasMoreTokens ()) {
903901 String token = tok .nextToken ().trim ().toLowerCase ();
904902 if ("must-revalidate" .equals (token )) {
@@ -966,11 +964,11 @@ protected String getResponseMessage(){
966964 }
967965
968966
969- protected java . util . Map <String , List <String >> getResponseHeaders (){
967+ protected Map <String , List <String >> getResponseHeaders (){
970968 return headers ;
971969 }
972970
973- public java . util . Map <String , List <String >> getRequestHeaders (){
971+ public Map <String , List <String >> getRequestHeaders (){
974972 if (requestHeaders !=null ) return requestHeaders ;
975973 else {
976974 return RequestProperties ;
@@ -983,15 +981,15 @@ protected String[] getResponseHeaders(String headerName){
983981 if (headers ==null ) return new String [0 ];
984982
985983 //Iterate through the headers and find the matching header
986- java . util . ArrayList <String > values = new java . util . ArrayList <String >();
987- java . util . Iterator <String > it = headers .keySet ().iterator ();
984+ ArrayList <String > values = new ArrayList <>();
985+ Iterator <String > it = headers .keySet ().iterator ();
988986 while (it .hasNext ()){
989987 String key = it .next ();
990988 if (key !=null ){
991989 if (key .equalsIgnoreCase (headerName )){
992990
993- java . util . List <String > list = headers .get (key );
994- java . util . Iterator <String > val = list .iterator ();
991+ List <String > list = headers .get (key );
992+ Iterator <String > val = list .iterator ();
995993 while (val .hasNext ()){
996994 values .add (val .next ());
997995 }
@@ -1119,13 +1117,13 @@ public String toString(){
11191117 //System.out.println("Request Header");
11201118 //System.out.println("------------------------------------------------");
11211119out .append (url + "\r \n " );
1122- java . util . Map <String ,List <String >> requestHeaders = getRequestHeaders ();
1120+ Map <String ,List <String >> requestHeaders = getRequestHeaders ();
11231121 if (requestHeaders !=null ){
1124- java . util . Iterator it = requestHeaders .keySet ().iterator ();
1122+ Iterator it = requestHeaders .keySet ().iterator ();
11251123 while (it .hasNext ()){
11261124 String key = (String ) it .next ();
11271125 if (key !=null ){
1128- java . util . List list = (java . util . List ) requestHeaders .get (key );
1126+ List list = (List ) requestHeaders .get (key );
11291127 for (int i =0 ; i <list .size (); i ++){
11301128 String value = list .get (i ).toString ();
11311129 out .append (key + ": " + value + "\r \n " );
0 commit comments