List of usage examples for java.net MalformedURLException getLocalizedMessage
public String getLocalizedMessage()
From source file:it.geosolutions.geoserver.rest.GeoServerRESTPublisher.java
/** * Remove a given Workspace.//from w ww .j av a 2s .c o m * * @param workspace The name of the workspace * @param recurse The recurse parameter is used to recursively delete all resources contained by the specified workspace. This includes data * stores, coverage stores, feature types, etc... Allowable values for this parameter are <i>true</i> or <i>false</i>. The default value is * <i>false</i>. * @return <TT>true</TT> if the WorkSpace was successfully removed. */ public boolean removeWorkspace(String workspace, boolean recurse) throws IllegalArgumentException { workspace = sanitize(workspace); try { if (workspace == null) throw new IllegalArgumentException("Arguments may not be null!"); if (workspace.isEmpty()) throw new IllegalArgumentException("Arguments may not be empty!"); StringBuffer url = new StringBuffer(restURL).append("/rest/workspaces/").append(workspace); if (recurse) url.append("?recurse=true"); deleteStylesForWorkspace(workspace); // !!! workaround final URL deleteUrl = new URL(url.toString()); boolean deleted = HTTPUtils.delete(deleteUrl.toExternalForm(), gsuser, gspass); if (!deleted) { LOGGER.warn("Could not delete Workspace " + workspace); } else { LOGGER.info("Workspace successfully deleted " + workspace); } return deleted; } catch (MalformedURLException ex) { if (LOGGER.isErrorEnabled()) LOGGER.error(ex.getLocalizedMessage(), ex); return false; } }
From source file:it.geosolutions.geoserver.rest.GeoServerRESTPublisher.java
/** * Remove a given Datastore in a given Workspace. * /* w ww. j a va 2s. co m*/ * @param workspace The name of the workspace * @param storename The name of the Datastore to remove. * @param the {@link StoreType} type * @param recurse if remove should be performed recursively * @param purge the purge method * @throws IllegalArgumentException if workspace or storename are null or empty * @return <TT>true</TT> if the store was successfully removed. */ private boolean removeStore(String workspace, String storename, StoreType type, final boolean recurse, final Purge purge) throws IllegalArgumentException { try { if (workspace == null || storename == null) throw new IllegalArgumentException("Arguments may not be null!"); if (workspace.isEmpty() || storename.isEmpty()) throw new IllegalArgumentException("Arguments may not be empty!"); final StringBuilder url = new StringBuilder(restURL); url.append("/rest/workspaces/").append(workspace).append("/").append(type).append("/") .append(storename); url.append("?recurse=").append(recurse); if (purge != null) url.append("&purge=").append(purge); final URL deleteStore = new URL(url.toString()); boolean deleted = HTTPUtils.delete(deleteStore.toExternalForm(), gsuser, gspass); if (!deleted) { LOGGER.warn("Could not delete store " + workspace + ":" + storename); } else { LOGGER.info("Store successfully deleted " + workspace + ":" + storename); } return deleted; } catch (MalformedURLException ex) { if (LOGGER.isErrorEnabled()) LOGGER.error(ex.getLocalizedMessage(), ex); return false; } }
From source file:it.geosolutions.geoserver.rest.GeoServerRESTPublisher.java
/** * Removes the featuretype and the associated layer. * <P>/* w w w . j av a 2 s.c o m*/ * You may also want to {@link #removeDatastore(String, String) remove the datastore}. * * @return true if the operation completed successfully. */ public boolean unpublishFeatureType(String workspace, String storename, String layerName) { try { final String fqLayerName; // this null check is here only for backward compatibility. // workspace // shall be mandatory. if (workspace == null) { fqLayerName = layerName; if (LOGGER.isWarnEnabled()) { LOGGER.warn("Null workspace while configuring layer : " + layerName + " -- This behavior is deprecated."); } } else { fqLayerName = workspace + ":" + layerName; } // delete related layer URL deleteLayerUrl = new URL(restURL + "/rest/layers/" + fqLayerName); boolean layerDeleted = HTTPUtils.delete(deleteLayerUrl.toExternalForm(), gsuser, gspass); if (!layerDeleted) { LOGGER.warn("Could not delete layer '" + fqLayerName + "'"); return false; } // delete the coverage URL deleteFtUrl = new URL(restURL + "/rest/workspaces/" + workspace + "/datastores/" + storename + "/featuretypes/" + layerName); boolean ftDeleted = HTTPUtils.delete(deleteFtUrl.toExternalForm(), gsuser, gspass); if (!ftDeleted) { LOGGER.warn("Could not delete featuretype " + workspace + ":" + storename + "/" + layerName + ", but layer was deleted."); } else { LOGGER.info("FeatureType successfully deleted " + workspace + ":" + storename + "/" + layerName); } return ftDeleted; // the store is still there: should we delete it? } catch (MalformedURLException ex) { if (LOGGER.isErrorEnabled()) LOGGER.error(ex.getLocalizedMessage(), ex); return false; } }
From source file:it.geosolutions.geoserver.rest.GeoServerRESTPublisher.java
/** * Remove the Coverage configuration from GeoServer. * <P>/*from w ww . j av a2 s .c o m*/ * First, the associated layer is removed, then the Coverage configuration itself. * <P> * <B>CHECKME</B> Maybe the coveragestore has to be removed as well. * * @return true if the operation completed successfully. */ public boolean unpublishCoverage(String workspace, String storename, String layerName) { try { final String fqLayerName; // this null check is here only for backward compatibility. // workspace // shall be mandatory. if (workspace == null) { fqLayerName = layerName; if (LOGGER.isWarnEnabled()) { LOGGER.warn("Null workspace while configuring layer : " + layerName + " -- This behavior is deprecated."); } } else { fqLayerName = workspace + ":" + layerName; } // delete related layer URL deleteLayerUrl = new URL(restURL + "/rest/layers/" + fqLayerName); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Going to delete " + "/rest/layers/" + fqLayerName); } boolean layerDeleted = HTTPUtils.delete(deleteLayerUrl.toExternalForm(), gsuser, gspass); if (!layerDeleted) { LOGGER.warn("Could not delete layer '" + fqLayerName + "'"); return false; } // delete the coverage URL deleteCovUrl = new URL(restURL + "/rest/workspaces/" + workspace + "/coveragestores/" + storename + "/coverages/" + layerName); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Going to delete " + "/rest/workspaces/" + workspace + "/coveragestores/" + storename + "/coverages/" + layerName); } boolean covDeleted = HTTPUtils.delete(deleteCovUrl.toExternalForm(), gsuser, gspass); if (!covDeleted) { LOGGER.warn("Could not delete coverage " + workspace + ":" + storename + "/" + layerName + ", but layer was deleted."); } else { LOGGER.info("Coverage successfully deleted " + workspace + ":" + storename + "/" + layerName); } return covDeleted; // the covstore is still there: should we delete it? } catch (MalformedURLException ex) { if (LOGGER.isErrorEnabled()) LOGGER.error(ex.getLocalizedMessage(), ex); return false; } }
From source file:it.geosolutions.geoserver.rest.GeoServerRESTPublisher.java
/** * Configure an existing coverage in a given workspace and coverage store * /*w w w .j a v a 2 s.com*/ * @param ce contains the coverage name to configure and the configuration to apply * @param wsname the workspace to search for existent coverage * @param csname the coverage store to search for existent coverage * @param coverageName the name of the coverage, useful for changing name for the coverage itself * @return true if success */ public boolean configureCoverage(final GSCoverageEncoder ce, final String wsname, final String csname, final String coverageName) { if (coverageName == null) { if (LOGGER.isErrorEnabled()) LOGGER.error( "Unable to configure a coverage with no name try using GSCoverageEncoder.setName(String)"); return false; } // retrieve coverage name GeoServerRESTReader reader; try { reader = new GeoServerRESTReader(restURL, gsuser, gspass); } catch (MalformedURLException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e.getLocalizedMessage(), e); return false; } // optimized search, left the old code for reference RESTCoverage coverage = reader.getCoverage(wsname, csname, coverageName); // final RESTCoverageList covList = reader.getCoverages(wsname, csname); // if (covList==null||covList.isEmpty()) { // if (LOGGER.isErrorEnabled()) // LOGGER.error("No coverages found in new coveragestore " + csname); // return false; // } // final Iterator<NameLinkElem> it = covList.iterator(); // while (it.hasNext()) { // NameLinkElem nameElem = it.next(); // if (nameElem.getName().equals(coverageName)) { // found = true; // break; // } // } // if no coverage to configure is found return false if (coverage == null) { if (LOGGER.isErrorEnabled()) LOGGER.error("No coverages found in new coveragestore " + csname + " called " + coverageName); return false; } // configure the selected coverage final String url = restURL + "/rest/workspaces/" + wsname + "/coveragestores/" + csname + "/coverages/" + coverageName + ".xml"; final String xmlBody = ce.toString(); final String sendResult = HTTPUtils.putXml(url, xmlBody, gsuser, gspass); if (sendResult != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Coverage successfully configured " + wsname + ":" + csname + ":" + coverageName); } } else { if (LOGGER.isWarnEnabled()) LOGGER.warn("Error configuring coverage " + wsname + ":" + csname + ":" + coverageName + " (" + sendResult + ")"); } return sendResult != null; }
From source file:org.openestate.is24.restapi.utils.RandomRealEstateFactory.java
/** * Create a random {@link RealtorContactDetails}. * * @return/*from ww w . j a v a2s . c o m*/ * randomly filled {@link RealtorContactDetails} object */ public RealtorContactDetails createRandomContact() { RealtorContactDetails contact = commonFactory.createRealtorContactDetails(); contact.setAdditionName(StringUtils.abbreviate(LOREM.getWords(1, 5), 30)); contact.setAddress(createRandomAddress()); contact.setBusinessCardContact(false); contact.setCellPhoneNumber("+49 160 123456"); contact.setCellPhoneNumberAreaCode("0160"); contact.setCellPhoneNumberCountryCode("+49"); contact.setCellPhoneNumberSubscriber("123456"); contact.setCompany(StringUtils.abbreviate(LOREM.getWords(1, 15), 100)); contact.setCountryCode(getRandomCountryCode()); contact.setDefaultContact(false); contact.setEmail("test@test.org"); //contact.setExternalId( null ); contact.setFaxNumber("+49 30 123457"); contact.setFaxNumberAreaCode("030"); contact.setFaxNumberCountryCode("+49"); contact.setFaxNumberSubscriber("123457"); contact.setFirstname(LOREM.getFirstName()); //contact.setId( null ); contact.setLastname(LOREM.getLastName()); contact.setLocalPartnerContact(false); contact.setOfficeHours(StringUtils.abbreviate(LOREM.getWords(1, 50), 1000)); contact.setPhoneNumber("+49 30 123456"); contact.setPhoneNumberAreaCode("030"); contact.setPhoneNumberCountryCode("+49"); contact.setPhoneNumberSubscriber("123456"); contact.setPosition(StringUtils.abbreviate(LOREM.getWords(1, 15), 100)); //contact.setRealEstateReferenceCount( null ); contact.setSalutation(getRandomSalutationType()); contact.setShowOnProfilePage(false); contact.setTitle(StringUtils.abbreviate(LOREM.getWords(1, 3), 15)); try { contact.setHomepageUrl(new URL("http://test.org")); contact.setPortraitUrl(new URL("http://test.org/portrait.jpg")); } catch (MalformedURLException ex) { LOGGER.warn("Can't write URL!"); LOGGER.warn("> " + ex.getLocalizedMessage(), ex); } return contact; }
From source file:org.opendatakit.briefcase.util.AggregateUtils.java
/** * Send a HEAD request to the server to confirm the validity of the URL and * credentials./* ww w. j a v a 2s .c o m*/ * * @param serverInfo * @param actionAddr * @return the confirmed URI of this action. * @throws TransmissionException */ public static final URI testServerConnectionWithHeadRequest(ServerConnectionInfo serverInfo, String actionAddr) throws TransmissionException { String urlString = serverInfo.getUrl(); if (urlString.endsWith("/")) { urlString = urlString + actionAddr; } else { urlString = urlString + "/" + actionAddr; } URI u; try { URL url = new URL(urlString); u = url.toURI(); } catch (MalformedURLException e) { String msg = "Invalid url: " + urlString + " for " + actionAddr + ".\nFailed with error: " + e.getMessage(); if (!urlString.toLowerCase().startsWith("http://") && !urlString.toLowerCase().startsWith("https://")) { msg += "\nDid you forget to prefix the address with 'http://' or 'https://' ?"; } log.warn(msg, e); throw new TransmissionException(msg); } catch (URISyntaxException e) { String msg = "Invalid uri: " + urlString + " for " + actionAddr + ".\nFailed with error: " + e.getMessage(); log.warn(msg, e); throw new TransmissionException(msg); } HttpClient httpClient = WebUtils.createHttpClient(); // get shared HttpContext so that authentication and cookies are retained. HttpClientContext localContext = WebUtils.getHttpContext(); WebUtils.setCredentials(localContext, serverInfo, u); { // we need to issue a head request HttpHead httpHead = WebUtils.createOpenRosaHttpHead(u); // prepare response HttpResponse response = null; try { response = httpClient.execute(httpHead, localContext); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 204) { Header[] openRosaVersions = response.getHeaders(WebUtils.OPEN_ROSA_VERSION_HEADER); if (openRosaVersions == null || openRosaVersions.length == 0) { String msg = "Url: " + u.toString() + ", header missing: " + WebUtils.OPEN_ROSA_VERSION_HEADER; log.warn(msg); throw new TransmissionException(msg); } Header[] locations = response.getHeaders("Location"); if (locations != null && locations.length == 1) { try { URL url = new URL(locations[0].getValue()); URI uNew = url.toURI(); if (u.getHost().equalsIgnoreCase(uNew.getHost())) { // trust the server to tell us a new location // ... and possibly to use https instead. u = uNew; // At this point, we may have updated the uri to use https. // This occurs only if the Location header keeps the host name // the same. If it specifies a different host name, we error // out. return u; } else { // Don't follow a redirection attempt to a different host. // We can't tell if this is a spoof or not. String msg = "Starting url: " + u.toString() + " unexpected redirection attempt to a different host: " + uNew.toString(); log.warn(msg); throw new TransmissionException(msg); } } catch (Exception e) { String msg = "Starting url: " + u + " unexpected exception: " + e.getLocalizedMessage(); log.warn(msg, e); throw new TransmissionException(msg); } } else { String msg = "The url: " + u.toString() + " is not ODK Aggregate - status code on Head request: " + statusCode; log.warn(msg); throw new TransmissionException(msg); } } else { // may be a server that does not handle HEAD requests if (response.getEntity() != null) { try { // don't really care about the stream... InputStream is = response.getEntity().getContent(); // read to end of stream... final long count = 1024L; while (is.skip(count) == count) ; is.close(); } catch (Exception e) { log.error("failed to process http stream", e); } } String msg = "The username or password may be incorrect or the url: " + u.toString() + " is not ODK Aggregate - status code on Head request: " + statusCode; log.warn(msg); throw new TransmissionException(msg); } } catch (Exception e) { String msg = "Starting url: " + u.toString() + " unexpected exception: " + e.getLocalizedMessage(); log.warn(msg, e); throw new TransmissionException(msg); } } }