From: <jum...@li...> - 2017-08-10 13:43:04
|
Revision: 5486 http://sourceforge.net/p/jump-pilot/code/5486 Author: edso Date: 2017-08-10 13:43:01 +0000 (Thu, 10 Aug 2017) Log Message: ----------- fix NPE in WMS/WFS when network timeout was unset java.lang.NullPointerException at com.vividsolutions.wms.AbstractWMSRequest.prepareConnection(AbstractWMSRequest.java:79) at com.vividsolutions.wms.AbstractWMSRequest.getConnection(AbstractWMSRequest.java:105) at com.vividsolutions.wms.WMService.initialize(WMService.java:141) Modified Paths: -------------- core/trunk/src/com/vividsolutions/jump/workbench/ui/network/ProxySettingsOptionsPanel.java core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/OptionsPlugIn.java core/trunk/src/com/vividsolutions/wms/AbstractWMSRequest.java core/trunk/src/de/latlon/deejump/wfs/client/WFSHttpClient.java Modified: core/trunk/src/com/vividsolutions/jump/workbench/ui/network/ProxySettingsOptionsPanel.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/workbench/ui/network/ProxySettingsOptionsPanel.java 2017-08-10 09:16:39 UTC (rev 5485) +++ core/trunk/src/com/vividsolutions/jump/workbench/ui/network/ProxySettingsOptionsPanel.java 2017-08-10 13:43:01 UTC (rev 5486) @@ -50,6 +50,8 @@ import java.net.URL; import java.net.URLConnection; import java.net.UnknownHostException; +import java.text.NumberFormat; +import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -65,6 +67,7 @@ import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; +import javax.swing.JFormattedTextField; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -75,6 +78,7 @@ import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import javax.swing.text.NumberFormatter; import org.apache.commons.lang3.StringUtils; import org.saig.core.gui.swing.sldeditor.util.FormUtils; @@ -89,11 +93,7 @@ import com.vividsolutions.jump.workbench.Logger; import com.vividsolutions.jump.workbench.ui.OptionsPanelV2; import com.vividsolutions.jump.workbench.ui.images.IconLoader; -import java.text.NumberFormat; -import java.text.ParseException; -import java.util.Formatter; -import javax.swing.JFormattedTextField; -import javax.swing.text.NumberFormatter; +import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn; /** * Allows to configure the network connection (through a proxy HTTP or SOCKS) @@ -112,11 +112,6 @@ /** long serialVersionUID field */ private static final long serialVersionUID = 1L; - /** default values for timeouts */ - private static final int DEFAULT_TIMEOUT_OPEN = 5000; - private static final int DEFAULT_TIMEOUT_READ = 20000; - - /** Panel icon */ public final static Icon ICON = IconLoader.icon("fugue/globe-network.png"); @@ -129,9 +124,16 @@ .getName() + "-TestUrl"; public final static String READ_TIMEOUT_KEY = ProxySettingsOptionsPanel.class .getName() + "-ReadTimeout"; - public final static String CONNECTION_TIMEOUT_KEY = ProxySettingsOptionsPanel.class + public final static String OPEN_TIMEOUT_KEY = ProxySettingsOptionsPanel.class .getName() + "-ConnectionTimeout"; + /** default values for timeouts */ + private static HashMap defaultValues = new HashMap<String, Object>(); + static{ + defaultValues.put(READ_TIMEOUT_KEY, 5000); + defaultValues.put(OPEN_TIMEOUT_KEY, 20000); + } + /** Connection status icons and labels */ public final static Icon SUCCESSFULL_CONNECTION_ICON = IconLoader .icon("saig/internet_connection_ok.png"); @@ -149,6 +151,8 @@ private final static String[] uservars = new String[]{ "User", "user" , "UserName", "Username", "username" }; private final static String[] passvars = new String[] { "Pass", "pass", "PassWord", "Password", "password" }; + private static ProxySettingsOptionsPanel instance = null; + /** Test connection panel */ private JPanel testConnectionPanel; private JButton testConnectionButton; @@ -194,7 +198,7 @@ /** * @param bb blackboard */ - public ProxySettingsOptionsPanel(Blackboard bb) { + private ProxySettingsOptionsPanel(Blackboard bb) { this.blackboard = bb; this.setLayout(new GridBagLayout()); @@ -471,22 +475,8 @@ testUrlTextField.setText(DEFAULT_TEST_URL); // recover new timeout values - Integer connectionTimeout = (Integer) blackboard.get(CONNECTION_TIMEOUT_KEY); - if (connectionTimeout != null) - connectionTimeoutTextField.setText(connectionTimeout.toString()); - else - connectionTimeoutTextField.setText( - String.valueOf( - ProxySettingsOptionsPanel.DEFAULT_TIMEOUT_OPEN)); - - Integer readTimeout = (Integer) blackboard.get(READ_TIMEOUT_KEY); - if (readTimeout != null) - readTimeoutTextField.setText(readTimeout.toString()); - else - readTimeoutTextField.setText( - String.valueOf( - ProxySettingsOptionsPanel.DEFAULT_TIMEOUT_READ)); - + connectionTimeoutTextField.setText(getSetting(OPEN_TIMEOUT_KEY).toString()); + readTimeoutTextField.setText(getSetting(READ_TIMEOUT_KEY).toString()); refreshEditability(); @@ -526,16 +516,16 @@ readTimeout = NumberFormat.getInstance().parse( readTimeoutTextField.getText().trim()).intValue(); } catch (ParseException pe) { - readTimeout = ProxySettingsOptionsPanel.DEFAULT_TIMEOUT_READ; + readTimeout = Integer.parseInt(defaultValues.get(READ_TIMEOUT_KEY).toString()); } try { cnxTimeout = NumberFormat.getInstance().parse( connectionTimeoutTextField.getText().trim()).intValue(); } catch (ParseException pe) { - cnxTimeout = ProxySettingsOptionsPanel.DEFAULT_TIMEOUT_OPEN; + cnxTimeout = Integer.parseInt(defaultValues.get(OPEN_TIMEOUT_KEY).toString()); } blackboard.put(READ_TIMEOUT_KEY, readTimeout); - blackboard.put(CONNECTION_TIMEOUT_KEY, cnxTimeout); + blackboard.put(OPEN_TIMEOUT_KEY, cnxTimeout); } /** @@ -707,23 +697,10 @@ } private void tuneConnection(URLConnection con) { - Integer readTimeout = null; - Integer cnxTimeout = null; - try { - readTimeout = NumberFormat.getInstance().parse( - readTimeoutTextField.getText().trim()).intValue(); - } catch (ParseException pe) { - readTimeout = ProxySettingsOptionsPanel.DEFAULT_TIMEOUT_READ; - } - try { - cnxTimeout = NumberFormat.getInstance().parse( - connectionTimeoutTextField.getText().trim()).intValue(); - } catch (ParseException pe) { - cnxTimeout = ProxySettingsOptionsPanel.DEFAULT_TIMEOUT_OPEN; - } - - con.setConnectTimeout(cnxTimeout); - con.setReadTimeout(readTimeout); + con.setConnectTimeout(Integer.parseInt( + ProxySettingsOptionsPanel.getInstance().getSetting(ProxySettingsOptionsPanel.OPEN_TIMEOUT_KEY).toString())); + con.setReadTimeout(Integer.parseInt( + ProxySettingsOptionsPanel.getInstance().getSetting(ProxySettingsOptionsPanel.READ_TIMEOUT_KEY).toString())); con.setUseCaches(false); } @@ -859,6 +836,15 @@ return formatter; } + public static ProxySettingsOptionsPanel getInstance(){ + if (instance == null) + instance = new ProxySettingsOptionsPanel(PersistentBlackboardPlugIn.get(JUMPWorkbench.getInstance().getBlackboard())); + return instance; + } + + public Object getSetting( String key ) { + return this.blackboard.get(key, defaultValues.get(key)); + } } class DNSResolver implements Runnable { Modified: core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/OptionsPlugIn.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/OptionsPlugIn.java 2017-08-10 09:16:39 UTC (rev 5485) +++ core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/OptionsPlugIn.java 2017-08-10 13:43:01 UTC (rev 5486) @@ -94,9 +94,7 @@ dialog(context).addTab(I18N.get("ui.DatasetOptionsPanel.datasetOptions"), new DatasetOptionsPanel(context.getWorkbenchContext())); // add proxy panel - OptionsPanelV2 proxypanel = new ProxySettingsOptionsPanel( - PersistentBlackboardPlugIn.get(context.getWorkbenchContext() - .getWorkbench().getBlackboard())); + OptionsPanelV2 proxypanel = ProxySettingsOptionsPanel.getInstance(); dialog(context).addTab(proxypanel); } Modified: core/trunk/src/com/vividsolutions/wms/AbstractWMSRequest.java =================================================================== --- core/trunk/src/com/vividsolutions/wms/AbstractWMSRequest.java 2017-08-10 09:16:39 UTC (rev 5485) +++ core/trunk/src/com/vividsolutions/wms/AbstractWMSRequest.java 2017-08-10 13:43:01 UTC (rev 5486) @@ -73,12 +73,12 @@ protected HttpURLConnection prepareConnection() throws IOException { URL requestUrl = getURL(); con = (HttpURLConnection) requestUrl.openConnection(); - - // nicolas ribot, 29 juin 2017: timeouts are now read from the conf. - Blackboard blackboard = PersistentBlackboardPlugIn.getInstance(); - con.setConnectTimeout((Integer)blackboard.get(ProxySettingsOptionsPanel.CONNECTION_TIMEOUT_KEY)); - con.setReadTimeout((Integer)blackboard.get(ProxySettingsOptionsPanel.READ_TIMEOUT_KEY)); + con.setConnectTimeout(Integer.parseInt( + ProxySettingsOptionsPanel.getInstance().getSetting(ProxySettingsOptionsPanel.OPEN_TIMEOUT_KEY).toString())); + con.setReadTimeout(Integer.parseInt( + ProxySettingsOptionsPanel.getInstance().getSetting(ProxySettingsOptionsPanel.OPEN_TIMEOUT_KEY).toString())); + // add this service's auth info String userInfo = requestUrl.getUserInfo(); if (userInfo != null) { Modified: core/trunk/src/de/latlon/deejump/wfs/client/WFSHttpClient.java =================================================================== --- core/trunk/src/de/latlon/deejump/wfs/client/WFSHttpClient.java 2017-08-10 09:16:39 UTC (rev 5485) +++ core/trunk/src/de/latlon/deejump/wfs/client/WFSHttpClient.java 2017-08-10 13:43:01 UTC (rev 5486) @@ -56,11 +56,12 @@ private void _init() { HttpClientParams clientPars = new HttpClientParams(); - // Nicolas Ribot, 29 juin 2017: timeout values are now read from options - Blackboard blackboard = PersistentBlackboardPlugIn.getInstance(); - clientPars.setConnectionManagerTimeout((Integer)blackboard.get(ProxySettingsOptionsPanel.CONNECTION_TIMEOUT_KEY)); - clientPars.setSoTimeout((Integer)blackboard.get(ProxySettingsOptionsPanel.READ_TIMEOUT_KEY)); + // timeout values + clientPars.setConnectionManagerTimeout(Integer.parseInt( + ProxySettingsOptionsPanel.getInstance().getSetting(ProxySettingsOptionsPanel.OPEN_TIMEOUT_KEY).toString())); + clientPars.setSoTimeout(Integer.parseInt( + ProxySettingsOptionsPanel.getInstance().getSetting(ProxySettingsOptionsPanel.READ_TIMEOUT_KEY).toString())); clientPars.setContentCharset("UTF-8"); this.setParams(clientPars); |