You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

1

Thursday, February 9th 2012, 5:01pm

Http User Agent - conn.setRequestProperty() how to set globaly

Hey everybody,

I am fetching data from a website via the H2 databaseengine and the FILE_READ('http://...') functionality in my
SQL statement.

The site returns a "403" HTTP error because a check is made to
restrict access to "real" browser!

Now the databaseengine establishes the connection to the website so I can not set the conn.setRequestProperty here!

Is there a way to globally set that information when starting my Jabaco Program?

This does NOT work:

Source code

1
System.setProperty ("http.agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");

This works for a BufferedReader not using H2:

Source code

1
2
3
4
5
URL urlObject = new URL(urlString);
URLConnection conn = urlObject.openConnection();
conn.setRequestProperty ( "User-Agent", "Mozilla/4.0 (compatible; MSIE
6.0; Windows NT 5.0)" );
MyInputStream = conn.getInputStream();



I found information to:

Source code

1
2
3
(start with java -d*http.agent*="myAgent" ....) 

>java "-Dhttp.agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" MyClass


I just do not know how to use this with Jabaco...?

Thanks for any advice...

Dani

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

2

Saturday, February 11th 2012, 12:23am

Hi Dani!

I have no experiences in that area.

But bacause you write something in Java, it could be helpful to ask in a Java Forum.
And because you are from germany, I can recommend you http://www.java-forum.org/ , which is in german and which I have also many times contacted for questions.

Greatings
theuserbl

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

3

Saturday, February 11th 2012, 10:45am

Thanks theuserbl,

I already asked in the H2 forum because I was hoping to be able to get a handle on the internal http connection H2 establishes!
Unfortunately that is not possible.

But there were some recommendations:

Source code

1
2
3
4
You can try to set the default java useragent:
http://docs.oracle.com/javase/1.4.2/docs/guide/net/properties.html
(start with java -d*http.agent*="myAgent" ....) alternativly cou can
provide a cstom URL sceme. 


I also quoted my source for a stream reader as Java syntax to state a working sample for better understanding!

I was hoping here to get an answere to the question:

Is it possible within a Jabaco project, the IDE, to set startup parameters?

As far as I understand:

Source code

1
>java "-Dhttp.agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" MyClass


would be a commandline parameter for Java to start my app with a preset http_agent!
Is there some place in the Jabaco Project Explorer or in the code (Sub_Main possibly!?) to set such parameter;
to tell Java to start my .jar file with this option?

-----------------------

Also theuserbl,
since you are probably the only one left around here who has considerably knowledge about the Jabaco framework,
did you happen to look at my post:

http://www.jabaco.org/board/770-jbdialog…uplocation.html

Do you have any thoughts or even solution for that?

I know you have provided many hints on how to compile the framework.
Would you mind to give me a rough scetch on how to do that again?
This is what I fetched from the forum so far:

1. Compile with the Java compiler Javac all in the directory VBA Framework\src
go to the directory "Framework\src" of the Framework-> tell javac VBA\*.java
That compiles all files there
2. Delete all *.java files in VBA, because you need for the jar-file only the just compiled binaries
3. Copy the complete VBA directory in a new directory and copy all in "framework\lib" in the same directory
4. After that the directories and files in your new directory have to look like:
\META-INF
\com
\eaio
NativeCall.dll
\net
\VBA
5. Now input it completly in a Zip archive rename it to Jabaco.jar
-----------------------
6. Load the file "FrameworkTest.jba" in the directory VB of the Jabaco-Framework in your Jabaco-IDE
7. Compile it with Jabaco
-----------------------
OK, so far?
I have 2 .jar files now what? Do I copy the content of both files into one file?
You mentioned her:
http://www.jabaco.org/board/p2145-proble…k.html#post2145
to compile it again...
I am getting confused from here on.

I will post a step by step Anleitung when I get this figured out!?


Dani

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

4

Saturday, February 11th 2012, 11:46am

Also theuserbl,
since you are probably the only one left around here who has considerably knowledge about the Jabaco framework,
did you happen to look at my post:

http://www.jabaco.org/board/770-jbdialog…uplocation.html

Do you have any thoughts or even solution for that?
Currently not. At the moment I haven't looked deep at it.

But when the dialog ist first at the wrong position and then on the right one, it have probably to do with fireLoaded:
http://code.google.com/p/jabacoframework…actForm.jsrc#44

