Modify

Opened 11 years ago

Closed 11 years ago

Last modified 4 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 Webstart 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 11 years ago.
8606_ugly.patch (6.9 KB ) - added by Don-vip 11 years ago.
Worst Java code I ever wrote

Download all attachments as: .zip

Change History (21)

comment:1 by stoecker, 11 years ago

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

by stoecker, 11 years ago

Attachment: 8606.patch added

comment:2 by Don-vip, 11 years ago

Patch looks ok, why did you not commit it ?

comment:3 by stoecker, 11 years ago

Because it only fixes a small part of the problem.

comment:4 by stoecker, 11 years ago

In 5868/josm:

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

comment:5 by stoecker, 11 years ago

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

comment:6 by Don-vip, 11 years ago

In 5873/josm:

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

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

Replying to stoecker:

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

Yes, reproduced also.

comment:8 by Don-vip, 11 years ago

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 11 years ago by Don-vip (previous) (diff)

by Don-vip, 11 years ago

Attachment: 8606_ugly.patch added

Worst Java code I ever wrote

comment:9 by bastiK, 11 years ago

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 11 years ago by Don-vip (previous) (diff)

comment:10 by stoecker, 11 years ago

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.

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

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 11 years ago by Don-vip (previous) (diff)

in reply to:  11 comment:12 by stoecker, 11 years ago

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 :-)

Version 0, edited 11 years ago by stoecker (next)

comment:13 by Don-vip, 11 years ago

Thanks :)

comment:14 by Don-vip, 11 years ago

In 5887/josm:

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

comment:15 by Don-vip, 11 years ago

In 5898/josm:

see #8606 - Set User-Agent for JMapViewer connections

comment:16 by Don-vip, 11 years ago

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 by stoecker, 11 years ago

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

comment:18 by Don-vip, 11 years ago

Resolution: fixed
Status: newclosed

comment:19 by Don-vip, 4 years ago

Component: CoreCore Webstart

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. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.