1
1
package javaxt .http ;
2
2
import java .io .*;
3
3
import java .net .*;
4
+ import java .util .*;
4
5
import java .text .DateFormat ;
5
6
import java .text .SimpleDateFormat ;
6
- import java .util .List ;
7
- import java .util .HashMap ;
8
- import java .util .ArrayList ;
9
7
import javax .net .ssl .*;
10
8
11
9
//******************************************************************************
@@ -44,11 +42,11 @@ public class Request {
44
42
private String password ;
45
43
private String method ;
46
44
47
- private java . util . Map <String , List <String >> requestHeaders = null ;
45
+ private Map <String , List <String >> requestHeaders = null ;
48
46
private HashMap <String , List <String >> RequestProperties = new HashMap <>();
49
47
50
48
//Http response properties
51
- private java . util . Map <String , List <String >> headers = null ;
49
+ private Map <String , List <String >> headers = null ;
52
50
private String protocol ;
53
51
private String version ;
54
52
private int responseCode ;
@@ -466,14 +464,14 @@ public void write(javaxt.html.Input[] inputs){
466
464
467
465
//Generate boundary
468
466
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 );
470
468
int boundarySize = boundary .length ();
471
469
472
470
try {
473
471
474
472
//Compute payload size and generate content metadata for each input
475
473
long size = 0 ;
476
- java . util . ArrayList <byte []> metadata = new java . util . ArrayList <byte [] >();
474
+ ArrayList <byte []> metadata = new ArrayList <>();
477
475
for (int i =0 ; i <inputs .length ; i ++){
478
476
479
477
javaxt .html .Input input = inputs [i ];
@@ -555,7 +553,7 @@ public void write(javaxt.html.Input[] inputs){
555
553
556
554
557
555
public List <String > getHeader (String key ){
558
- java . util . Iterator <String > it = RequestProperties .keySet ().iterator ();
556
+ Iterator <String > it = RequestProperties .keySet ().iterator ();
559
557
while (it .hasNext ()){
560
558
String currKey = it .next ();
561
559
if (key .equalsIgnoreCase (currKey )){
@@ -573,20 +571,20 @@ public List<String> getHeader(String key){
573
571
public void setHeader (String key , String value ){
574
572
575
573
boolean foundProperty = false ;
576
- java . util . Iterator <String > it = RequestProperties .keySet ().iterator ();
574
+ Iterator <String > it = RequestProperties .keySet ().iterator ();
577
575
while (it .hasNext ()){
578
576
String currKey = it .next ();
579
577
if (key .equalsIgnoreCase (currKey )){
580
578
foundProperty = true ;
581
- List <String > values = new ArrayList <String >();
579
+
57AE
List <String > values = new ArrayList <>();
582
580
values .add (value );
583
581
RequestProperties .put (currKey , values );
584
582
break ;
585
583
}
586
584
}
587
585
588
586
if (!foundProperty ){
589
- List <String > values = new ArrayList <String >();
587
+ List <String > values = new ArrayList <>();
590
588
values .add (value );
591
589
RequestProperties .put (key , values );
592
590
}
@@ -604,13 +602,13 @@ public void addHeader(String key, String value){
604
602
}
605
603
606
604
boolean foundProperty = false ;
607
- java . util . Iterator <String > it = RequestProperties .keySet ().iterator ();
605
+ Iterator <String > it = RequestProperties .keySet ().iterator ();
608
606
while (it .hasNext ()){
609
607
String currKey = it .next ();
610
608
if (key .equalsIgnoreCase (currKey )){
611
609
foundProperty = true ;
612
610
List <String > values = RequestProperties .get (currKey );
613
- if (values ==null ) values = new ArrayList <String >();
611
+ if (values ==null ) values = new ArrayList <>();
614
612
values .add (value );
615
613
RequestProperties .put (currKey , values );
616
614
break ;
@@ -680,14 +678,14 @@ private URLConnection connect(boolean doOutput){
680
678
681
679
//Set request method as needed
682
680
if (method !=null ){
681
+ HttpURLConnection con ;
683
682
if (ssl ){
684
- HttpsURLConnection con = (HttpsURLConnection )conn ;
685
- con .setRequestMethod (method );
683
+ con = (HttpsURLConnection )conn ;
686
684
}
687
685
else {
688
- HttpURLConnection con = (HttpURLConnection )conn ;
689
- con .setRequestMethod (method );
686
+ con = (HttpURLConnection )conn ;
690
687
}
688
+ con .setRequestMethod (method );
691
689
}
692
690
693
691
@@ -729,7 +727,7 @@ private URLConnection connect(boolean doOutput){
729
727
String credentials = getCredentials ();
730
728
if (credentials !=null ) conn .setRequestProperty ("Authorization" , "Basic " + credentials );
731
729
732
- java . util . Iterator <String > it = RequestProperties .keySet ().iterator ();
730
+ Iterator <String > it = RequestProperties .keySet ().iterator ();
733
731
while (it .hasNext ()){
734
732
String key = it .next ();
735
733
List <String > values = RequestProperties .get (key );
@@ -738,7 +736,7 @@ private URLConnection connect(boolean doOutput){
738
736
conn .setRequestProperty (key , values .iterator ().next ());
739
737
}
740
738
else {
741
- java . util . Iterator <String > value = values .iterator ();
739
+ Iterator <String > value = values .iterator ();
742
740
while (value .hasNext ()){
743
741
conn .addRequestProperty (key , value .next ());
744
742
}
@@ -858,7 +856,7 @@ private void parseResponse(URLConnection conn){
858
856
List status = (List )headers .get (null );
859
857
if (status !=null ){
860
858
861
- java . util . StringTokenizer st = new java . util . StringTokenizer ( (String )(status ).get (0 ) );
859
+ StringTokenizer st = new StringTokenizer ( (String )(status ).get (0 ) );
862
860
if (st .hasMoreTokens ()) protocol = st .nextToken ().trim ().toUpperCase ();
863
861
if (protocol .contains ("/" )) {
864
862
String temp = protocol ;
@@ -898,7 +896,7 @@ private Long getExpiration(URLConnection connection, long baseTime) {
898
896
899
897
String cacheControl = connection .getHeaderField ("Cache-Control" );
900
898
if (cacheControl != null ) {
901
- java . util . StringTokenizer tok = new java . util . StringTokenizer (cacheControl , "," );
899
+ StringTokenizer tok = new StringTokenizer (cacheControl , "," );
902
900
while (tok .hasMoreTokens ()) {
903
901
String token = tok .nextToken ().trim ().toLowerCase ();
904
902
if ("must-revalidate" .equals (token )) {
@@ -966,11 +964,11 @@ protected String getResponseMessage(){
966
964
}
967
965
968
966
969
- protected java . util . Map <String , List <String >> getResponseHeaders (){
967
+ protected Map <String , List <String >> getResponseHeaders (){
970
968
return headers ;
971
969
}
972
970
973
- public java . util . Map <String , List <String >> getRequestHeaders (){
971
+ public Map <String , List <String >> getRequestHeaders (){
974
972
if (requestHeaders !=null ) return requestHeaders ;
975
973
else {
976
974
return RequestProperties ;
@@ -983,15 +981,15 @@ protected String[] getResponseHeaders(String headerName){
983
981
if (headers ==null ) return new String [0 ];
984
982
985
983
//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 ();
988
986
while (it .hasNext ()){
989
987
String key = it .next ();
990
988
if (key !=null ){
991
989
if (key .equalsIgnoreCase (headerName )){
992
990
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 ();
995
993
while (val .hasNext ()){
996
994
values .add (val .next ());
997
995
}
@@ -1119,13 +1117,13 @@ public String toString(){
1119
1117
//System.out.println("Request Header");
1120
1118
//System.out.println("------------------------------------------------");
1121
1119
out .append (url + "\r \n " );
1122
- java . util . Map <String ,List <String >> requestHeaders = getRequestHeaders ();
1120
+ Map <String ,List <String >> requestHeaders = getRequestHeaders ();
1123
1121
if (requestHeaders !=null ){
1124
- java . util . Iterator it = requestHeaders .keySet ().iterator ();
1122
+ Iterator it = requestHeaders .keySet ().iterator ();
1125
1123
while (it .hasNext ()){
1126
1124
String key = (String ) it .next ();
1127
1125
if (key !=null ){
1128
- java . util . List list = (java . util . List ) requestHeaders .get (key );
1126
+ List list = (List ) requestHeaders .get (key );
1129
1127
for (int i =0 ; i <list .size (); i ++){
1130
1128
String value = list .get (i ).toString ();
1131
1129
out .append (key + ": " + value + "\r \n " );
0 commit comments