E
Erik
In the following coe, at the indicated line (// <<==) , why would the
the computer jump to "finally" and forget about the following lines ?
Stepping through the code shows that behaviour.
If I take out the "finally" and just "return ret;", it DOES execute
the following lines and it does not jump to any "catch"...
According to the javadoc, PostMethod does not throw any exceptions.
Which sounds weird to me.
import java.io.File;
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.methods.multipart.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
public class CSSValidator {
public boolean validateFile( String fn ) {
boolean ret = false;
try {
PostMethod method;
HttpClient client = new HttpClient();
method = new
PostMethod("http://jigsaw.w3.org/css-validator/validator"); // <<==
method.setRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
method.setRequestHeader("Accept-Language","en-us,en;q=0.5");
method.setRequestHeader("Accept-Encoding","gzip,deflate");
method.setRequestHeader("Accept-CharSet","ISO-8859-1,utf-8;q=0.7,*;q=0.7");
method.setRequestHeader("Referer","http://jigsaw.w3.org/css-validator/");
method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,
false);
Part[] parts = {
new FilePart("file",new File(fn)),
new StringPart("usermedium","all"),
new StringPart("lang","en"),
new StringPart("profile","css21"),
new StringPart("warning","1")
} ;
method.setRequestEntity(new MultipartRequestEntity(parts,
method.getParams()) );
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
int status = client.executeMethod((HttpMethod) method);
if (status == HttpStatus.SC_OK) {
System.out.println("OK");
ret = true;
} else {
System.out.println("Not OK");
}
}
catch (HttpException e) {
System.out.println("ERROR: " + e.getClass().getName() + "
"+ e.getMessage());
e.printStackTrace();
}
catch (IOException ioe) {
System.out.println("ERROR: " + ioe.getClass().getName() +
" "+ ioe.getMessage());
ioe.printStackTrace();
}
catch (Exception ex) {
System.out.println("ERROR: " + ex.getClass().getName() + "
"+ ex.getMessage());
ex.printStackTrace();
}
finally {
return ret;
}
}
}
the computer jump to "finally" and forget about the following lines ?
Stepping through the code shows that behaviour.
If I take out the "finally" and just "return ret;", it DOES execute
the following lines and it does not jump to any "catch"...
According to the javadoc, PostMethod does not throw any exceptions.
Which sounds weird to me.
import java.io.File;
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.methods.multipart.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
public class CSSValidator {
public boolean validateFile( String fn ) {
boolean ret = false;
try {
PostMethod method;
HttpClient client = new HttpClient();
method = new
PostMethod("http://jigsaw.w3.org/css-validator/validator"); // <<==
method.setRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
method.setRequestHeader("Accept-Language","en-us,en;q=0.5");
method.setRequestHeader("Accept-Encoding","gzip,deflate");
method.setRequestHeader("Accept-CharSet","ISO-8859-1,utf-8;q=0.7,*;q=0.7");
method.setRequestHeader("Referer","http://jigsaw.w3.org/css-validator/");
method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,
false);
Part[] parts = {
new FilePart("file",new File(fn)),
new StringPart("usermedium","all"),
new StringPart("lang","en"),
new StringPart("profile","css21"),
new StringPart("warning","1")
} ;
method.setRequestEntity(new MultipartRequestEntity(parts,
method.getParams()) );
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
int status = client.executeMethod((HttpMethod) method);
if (status == HttpStatus.SC_OK) {
System.out.println("OK");
ret = true;
} else {
System.out.println("Not OK");
}
}
catch (HttpException e) {
System.out.println("ERROR: " + e.getClass().getName() + "
"+ e.getMessage());
e.printStackTrace();
}
catch (IOException ioe) {
System.out.println("ERROR: " + ioe.getClass().getName() +
" "+ ioe.getMessage());
ioe.printStackTrace();
}
catch (Exception ex) {
System.out.println("ERROR: " + ex.getClass().getName() + "
"+ ex.getMessage());
ex.printStackTrace();
}
finally {
return ret;
}
}
}