Modify

Opened 7 years ago

Closed 6 years ago

#8606 closed defect (fixed)

For JOSM webstart version the user agent is not set

Reported by: stoecker Owned by: team
Priority: normal Milestone:
Component: Core Version:
Keywords: Cc:

Description

When the webstart is used, the user agent is simply Java/... and no longer the josm agent.

It seems the user agent value is cached somewhere, as the http.agent property is correct, but it is not used.

See also: http://wiki.nikhef.nl/grid/JGridstart/Java_user_agents for a fix (would mean to reintroduce the User-Agent header setting with a slight modification.

Attachments (2)

8606.patch (1.9 KB) - added by stoecker 7 years ago.
8606_ugly.patch (6.9 KB) - added by Don-vip 7 years ago.
Worst Java code I ever wrote

Download all attachments as: .zip

Change History (20)

comment:1 Changed 7 years ago by stoecker

The fix again has the problem, that e.g. the wiki reader uses another user agent in this case.

Changed 7 years ago by stoecker

Attachment: 8606.patch added

comment:2 Changed 7 years ago by Don-vip

Patch looks ok, why did you not commit it ?

comment:3 Changed 7 years ago by stoecker

Because it only fixes a small part of the problem.

comment:4 Changed 7 years ago by stoecker

In 5868/josm:

see #8606 - use JOSM agent also for WebStart, join help browser and WikiReader

comment:5 Changed 7 years ago by stoecker

Still not all. E.g. icons when loading a help page have wrong agent.

comment:6 Changed 7 years ago by Don-vip

In 5873/josm:

see #8571, #8602, #8606: Remove "Operating system" line from status report header as it is now fully included in Agent string

comment:7 in reply to:  5 Changed 7 years ago by Don-vip

Replying to stoecker:

Still not all. E.g. icons when loading a help page have wrong agent.

Yes, reproduced also.

comment:8 Changed 7 years ago by Don-vip

Summary: For JOSM webstart version the user agent is not set[Patch] For JOSM webstart version the user agent is not set

As I understand the problem: When using Web Start, The JVM makes a HTTP request to download our jar file, thus initiates on its own the Java HTTP internal mechanism. This results in running the following code before JOSM starts, in sun.net.www.protocol.http.HttpURLConnection:

    public static final String userAgent;
    static {
        String agent = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("http.agent"));
        if (agent == null) {
            agent = "Java/"+version;
        } else {
            agent = agent + " Java/"+version;
        }
        userAgent = agent;
    }

The variable userAgent is then used to set the User-Agent property for all HTTP connections created by Java. It works as expected when we are not in Web Start, because there is not a single HTTP URL created before we set the Java property "http.agent".

I first thought about modifying this variable using Java reflection, but it is not allowed for static final variables.

I have a working solution (to reproduce the problem and simulate Web Start behaviour, it is enough to add System.out.println(HttpURLConnection.userAgent); as the first instruction run by JOSM in its main method), but it is ugly as hell.

Not sure if there's a simpler and cleaner fix.

Last edited 7 years ago by Don-vip (previous) (diff)

Changed 7 years ago by Don-vip

Attachment: 8606_ugly.patch added

Worst Java code I ever wrote

comment:9 Changed 7 years ago by bastiK

Pretty neat! ;)

An alternative would be to add something like this to the .jnlp file:

    <java>
        <java-vm-args>-Dhttp.agent="JOSM/1.5 r1234"</java-vm-args>
    </java>

(untested)

But this way, we cannot add information like OS and locale, so your solution is probably better.

Last edited 7 years ago by Don-vip (previous) (diff)

comment:10 Changed 7 years ago by stoecker

I think lets wait some days, maybe we'll find a better solution (probably asking at stackoverflow if someone else has a tipp?) and when not use this patch.

comment:11 in reply to:  10 ; Changed 7 years ago by Don-vip

Replying to stoecker:

I think lets wait some days, maybe we'll find a better solution (probably asking at stackoverflow if someone else has a tipp?) and when not use this patch.

I asked on StackOverflow (my first question !). Let's see there...

Last edited 7 years ago by Don-vip (previous) (diff)

comment:12 in reply to:  11 Changed 7 years ago by stoecker

Replying to Don-vip:

Replying to stoecker:

I think lets wait some days, maybe we'll find a better solution (probably asking at stackoverflow if someone else has a tipp?) and when not use this patch.

I asked on StackOverflow (my first question !). Let's see there...

I increased the question value by one :-)

Last edited 7 years ago by Don-vip (previous) (diff)

comment:13 Changed 7 years ago by Don-vip

Thanks :)

comment:14 Changed 7 years ago by Don-vip

In 5887/josm:

see #8606 - Fix user-agent used with JEditorPage.setPage() or JEditorPane(URL) + fix version number from previous commit

comment:15 Changed 7 years ago by Don-vip

In 5898/josm:

see #8606 - Set User-Agent for JMapViewer connections

comment:16 Changed 7 years ago by Don-vip

Looks like there is no easy solution to this problem.
I have manually setup the User-Agent to some other connections.

Are some some connections remaining, apart the <img> resolutions ? If it's the only one that we cannot fix, I think we can live with it, and not apply this patch, as its gain is not worth the risks it introduces.

comment:17 Changed 7 years ago by stoecker

Summary: [Patch] For JOSM webstart version the user agent is not setFor JOSM webstart version the user agent is not set

comment:18 Changed 6 years ago by Don-vip

Resolution: fixed
Status: newclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.