#5824 closed enhancement (fixed)
remotecontrol: add command for opening local files
| Reported by: | Cobra | Owned by: | framm |
|---|---|---|---|
| Priority: | normal | Component: | Core remotecontrol |
| Version: | Keywords: | ||
| Cc: |
Description (last modified by simon04)
It would be quite useful to be able to load files into a running instance of josm.
For example, this would allow to open files from a file manager with josm by using a simple script.
Attachments (2)
Change History (19)
comment:1 Changed 16 months ago by simon04
- Component changed from Core to Core remotecontrol
- Description modified (diff)
- Owner changed from team to framm
comment:2 Changed 16 months ago by simon04
- Summary changed from remotecontrol: add command for opening local files to [Patch] remotecontrol: add command for opening local files
comment:3 Changed 16 months ago by Cobra
simon04, are you sure this is the patch you intended to upload? This is just some netbeans properties stuff...
Changed 16 months ago by simon04
comment:4 Changed 16 months ago by simon04
Cobra: Of course not. :-) I attached the correct patch now (falsely used git diff instead of git diff --staged to generate the patch).
Changed 16 months ago by simon04
comment:5 Changed 15 months ago by simon04
- Resolution set to fixed
- Status changed from new to closed
In 5085/josm:
comment:6 Changed 15 months ago by Cobra
I just tested this and got these two exceptions. After restarting only the first exception was thrown.
GET http://localhost:8111/open_file?filename=/tmp/test.osm OK
Repository Root: http://josm.openstreetmap.de/svn Build-Date: 2012-03-15 02:32:12 Last Changed Author: simon04 Revision: 5086 Repository UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b URL: http://josm.openstreetmap.de/svn/trunk Last Changed Date: 2012-03-14 23:34:54 +0100 (Wed, 14 Mar 2012) Last Changed Rev: 5086 Identification: JOSM/1.5 (5086 en) Memory Usage: 131 MB / 910 MB (35 MB allocated, but free) Java version: 1.6.0_30, Sun Microsystems Inc., Java HotSpot(TM) 64-Bit Server VM Operating system: Linux Dataset consistency test: No problems found Plugin: FastDraw (27981) Plugin: FixAddresses (27907) Plugin: ImportImagePlugin (27906) Plugin: InfoMode (27981) Plugin: PicLayer (27883) Plugin: alignways (27852) Plugin: buildings_tools (27984) Plugin: licensechange (27964) Plugin: measurement (27957) Plugin: openstreetbugs (27852) Plugin: openvisible (27852) Plugin: pdfimport (27867) Plugin: proj4j (27902) Plugin: restart (27852) Plugin: reverter (27865) Plugin: terracer (27852) Plugin: undelete (27852) Plugin: utilsplugin2 (28045) java.lang.NullPointerException at org.openstreetmap.josm.tools.AlphanumComparator.compare(AlphanumComparator.java:75) at org.openstreetmap.josm.gui.DefaultNameFormatter$3.compare(DefaultNameFormatter.java:381) at org.openstreetmap.josm.gui.DefaultNameFormatter$3.compare(DefaultNameFormatter.java:351) at java.util.Arrays.mergeSort(Arrays.java:1293) at java.util.Arrays.mergeSort(Arrays.java:1281) at java.util.Arrays.sort(Arrays.java:1210) at java.util.Collections.sort(Collections.java:159) at org.openstreetmap.josm.gui.dialogs.RelationListDialog$RelationListModel.sort(RelationListDialog.java:644) at org.openstreetmap.josm.gui.dialogs.RelationListDialog$RelationListModel.setRelations(RelationListDialog.java:668) at org.openstreetmap.josm.gui.dialogs.RelationListDialog.initFromLayer(RelationListDialog.java:185) at org.openstreetmap.josm.gui.dialogs.RelationListDialog.dataChanged(RelationListDialog.java:920) at org.openstreetmap.josm.data.osm.event.DataChangedEvent.fire(DataChangedEvent.java:26) at org.openstreetmap.josm.data.osm.event.DatasetEventManager.fireEvents(DatasetEventManager.java:109) at org.openstreetmap.josm.data.osm.event.DatasetEventManager.access$200(DatasetEventManager.java:27) at org.openstreetmap.josm.data.osm.event.DatasetEventManager$1.run(DatasetEventManager.java:139) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646) at java.awt.EventQueue.access$000(EventQueue.java:84) at java.awt.EventQueue$1.run(EventQueue.java:607) at java.awt.EventQueue$1.run(EventQueue.java:605) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:616) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178) at java.awt.Dialog$1.run(Dialog.java:1044) at java.awt.Dialog$3.run(Dialog.java:1096) at java.security.AccessController.doPrivileged(Native Method) at java.awt.Dialog.show(Dialog.java:1094) at java.awt.Component.show(Component.java:1584) at java.awt.Component.setVisible(Component.java:1536) at java.awt.Window.setVisible(Window.java:841) at java.awt.Dialog.setVisible(Dialog.java:984) at org.openstreetmap.josm.gui.ExtendedDialog.setVisible(ExtendedDialog.java:463) at org.openstreetmap.josm.gui.ExtendedDialog.showDialog(ExtendedDialog.java:269) at org.openstreetmap.josm.tools.BugReportExceptionHandler$1.run(BugReportExceptionHandler.java:96) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646) at java.awt.EventQueue.access$000(EventQueue.java:84) at java.awt.EventQueue$1.run(EventQueue.java:607) at java.awt.EventQueue$1.run(EventQueue.java:605) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:616) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178) at java.awt.Dialog$1.run(Dialog.java:1044) at java.awt.Dialog$3.run(Dialog.java:1096) at java.security.AccessController.doPrivileged(Native Method) at java.awt.Dialog.show(Dialog.java:1094) at java.awt.Component.show(Component.java:1584) at java.awt.Component.setVisible(Component.java:1536) at java.awt.Window.setVisible(Window.java:841) at java.awt.Dialog.setVisible(Dialog.java:984) at org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor$4.run(PleaseWaitProgressMonitor.java:170) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646) at java.awt.EventQueue.access$000(EventQueue.java:84) at java.awt.EventQueue$1.run(EventQueue.java:607) at java.awt.EventQueue$1.run(EventQueue.java:605) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:616) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) ...<snip>...
Repository Root: http://josm.openstreetmap.de/svn Build-Date: 2012-03-15 02:32:12 Last Changed Author: simon04 Revision: 5086 Repository UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b URL: http://josm.openstreetmap.de/svn/trunk Last Changed Date: 2012-03-14 23:34:54 +0100 (Wed, 14 Mar 2012) Last Changed Rev: 5086 Identification: JOSM/1.5 (5086 en) Memory Usage: 158 MB / 910 MB (85 MB allocated, but free) Java version: 1.6.0_30, Sun Microsystems Inc., Java HotSpot(TM) 64-Bit Server VM Operating system: Linux Dataset consistency test: No problems found Plugin: FastDraw (27981) Plugin: FixAddresses (27907) Plugin: ImportImagePlugin (27906) Plugin: InfoMode (27981) Plugin: PicLayer (27883) Plugin: alignways (27852) Plugin: buildings_tools (27984) Plugin: licensechange (27964) Plugin: measurement (27957) Plugin: openstreetbugs (27852) Plugin: openvisible (27852) Plugin: pdfimport (27867) Plugin: proj4j (27902) Plugin: restart (27852) Plugin: reverter (27865) Plugin: terracer (27852) Plugin: undelete (27852) Plugin: utilsplugin2 (28045) java.lang.AbstractMethodError at org.openstreetmap.josm.io.remotecontrol.RequestProcessor.run(RequestProcessor.java:185)
comment:7 Changed 15 months ago by simon04
- See #7507
- I'm investigating.
comment:8 Changed 15 months ago by simon04
- I cannot reproduce. I assume, you opened localhost:8111 without any command. When I do so, I do not get this exception. To debug, please try this build with some debugging output: http://osm.simon04.net/josm5824.jar
comment:9 Changed 15 months ago by Cobra
Both exceptions were thrown after the above command. First one, then immediately the other one.
The second one is thrown when "open local files" isn't allowed in the preferences. Above call results in 403 and the second exception.
After enabling "open local files" and without restarting josm (there is no message to do so) this exception is thrown again, but the file is opened correctly.
Even after restarting josm this exception is thrown again (I'm using 5088 SVN now).
So to reproduce disable "open local files", restart josm, re-enable it again and try again.
comment:10 Changed 15 months ago by simon04
- Summary changed from [Patch] remotecontrol: add command for opening local files to remotecontrol: add command for opening local files
Sorry, I still cannot reproduce (tested with GNU/Linux 3.2.9 and OpenSDK 1.7, and Windows XP and Sun/Oracle 1.6).
You could try with an empty preference directory …
comment:11 Changed 15 months ago by Cobra
This happens only when the reverter plugin is installed.
This is the minimal preferences.xml file required to cause this problem:
<?xml version="1.0" encoding="UTF-8"?>
<preferences xmlns="http://josm.openstreetmap.de/preferences-1.0" version="5088">
<list key='plugins'>
<entry value='reverter'/>
</list>
<tag key='remotecontrol.enabled' value='true'/>
<tag key='remotecontrol.permission.open-files' value='true'/>
</preferences>
comment:12 Changed 15 months ago by simon04
- Resolution fixed deleted
- Status changed from closed to reopened
Thanks for this hint – I wasn't aware that other plugins also provide remote control handlers. The code needs some adaptation …
comment:13 Changed 15 months ago by simon04
- Resolution set to fixed
- Status changed from reopened to closed
Fixed in o28089.
comment:14 follow-up: ↓ 16 Changed 15 months ago by Cobra
- Resolution fixed deleted
- Status changed from closed to reopened
This doesn't work for file names containing spaces.
GET http://localhost:8111/open_file?filename=/tmp/test\ file.osm OK
RemoteControl received: GET /open_file?filename=/tmp/test%20file.osm HTTP/1.1 Open file: /tmp/test%20file.osm (0 bytes) java.io.FileNotFoundException: /tmp/test%20file.osm (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:120) at org.openstreetmap.josm.io.OsmImporter.importData(OsmImporter.java:54) at org.openstreetmap.josm.io.FileImporter.importDataHandleExceptions(FileImporter.java:57) at org.openstreetmap.josm.actions.OpenFileAction$OpenFileTask.importData(OpenFileAction.java:328) at org.openstreetmap.josm.actions.OpenFileAction$OpenFileTask.realRun(OpenFileAction.java:271) at org.openstreetmap.josm.gui.PleaseWaitRunnable.doRealRun(PleaseWaitRunnable.java:82) at org.openstreetmap.josm.gui.PleaseWaitRunnable.run(PleaseWaitRunnable.java:145) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) java.io.IOException: File 'test%20file.osm' does not exist. at org.openstreetmap.josm.io.OsmImporter.importData(OsmImporter.java:58) at org.openstreetmap.josm.io.FileImporter.importDataHandleExceptions(FileImporter.java:57) at org.openstreetmap.josm.actions.OpenFileAction$OpenFileTask.importData(OpenFileAction.java:328) at org.openstreetmap.josm.actions.OpenFileAction$OpenFileTask.realRun(OpenFileAction.java:271) at org.openstreetmap.josm.gui.PleaseWaitRunnable.doRealRun(PleaseWaitRunnable.java:82) at org.openstreetmap.josm.gui.PleaseWaitRunnable.run(PleaseWaitRunnable.java:145) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)
josm tries to open the file /tmp/test%20file.osm. If I create this file, josm will open this one correctly.
The file names must be unescaped before trying to open the file.
As a separate point, why does remotecontrol return "OK" even when the command fails due to wrong file names?
comment:15 Changed 15 months ago by simon04
- Resolution set to fixed
- Status changed from reopened to closed
In 5103/josm:
comment:16 in reply to: ↑ 14 ; follow-up: ↓ 17 Changed 15 months ago by simon04
Replying to Cobra:
As a separate point, why does remotecontrol return "OK" even when the command fails due to wrong file names?
The file opening is performed in a separate thread and linked to some UI (progress monitor). Thus exceptions cannot be handled in the remote control. However, just testing for existing files would work to catch the main error source, if needed …
comment:17 in reply to: ↑ 16 Changed 15 months ago by Cobra
Replying to simon04:
Replying to Cobra:
As a separate point, why does remotecontrol return "OK" even when the command fails due to wrong file names?
The file opening is performed in a separate thread and linked to some UI (progress monitor). Thus exceptions cannot be handled in the remote control. However, just testing for existing files would work to catch the main error source, if needed …
That's what suspected. Considering that remotecontrol is used only on the same machine I think it's sufficient to keep the whole process like it is. The user will notice that something failed by a separate error/warning dialog, so I don't see much benefit in adding much more code to give some feedback to the calling application.



Patch attached. This also includes a big refactoring of the remotecontrol package in particular to ease the handling of permission preference.
Nice detail: when Confirm all Remote Control actions manually was enabled, the dialog needed to be answered twice. As nobody complained for months/years, I conclude that nobody uses this feature. :-)