> What do you mean:
>> (start with java -d*http.agent*="myAgent" ....)
>
> commandline? as a param with conn url org:h2 ?
No, command line (terminal, console, shell) or starting a process.
> How would I do that on startup with my program?
java -Dhttp.agent="myAgent" -jar yourApplication.jar
Regards,
Thomas
However, you can implement it yourself and expose it to your SQL code
using CREATE ALIAS. See here:
http://www.h2database.com/html/grammar.html#create_alias
e.g.
CREATE ALIAS MATRIX FOR "org.h2.samples.Function.getMatrix"
SELECT * FROM MATRIX(?)
(the quotes must be only around the argument)
For the Streamhandler you can try this:
URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
@Override
public URLStreamHandler createURLStreamHandler(String protocol) {
if (protocol.equalsIgnoreCase("httpwithagent")) {
return new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
URL httpurl = new URL("http", u.getHost(), u.getPort(), u.getFile(),
null);
URLConnection connection = httpurl.openConnection();
connection.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE6.0; Windows NT 5.0)");
return connection;
}
};
}
return null;
}
});
CREATE TABLE RAWDATA (`HTML` CLOB );
INSERT INTO
RAWDATA
(HTML)
VALUES
(SELECT
FILE_READ('httpwithagent://www.google.de/search?q=H2+database',
NULL));
I don't think it make sense to add this to FILE_READ and CSV_READ. The
http.agent system property is a solution, and the URLStreamHandler.
The real solution would be:
> The site returns a "403" HTTP error because a check is made to
> restrict access to "real" browser!
That's no reason to return 403.
Regards,
Thomas