Java Reference
In-Depth Information
iif
(!
"http"
.
equals
(
protocol
)) {
errorResponse
(
401
,
"protocol not supported: "
+
requestURL
);
clntSock
.
close
();
return
return
;
}
returnURL
(
url
,
os
);
os
.
flush
();
clntSock
.
close
();
System
.
out
.
println
(
"END OF REQUEST"
);
}
catch
catch
(
FileNotFoundException e
) {
errorResponse
(
404
,
"Server can't find "
+
requestURL
);
}
catch
catch
(
IOException e
) {
errorResponse
(
500
,
"IO Error on proxy"
);
System
.
out
.
println
(
"IOException "
+
e
);
e
.
printStackTrace
();
}
}
private
private
void
void
returnURL
(
URL url
,
PrintStream os
)
throws
throws
IOException
{
InputStream is
=
url
.
openStream
();
int
int
c
;
while
while
((
c
=
is
.
read
()) != -
1
) {
os
.
write
(
c
);
}
}
/** Sends an error response, by number, hopefully localized. */
protected
protected
void
void
errorResponse
(
final
final
int
int
errNum
,
final
final
String errMsg
) {
// Check for localized messages
ResourceBundle messages
=
null
null
;
try
try
{
messages
=
ResourceBundle
.
getBundle
(
"errors"
);
}
catch
catch
(
MissingResourceException e
) {
System
.
err
.
println
(
e
);
}
String response
=
errMsg
;
iif
(
messages
!=
null
null
) {
try
try
{
response
=
messages
.
getString
(
Integer
.
toString
(
errNum
));
}
catch
catch
(
MissingResourceException e
) {
response
=
errMsg
;