List of usage examples for java.net MalformedURLException getLocalizedMessage
public String getLocalizedMessage()
From source file:eu.codeplumbers.cosi.api.tasks.DeleteFileTask.java
@Override protected String doInBackground(File... files) { for (int i = 0; i < files.length; i++) { File file = files[i];/*from w w w . j a v a2 s . com*/ String binaryRemoteId = file.getRemoteId(); if (!binaryRemoteId.isEmpty()) { publishProgress("Deleting file: " + file.getName(), "0", "100"); URL urlO = null; try { urlO = new URL(url + binaryRemoteId + "/binaries/file"); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoInput(true); conn.setRequestMethod("DELETE"); InputStream in = null; // read the response int status = conn.getResponseCode(); if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { in = conn.getErrorStream(); } else { in = conn.getInputStream(); } StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { errorMessage = conn.getResponseMessage(); } else { errorMessage = deleteFileRequest(file); if (errorMessage == "") { java.io.File newFile = file.getLocalPath(); if (newFile.exists()) { newFile.delete(); } file.delete(); } else { return errorMessage; } } } catch (MalformedURLException e) { errorMessage = e.getLocalizedMessage(); } catch (ProtocolException e) { errorMessage = e.getLocalizedMessage(); } catch (IOException e) { errorMessage = e.getLocalizedMessage(); } } } return errorMessage; }
From source file:org.kalypso.commons.databinding.validation.StringToUrlValidator.java
@Override protected IStatus doValidate(final String value) { if (StringUtils.isEmpty(value)) return ValidationStatus.error(String.format(Messages.getString("StringToUrlValidator_0"), m_fieldName)); //$NON-NLS-1$ try {/*from ww w . ja va 2 s . c o m*/ final URL url = new URL(value); final String host = url.getHost(); if (StringUtils.isBlank(host)) return ValidationStatus .error(String.format(Messages.getString("StringToUrlValidator_1"), m_fieldName)); //$NON-NLS-1$ } catch (final MalformedURLException e) { // REMARK: we do not give the exception here, else the console gets cluttered with the stack traces when the user // enters a url return ValidationStatus.error(e.getLocalizedMessage(), null); } return ValidationStatus.ok(); }
From source file:it.geosolutions.geofence.gui.server.service.impl.WorkspacesManagerServiceImpl.java
public PagingLoadResult<Workspace> getWorkspaces(int offset, int limit, String remoteURL, GSInstance gsInstance) throws ApplicationException { List<Workspace> workspacesListDTO = new ArrayList<Workspace>(); workspacesListDTO.add(new Workspace("*")); if ((remoteURL != null) && !remoteURL.equals("*") && !remoteURL.contains("?")) { try {//from ww w . j av a2 s .co m GeoServerRESTReader gsreader = new GeoServerRESTReader(remoteURL, gsInstance.getUsername(), gsInstance.getPassword()); RESTWorkspaceList workspaces = gsreader.getWorkspaces(); if ((workspaces != null) && !workspaces.isEmpty()) { Iterator<RESTShortWorkspace> wkIT = workspaces.iterator(); while (wkIT.hasNext()) { RESTShortWorkspace workspace = wkIT.next(); workspacesListDTO.add(new Workspace(workspace.getName())); } } } catch (MalformedURLException e) { logger.error(e.getLocalizedMessage(), e); throw new ApplicationException(e.getLocalizedMessage(), e); } } return new RpcPageLoadResult<Workspace>(workspacesListDTO, 0, workspacesListDTO.size()); }
From source file:org.geoserver.geofence.gui.server.service.impl.WorkspacesManagerServiceImpl.java
public List<LayerStyle> getStyles(RuleModel rule) throws ApplicationException { List<LayerStyle> layerStyles = new ArrayList<LayerStyle>(); Set<String> allowedStyles = null; int size = 0; try {//from w ww . j a va 2 s.c o m LayerDetails layerDetails = geofenceRemoteService.getRuleAdminService().get(rule.getId()) .getLayerDetails(); if (layerDetails != null) { allowedStyles = layerDetails.getAllowedStyles(); if (allowedStyles != null) { size = allowedStyles.size(); } } GeoServerRESTReader gsreader = new GeoServerRESTReader(rule.getInstance().getBaseURL(), rule.getInstance().getUsername(), rule.getInstance().getPassword()); RESTStyleList styles = gsreader.getStyles(); List<String> names = styles.getNames(); Iterator<String> iterator = names.iterator(); while (iterator.hasNext()) { String name = iterator.next(); LayerStyle layerStyle = new LayerStyle(); if (size > 0) { Iterator<String> styleIterator = allowedStyles.iterator(); while (styleIterator.hasNext()) { String allowed = styleIterator.next(); if (allowed.equalsIgnoreCase(name)) { layerStyle.setEnabled(true); } } } else { layerStyle.setEnabled(false); } layerStyle.setStyle(name); layerStyles.add(layerStyle); } } catch (MalformedURLException e) { logger.error(e.getLocalizedMessage(), e); throw new ApplicationException(e.getLocalizedMessage(), e); } catch (NotFoundServiceEx e) { logger.error(e.getLocalizedMessage(), e); throw new ApplicationException(e.getLocalizedMessage(), e); } return layerStyles; }
From source file:org.geoserver.geofence.gui.server.service.impl.InstancesManagerServiceImpl.java
public void testConnection(org.geoserver.geofence.gui.client.model.GSInstanceModel instance) throws ApplicationException { try {/* w w w .ja v a 2 s. c o m*/ String response = getURL(instance.getBaseURL() + "/rest/geofence/info", instance.getUsername(), instance.getPassword()); if (response != null) { if (!response.equals(instance.getName())) { if (response.contains("Geoserver Configuration API")) { // some heuristic here logger.error("GeoFence probe not installed on " + instance.getName()); throw new ApplicationException("GeoFence probe not installed on " + instance.getName()); } else { logger.error("Wrong instance name: " + response); throw new ApplicationException( "Wrong instance name: " + instance.getName() + ", should be :" + response); } } } else { throw new ApplicationException("Error contacting GeoServer"); } } catch (MalformedURLException e) { logger.error(e.getLocalizedMessage(), e.getCause()); throw new ApplicationException(e.getLocalizedMessage(), e.getCause()); } }
From source file:org.geoserver.geofence.gui.server.service.impl.WorkspacesManagerServiceImpl.java
public PagingLoadResult<Layer> getLayers(int offset, int limit, String baseURL, GSInstanceModel gsInstance, String workspace, String service) throws ApplicationException { List<Layer> layersListDTO = new ArrayList<Layer>(); layersListDTO.add(new Layer("*")); if ((baseURL != null) && !baseURL.equals("*") && !baseURL.contains("?") && (workspace != null) && (workspace.length() > 0)) { try {/*from w ww . ja v a 2 s . c om*/ GeoServerRESTReader gsreader = new GeoServerRESTReader(baseURL, gsInstance.getUsername(), gsInstance.getPassword()); if (workspace.equals("*") && workspaceConfigOpts.isShowDefaultGroups() && service.equals("WMS")) { RESTAbstractList<NameLinkElem> layerGroups = gsreader.getLayerGroups(); if ((layerGroups != null)) { for (NameLinkElem lg : layerGroups) { // RESTLayerGroup group = gsreader.getLayerGroup(lg.getName()); // if (group != null) // { // layersListDTO.add(new Layer(group.getName())); // } layersListDTO.add(new Layer(lg.getName())); } } } else { SortedSet<String> sortedLayerNames = new TreeSet<String>(); RESTAbstractList<NameLinkElem> layers = gsreader.getLayers(); if (workspace.equals("*")) { // load all layers if (layers != null) for (NameLinkElem layerLink : layers) { sortedLayerNames.add(layerLink.getName()); } } else { if ((layers != null) && !layers.isEmpty()) { for (NameLinkElem layerNL : layers) { // next block is really too slow RESTLayer layer = gsreader.getLayer(layerNL.getName()); if (layer.getResourceUrl().contains("workspaces/" + workspace + "/")) { sortedLayerNames.add(layerNL.getName()); //layersListDTO.add(new Layer(layerNL.getName())); } } } } // return the sorted layers list for (String layerName : sortedLayerNames) { layersListDTO.add(new Layer(layerName)); } } } catch (MalformedURLException e) { logger.error(e.getLocalizedMessage(), e); throw new ApplicationException(e.getLocalizedMessage(), e); } } return new RpcPageLoadResult<Layer>(layersListDTO, 0, layersListDTO.size()); }
From source file:biz.wolschon.finance.jgnucash.actions.FileBugInBrowserAction.java
@Override public void actionPerformed(final ActionEvent aE) { try {/*from w w w .java 2 s .c o m*/ final URL fileABugURL = new URL("https://sourceforge.net/tracker2/?group_id=147662&atid=769090"); showDocument(fileABugURL); } catch (MalformedURLException e) { LOGGER.error("Error, cannot launch web browser", e); JOptionPane.showMessageDialog(null, "Error, cannot launch web browser:\n" + e.getLocalizedMessage()); } }
From source file:eu.codeplumbers.cosi.api.tasks.GetPlacesTask.java
@Override protected List<Place> doInBackground(Void... voids) { URL urlO = null;/*from w w w.ja v a2 s. c o m*/ try { urlO = new URL(url); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoInput(true); conn.setRequestMethod("POST"); // read the response int status = conn.getResponseCode(); InputStream in = null; if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { in = conn.getErrorStream(); } else { in = conn.getInputStream(); } StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); JSONArray jsonArray = new JSONArray(result); if (jsonArray != null) { if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { String version = "0"; if (jsonArray.getJSONObject(i).has("version")) { version = jsonArray.getJSONObject(i).getString("version"); } JSONObject placeJson = jsonArray.getJSONObject(i).getJSONObject("value"); Place place = Place.getByLocation(placeJson.get("description").toString(), placeJson.get("latitude").toString(), placeJson.get("longitude").toString()); if (place == null) { place = new Place(placeJson); } else { place.setDeviceId(placeJson.getString("deviceId")); place.setAddress(placeJson.getString("address")); place.setDateAndTime(placeJson.getString("dateAndTime")); place.setLongitude(placeJson.getDouble("longitude")); place.setLatitude(placeJson.getDouble("latitude")); place.setRemoteId(placeJson.getString("_id")); } publishProgress("Saving place : " + place.getAddress()); place.save(); allPlaces.add(place); } } else { publishProgress("Your Cozy has no places stored."); return allPlaces; } } else { errorMessage = "Failed to parse API response"; } in.close(); conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); errorMessage = e.getLocalizedMessage(); } catch (ProtocolException e) { errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } catch (IOException e) { errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } catch (JSONException e) { errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } return allPlaces; }
From source file:it.geosolutions.geobatch.imagemosaic.GeoBatchBaseTest.java
protected void connectToGeoserver() throws Exception { LOGGER.debug("geoserver url is " + getFixture().getProperty("gs_url")); try {// www .j ava 2 s.c o m GeoServerRESTReader reader = createGSReader(); if (!reader.existGeoserver()) { LOGGER.error("GeoServer not found at " + getFixture().getProperty("gs_url")); throw new ConnectException("GeoServer not found at " + getFixture().getProperty("gs_url")); } } catch (MalformedURLException e) { LOGGER.error(e.getLocalizedMessage(), e); throw e; } LOGGER.debug("geoserver connection is ok"); }
From source file:it.geosolutions.geofence.gui.server.service.impl.WorkspacesManagerServiceImpl.java
public List<LayerStyle> getStyles(Rule rule) throws ApplicationException { List<LayerStyle> layerStyles = new ArrayList<LayerStyle>(); Set<String> allowedStyles = null; int size = 0; try {/*w w w . j av a2s . co m*/ LayerDetails layerDetails = geofenceRemoteService.getRuleAdminService().get(rule.getId()) .getLayerDetails(); if (layerDetails != null) { allowedStyles = layerDetails.getAllowedStyles(); if (allowedStyles != null) { size = allowedStyles.size(); } } GeoServerRESTReader gsreader = new GeoServerRESTReader(rule.getInstance().getBaseURL(), rule.getInstance().getUsername(), rule.getInstance().getPassword()); RESTStyleList styles = gsreader.getStyles(); List<String> names = styles.getNames(); Iterator<String> iterator = names.iterator(); while (iterator.hasNext()) { String name = iterator.next(); LayerStyle layerStyle = new LayerStyle(); if (size > 0) { Iterator<String> styleIterator = allowedStyles.iterator(); while (styleIterator.hasNext()) { String allowed = styleIterator.next(); if (allowed.equalsIgnoreCase(name)) { layerStyle.setEnabled(true); } } } else { layerStyle.setEnabled(false); } layerStyle.setStyle(name); layerStyles.add(layerStyle); } } catch (MalformedURLException e) { logger.error(e.getLocalizedMessage(), e); throw new ApplicationException(e.getLocalizedMessage(), e); } catch (NotFoundServiceEx e) { logger.error(e.getLocalizedMessage(), e); throw new ApplicationException(e.getLocalizedMessage(), e); } return layerStyles; }