I think in Java some window-information you can only become, if you already have created the window.
And fireLoaded() do everything after the window is created. For example: resizing, new position, etc.
Possibly the information can be become before. But as Manuel Jabaco 1.5.2 wrote, he don't know. And currently I don't know how to do it, too.

Quoted

I know you have provided many hints on how to compile the framework.
Would you mind to give me a rough scetch on how to do that again?
This is what I fetched from the forum so far:

1. Compile with the Java compiler Javac all in the directory VBA Framework\src
go to the directory "Framework\src" of the Framework-> tell javac VBA\*.java
That compiles all files there
2. Delete all *.java files in VBA, because you need for the jar-file only the just compiled binaries
3. Copy the complete VBA directory in a new directory and copy all in "framework\lib" in the same directory
4. After that the directories and files in your new directory have to look like:
\META-INF
\com
\eaio
NativeCall.dll
\net
\VBA
5. Now input it completly in a Zip archive rename it to Jabaco.jar
And then you have to replace your Jabaco.jar in your Jabaco-directory with this one.
Your new Jabaco.jar is then the new Jabaco-framework version without the files in the directory VB (like Form, Dialog, etc).
So you can create Console Applications now, but no typical Jabaco GUI programs.

To create the files in VB you have to do the fowllowing (but you needed to create the Jabaco.jar without the VB-files before, because the VB-files are dependend on the other files):

Quoted

6. Load the file "FrameworkTest.jba" in the directory VB of the Jabaco-Framework in your Jabaco-IDE
7. Compile it with Jabaco
When you have compiled it, you have for example a file called "FrameworkTest.jar".
In this file are
- all the parts of your before created Jabaco.jar
- all compiled files in VB for the framework
- a big example program, which comes with the framework.

So you can already start then FrameworkTest.jar. It is a executable jar file (a program). But it have too much files to be only a library.
a) So, take a program, which can bowse an modyfy zip files, and delete in the zip file all files in the top-directory WITHOUT NativeCall.dll.
b) Delete the complete directory /res in the zip file.
c) delete the file MANIFEST.MF in the META-INF diretory.
d) rename your FrameworkTest.jar file to Jabaco.jar
e) replace now again the Jabaco.jar in the Jabaco-directory with your now new created Jabaco.jar

Hope it helps.

Greatings
theuserbl

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

5

Saturday, February 11th 2012, 11:53am

Quoted

6. Load the file "FrameworkTest.jba" in the directory VB of the Jabaco-Framework in your Jabaco-IDE
7. Compile it with Jabaco
Important: Don't compile direct after loading FrameworkTest.jba in the IDE.
Jabaco have a bug, so that it don't compile correct.
So
- load FrameworkTest.jba in your IDE
- waint until you can navigate with your cursor keys in the IDE (!)
- now you can compile the program

Greatings
theuserbl

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

6

Saturday, February 11th 2012, 12:38pm

I will try compiling a Jabaco.jar next week.
I don't have the time this weekend!!
So I might get back to you if I get stuck at any point...

Regarding the dialog matter:

I am just wondering how come that when I creat a bordeless form1 / dialog1:

Jabaco Source

1
.BorderStyle = vbBSNone


the form / dialog does open as a startupscreen on top of my main form without the popup effect!!?

It seems possible to get that behavior.
So we have to find the piece of code in the framework where a .BorderStyle = vbBSNone form / dialog is beeing adressed to .show() and look up how its done!?

Sounds too easy does'nt it.


Well anyways, have a nice weekend and thanks...


Dani

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

7

Saturday, February 11th 2012, 6:36pm

One reason why fireLoaded() exists is BECAUSE the windows having frames.

For example:
If you write in Java

Jabaco Source

1
2
3
JFrame f = new JFrame("My Window");
f.setSize(400,300);
f.setVisible(true);
your window WITH its frame is 400 pixel width and 300 pixel height.

If you set in Jabaco the size of a Jabaco Form with width 400 and height 300, then it is the size in the frame. Without the platformdependent decorations.

In Java existing for example an other possibility to do this behavior:

Jabaco Source

1
2
3
4
5
JFrame f = new JFrame("My Window");
p = new JPanel();
p.setPreferredSize(new Dimension(400,300));
f.add(p);
f.setVisible(true);

But that solution works not so good like that of Jabacos implementation, I think.

I think Jabaco ask in its framework, how big the frame around a window is. And I think, this is only possible, after the window is created.

