List of usage examples for java.net MalformedURLException getLocalizedMessage
public String getLocalizedMessage()
From source file:it.geosolutions.geofence.gui.server.service.impl.InstancesManagerServiceImpl.java
public void testConnection(it.geosolutions.geofence.gui.client.model.GSInstance instance) throws ApplicationException { try {// ww w.j a va 2s . co 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:de.thm.arsnova.ImageUtils.java
/** * Gets the bytestream of an image url./* www .j ava 2s.c o m*/ * s * @param imageUrl The image url as a {@link String} * @return The <code>byte[]</code> of the image on success, otherwise <code>null</code>. */ public byte[] convertImageToByteArray(final String imageUrl, final String extension) { try { final URL url = new URL(imageUrl); final BufferedImage image = ImageIO.read(url); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, extension, baos); baos.flush(); baos.close(); return baos.toByteArray(); } catch (final MalformedURLException e) { LOGGER.error(e.getLocalizedMessage()); } catch (final IOException e) { LOGGER.error(e.getLocalizedMessage()); } return null; }
From source file:it.geosolutions.geofence.gui.server.service.impl.WorkspacesManagerServiceImpl.java
public PagingLoadResult<Layer> getLayers(int offset, int limit, String baseURL, GSInstance 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 {/*w w w .j a 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:de.thm.arsnova.ImageUtils.java
/** * Gets the bytestream of an image url.//from ww w. ja v a 2s. c om * * @param imageUrl The image url as a {@link String} * @return The <code>byte[]</code> of the image on success, otherwise <code>null</code>. */ public byte[] convertFileToByteArray(final String imageUrl) { try { final URL url = new URL(imageUrl); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final InputStream is = url.openStream(); final byte[] byteChunk = new byte[CHUNK_SIZE]; int n; while ((n = is.read(byteChunk)) > 0) { baos.write(byteChunk, 0, n); } baos.flush(); baos.close(); return baos.toByteArray(); } catch (final MalformedURLException e) { LOGGER.error(e.getLocalizedMessage()); } catch (final IOException e) { LOGGER.error(e.getLocalizedMessage()); } return null; }
From source file:eu.codeplumbers.cosi.api.tasks.CheckDesignDocumentsTask.java
@Override protected String doInBackground(String... docTypes) { errorMessage = ""; for (int i = 0; i < docTypes.length; i++) { String docType = docTypes[i].toLowerCase(); publishProgress("Checking design: " + docType); URL urlO = null;//w ww. jav a2 s . c o m try { // using all view can break notes, files app in cozy urlO = getCosiUrl(docType); 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(); if (result != "") { errorMessage = createDesignDocument(docType); if (errorMessage != "") { return errorMessage; } else { errorMessage = ""; } } else { errorMessage = "Failed to parse API response"; return errorMessage; } 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(); } } return errorMessage; }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.Geoserver.java
public Geoserver(GeoserverVO geoserverVO) { geoserverAUX = geoserverVO;/* www . ja va2 s .c om*/ try { URL geoserverUrl = URI.create(geoserverAUX.getGeoserverUrl()).toURL(); gsManager = new GeoServerRESTManager(geoserverUrl, geoserverAUX.getGeoserverUser(), geoserverAUX.getGeoserverPassword()); } catch (MalformedURLException e) { log.error("Error al intentar acceder a la API REST de geoserver: " + e.getLocalizedMessage()); } }
From source file:org.apache.chemistry.shell.Main.java
public void parseArgs(String[] args) throws IOException { if (args.length > 0) { for (int i = 0; i < args.length; i++) { String arg = args[i]; if ("-u".equals(arg)) { // username if (++i == args.length) { error("Invalid option -u without value. Username required."); }//from w w w . j a v a 2s . co m username = args[i]; } else if ("-p".equals(arg)) { // password if (++i == args.length) { error("Invalid option -p without value. Password required."); } password = args[i]; } else if ("-t".equals(arg)) { // test mode testMode = true; } else if ("--enable-time".equals(arg)) { // enable time setting by default enableTime = true; } else if ("-e".equals(arg)) { // execute mode // execute one command execMode = true; StringBuilder buf = new StringBuilder(); for (i++; i < args.length; i++) { buf.append(args[i]).append(" "); } command = buf.toString(); break; } else if ("-b".equals(arg)) { // batch mode // execute commands in the given file or if no specified // read from stdin batchMode = true; if (++i < args.length) { // read commands from a file command = args[i]; } break; } else if ("-h".equals(arg) || "--help".equals(arg)) { // help // execute help command usage(); System.exit(0); } else if (!arg.startsWith("-")) { url = arg; } else if ("-j".equals(arg)) { // use json binding useJSONBinding = true; } else if ("--compression".equals(arg)) { // use compression useCompression = true; } else if ("--version".equals(arg)) { // print actual version version(); System.exit(0); } else if ("--insecure".equals(arg)) { acceptSelfSignedCertificates(); System.setProperty("jsse.enableSNIExtension", "false"); } else { System.err.println("Skipping unknown argument: " + arg); } } if (url != null) { if (!url.contains("://")) { url = "http://" + url; } try { URL u = new URL(url); if (username == null) { String userInfo = u.getUserInfo(); if (userInfo != null) { if (userInfo.contains(":")) { int p = userInfo.indexOf(':'); username = userInfo.substring(0, p); if (password == null && p < userInfo.length() - 1) { password = userInfo.substring(p + 1); } } else { username = userInfo; } } } } catch (MalformedURLException e) { System.err.println("Malformed URL: " + e.getLocalizedMessage()); System.exit(1); } } if (url != null && username == null) { username = System.console().readLine("User: "); } if (username != null && password == null) { password = PasswordReader.read(); } } }
From source file:org.opencms.gwt.CmsGwtServiceContext.java
/** * Finds the path of the serialization policy file.<p> * /*from w w w. j ava2s. c o m*/ * @param cms the current CMS context * @param moduleBaseURL the GWT module's base url * @param strongName the strong name of the service * * @return the serialization policy path */ protected String getSerializationPolicyPath(CmsObject cms, String moduleBaseURL, String strongName) { // locate the serialization policy file in OpenCms String modulePath = null; try { modulePath = new URL(moduleBaseURL).getPath(); } catch (MalformedURLException ex) { // moduleBaseUrl is bad LOG.error(ex.getLocalizedMessage(), ex); return null; } catch (NullPointerException ex) { // moduleBaseUrl is null LOG.error(ex.getLocalizedMessage(), ex); return null; } String serializationPolicyUrl = SerializationPolicyLoader .getSerializationPolicyFileName(modulePath + strongName); return OpenCms.getLinkManager().getRootPath(cms, serializationPolicyUrl); }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.Geoserver.java
public List<String> getDatastoresFromWorkspace(String workspaceName) { List<String> datastoresNames = new LinkedList<String>(); if (!StringUtils.isEmpty(workspaceName)) { // bug in GeoServerRESTReader to list datasources?? String restDatastoresUrl = geoserverAUX.getGeoserverUrl().concat("/rest/workspaces/") .concat(workspaceName).concat("/datastores.json"); String datastoresResponse; try {/* www . ja v a 2 s . co m*/ datastoresResponse = HTTPUtils.get(restDatastoresUrl, geoserverAUX.getGeoserverUser(), geoserverAUX.getGeoserverPassword()); JSONObject jDatastoreResponse = new JSONObject(datastoresResponse); JSONObject jDatastores = jDatastoreResponse.getJSONObject("dataStores"); JSONArray jDatastoresArray = jDatastores.getJSONArray("dataStore"); for (int i = 0; i < jDatastoresArray.length(); i++) { JSONObject jDatastore = jDatastoresArray.getJSONObject(i); String datastoreName = jDatastore.getString("name"); datastoresNames.add(datastoreName); } } catch (MalformedURLException e) { log.error("Error al conectar con la API REST de Geoserver: " + e.getLocalizedMessage()); } catch (JSONException e) { log.error("Error al procesar la respuesta JSON de Geoserver: " + e.getLocalizedMessage()); } } return datastoresNames; }
From source file:eu.codeplumbers.cosi.api.tasks.SyncDocumentTask.java
@Override protected String doInBackground(JSONObject... jsonObjects) { for (int i = 0; i < jsonObjects.length; i++) { JSONObject jsonObject = jsonObjects[i]; URL urlO = null;//from w ww . j av a 2 s. c o m try { publishProgress("Syncing " + jsonObject.getString("docType") + ":", i + "", jsonObjects.length + ""); String remoteId = jsonObject.getString("remoteId"); String requestMethod = ""; if (remoteId.isEmpty()) { urlO = new URL(url); requestMethod = "POST"; } else { urlO = new URL(url + remoteId + "/"); requestMethod = "PUT"; } HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod(requestMethod); // set request body jsonObject.remove("remoteId"); objectId = jsonObject.getLong("id"); jsonObject.remove("id"); OutputStream os = conn.getOutputStream(); os.write(jsonObject.toString().getBytes("UTF-8")); os.flush(); // read the response InputStream in = new BufferedInputStream(conn.getInputStream()); StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); JSONObject jsonObjectResult = new JSONObject(result); if (jsonObjectResult != null && jsonObjectResult.has("_id")) { result = jsonObjectResult.getString("_id"); if (jsonObject.get("docType").equals("Sms")) { Sms sms = Sms.load(Sms.class, objectId); sms.setRemoteId(result); sms.save(); } if (jsonObject.get("docType").equals("Note")) { Note note = Note.load(Note.class, objectId); note.setRemoteId(result); note.save(); } if (jsonObject.get("docType").equals("Call")) { Call call = Call.load(Call.class, objectId); call.setRemoteId(result); call.save(); } if (jsonObject.get("docType").equals("Expense")) { Expense expense = Expense.load(Expense.class, objectId); expense.setRemoteId(result); expense.save(); } } in.close(); conn.disconnect(); } catch (MalformedURLException e) { result = "error"; e.printStackTrace(); errorMessage = e.getLocalizedMessage(); } catch (ProtocolException e) { result = "error"; errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } catch (IOException e) { result = "error"; errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } catch (JSONException e) { result = "error"; errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } } return result; }