For example what is my understanding, what the Jabaco Framework do:
1. creating the window. For example the window with frame to 400x300.
2. ask the program, how width is the left frame side. How width the right frame side. How hight the top frame size and how height the bottom frame size.
3. resize the window: f.setSize(400+leftWidth+rightWidth, 300+topHeight+bottomHeight);

Thats for resizing. And possible with the window position it is similar.

Greatings
theuserbl

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

8

Tuesday, February 21st 2012, 6:41pm

@ my initial Post of this thread

When I use a .bat file to start my.jar:

Source code

1
2
3
4
5
@echo off

start /B javaw -Dhttp.agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -jar -Xms16m -Xmx512m my.jar

@echo on


I can successfully fetch that site from within my H2 database!!
I am wondering why this does not work though:

Source code

1
System.setProperty ("http.agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)")


Is there some way to set that as a startup parameter within the .jar file/folder, in the manifest file maybe?
But not via a .bat file...

Dani

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

9

Wednesday, February 22nd 2012, 12:33am

Hmmm.. don't know, why it don't work. But it should do:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
* Listing1604.java */

import java.util.*;

public class Listing1604
{
  public static void main(String[] args)
  {
    System.setProperty ("http.agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");

    Properties sysprops   = System.getProperties();
    Enumeration propnames = sysprops.propertyNames();
    while (propnames.hasMoreElements()) {
      String propname = (String)propnames.nextElement();
      System.out.println(
        propname + "=" + System.getProperty(propname)
      );
    }
  }
}
(Modified Listing of http://www.javabuch.de/)

It works perfect.
Addistional you can run the program with
java -Dhttp.agent2="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" Listing1604
and then both properties exists:

Jabaco Source

1
2
http.agent2=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
http.agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)


So I don't know, why it don't work.

But possible it helps, if you output the "http.agent" property in your program.
It seems, that the -D option have a very low range, It only works, if the property don't exists.
Running the mentioned program with:
java -Dhttp.agent="something other" Listing1604
it still outputs

Jabaco Source

1
http.agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)


Possible after you set your property with System.setProperty() it is later changed.
Or runs your program already ok, if you don't set that property?

Greatings
theuserbl

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

10

Wednesday, February 22nd 2012, 10:33am

Hey there theuserbl,

you are right it does work, but not for every site!

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Option Explicit
Public Sub Command1_Click()
   java#lang#Class.forName("org.h2.Driver")
   Dim conn As Connection 
   Dim qry As String 
   Dim st As java#sql#Statement 
   Dim rs As ResultSet
   Dim UserAgent As Boolean = True
   conn = DriverManager.getConnection("jdbc:h2:C:\test", "xy", "xyz")
   st = conn.createStatement()
   If UserAgent = True Then 
      System.setProperty("http.agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)")
      System.setProperty("http.agent2", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)")
   Else
      System.setProperty("http.agent", "")
      System.setProperty("http.agent2", "")
      'java.io.IOException: Server returned HTTP response code: 403
   End If
   Debug.Print  System.getProperty("http.agent")
   Debug.Print  System.getProperty("http.agent2")
   st.executeUpdate("DROP TABLE IF EXISTS RAWDATA;")
   qry = "CREATE MEMORY TABLE RAWDATA (HTML CLOB);"
   st.executeUpdate(qry)               
   qry = "INSERT INTO RAWDATA (HTML) VALUES " & _
         "(SELECT FILE_READ('http://www.onvista.de/aktien/realtime.html?WKN=840400', NULL));" 
'         "(SELECT FILE_READ('http://www.google.de/search?q=H2+database', NULL));" 
'         "(SELECT FILE_READ('http://www.jabaco.org', NULL));" 
   st.executeUpdate(qry)
   rs = st.executeQuery("SELECT * FROM RAWDATA;")                    
   Do While rs.next()
      Me.Caption = "success " & Left(rs.getString("HTML"),10) & "..."
   Loop
End Sub


assuming the org.h2.Driver .jar. is present on your system, e.g.:
C:\Programme\Java\jre6\lib\ext\h2-1.3.164.jar

Google needs the http.agent to be set and the above sample works just fine for Google.
But onvista will not load...

Maybe I am on the wrong track here and there is some other reason why it won't load.
I am getting the same ErrorMsg as if the http.agent is not set though:

Quoted

java.io.IOException: Server returned HTTP response code: 403



Dani

Rate this thread
WoltLab Burning Board