Java Code Examples for java.net.MalformedURLException#getLocalizedMessage()

The following examples show how to use java.net.MalformedURLException#getLocalizedMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InstancesManagerServiceImpl.java    From geofence with GNU General Public License v2.0 6 votes vote down vote up
public void testConnection(org.geoserver.geofence.gui.client.model.GSInstanceModel instance) throws ApplicationException {
	try {
		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());
	}
}
 
Example 2
Source File: JMXServiceURLTypeConverter.java    From cassandra-exporter with Apache License 2.0 5 votes vote down vote up
@Override
public JMXServiceURL convert(final String value) {
    try {
        return new JMXServiceURL(value);

    } catch (final MalformedURLException e) {
        throw new CommandLine.TypeConversionException("Invalid JMX service URL (" + e.getLocalizedMessage() + ")");
    }
}
 
Example 3
Source File: PreferencesConnection.java    From habpanelviewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(final Preference preference, Object o) {
    String text = (String) o;

    if (text == null || text.isEmpty()) {
        return true;
    }

    String dialogText = null;

    try {
        URL uri = new URL(text);

        int port = uri.getPort();
        if (port == -1) {
            port = uri.getDefaultPort();
        }

        if (port < 0 || port > 65535) {
            dialogText = "Port invalid: " + port;
        }
    } catch (MalformedURLException e) {
        dialogText = "URL invalid: " + e.getLocalizedMessage();
    }

    if (dialogText != null) {
        UiUtil.showDialog(getActivity(), preference.getTitle() + " "
                + getActivity().getResources().getString(R.string.invalid), dialogText);
    }

    return true;
}
 
Example 4
Source File: WorkspacesManagerServiceImpl.java    From geofence with GNU General Public License v2.0 5 votes vote down vote up
public PagingLoadResult<WorkspaceModel> getWorkspaces(int offset, int limit, String remoteURL,
    GSInstanceModel gsInstance) throws ApplicationException
{

    List<WorkspaceModel> workspacesListDTO = new ArrayList<WorkspaceModel>();
    workspacesListDTO.add(new WorkspaceModel("*"));

    if ((remoteURL != null) && !remoteURL.equals("*") && !remoteURL.contains("?"))
    {
        try
        {
            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 WorkspaceModel(workspace.getName()));
                }
            }
        }
        catch (MalformedURLException e)
        {
            logger.error(e.getLocalizedMessage(), e);
            throw new ApplicationException(e.getLocalizedMessage(), e);
        }
    }

    return new RpcPageLoadResult<WorkspaceModel>(workspacesListDTO, 0, workspacesListDTO.size());
}
 
Example 5
Source File: DeployUrlCommand.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public URL convert(CLIConverterInvocation c) throws OptionValidatorException {
    try {
        return new URL(c.getInput());
    } catch (MalformedURLException e) {
        throw new OptionValidatorException(e.getLocalizedMessage());
    }
}
 
Example 6
Source File: LstFileLoader.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method reads the given URL and stores its contents in the provided
 * data buffer, returning a URL to the specified file for use in log/error
 * messages by its caller.
 *
 * @param uri        String path of the URL to read -- MUST be a URL path,
 *                   not a file!
 * @return URL pointing to the actual file read, for use in debug/log
 *         messages
 * @throws PersistenceLayerException 
 */
@Nullable
public static String readFromURI(URI uri) throws PersistenceLayerException
{
	if (uri == null)
	{
		// We have a problem!
		throw new PersistenceLayerException("LstFileLoader.readFromURI() received a null uri parameter!");
	}

	URL url;
	try
	{
		url = uri.toURL();
	}
	catch (MalformedURLException e)
	{
		throw new PersistenceLayerException(
			"LstFileLoader.readFromURI() could not convert parameter to a URL: " + e.getLocalizedMessage(), e);
	}

	try
	{
		//only load local urls, unless loading of URLs is allowed
		if (!CoreUtility.isNetURL(url) || SettingsHandler.isLoadURLs())
		{
			InputStream inputStream = url.openStream();
			// Java doesn't handle BOM correctly. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
			try (var bomInputStream = new BOMInputStream(inputStream))
			{
				return new String(bomInputStream.readAllBytes(), StandardCharsets.UTF_8);
			}
		}
		else
		{
			// Just to protect people from using web
			// sources without their knowledge,
			// we added a preference.
			ShowMessageDelegate.showMessageDialog("Preferences are currently set to NOT allow\nloading of "
				+ "sources from web links. \n" + url + " is a web link", Constants.APPLICATION_NAME,
				MessageType.ERROR);
		}
	}
	catch (IOException ioe)
	{
		// Don't throw an exception here because a simple
		// file not found will prevent ANY other files from
		// being loaded/processed -- NOT what we want
		Logging.errorPrint("ERROR:" + url + '\n' + "Exception type:" + ioe.getClass().getName() + "\n" + "Message:"
			+ ioe.getMessage(), ioe);
	}
	return null;
}
 
Example 7
Source File: LstFileLoader.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method reads the given URL and stores its contents in the provided
 * data buffer, returning a URL to the specified file for use in log/error
 * messages by its caller.
 *
 * @param uri        String path of the URL to read -- MUST be a URL path,
 *                   not a file!
 * @return URL pointing to the actual file read, for use in debug/log
 *         messages
 * @throws PersistenceLayerException 
 */
@Nullable
public static String readFromURI(URI uri) throws PersistenceLayerException
{
	if (uri == null)
	{
		// We have a problem!
		throw new PersistenceLayerException("LstFileLoader.readFromURI() received a null uri parameter!");
	}

	URL url;
	try
	{
		url = uri.toURL();
	}
	catch (MalformedURLException e)
	{
		throw new PersistenceLayerException(
			"LstFileLoader.readFromURI() could not convert parameter to a URL: " + e.getLocalizedMessage(), e);
	}

	try
	{
		//only load local urls, unless loading of URLs is allowed
		if (!CoreUtility.isNetURL(url) || SettingsHandler.isLoadURLs())
		{
			InputStream inputStream = url.openStream();
			// Java doesn't handle BOM correctly. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
			try (var bomInputStream = new BOMInputStream(inputStream))
			{
				return new String(bomInputStream.readAllBytes(), StandardCharsets.UTF_8);
			}
		}
		else
		{
			// Just to protect people from using web
			// sources without their knowledge,
			// we added a preference.
			ShowMessageDelegate.showMessageDialog("Preferences are currently set to NOT allow\nloading of "
				+ "sources from web links. \n" + url + " is a web link", Constants.APPLICATION_NAME,
				MessageType.ERROR);
		}
	}
	catch (IOException ioe)
	{
		// Don't throw an exception here because a simple
		// file not found will prevent ANY other files from
		// being loaded/processed -- NOT what we want
		Logging.errorPrint("ERROR:" + url + '\n' + "Exception type:" + ioe.getClass().getName() + "\n" + "Message:"
			+ ioe.getMessage(), ioe);
	}
	return null;
}
 
Example 8
Source File: WorkspacesManagerServiceImpl.java    From geofence with GNU General Public License v2.0 4 votes vote down vote up
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
            {
                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>();

                    if (workspace.equals("*")) { // load all layers
                        RESTAbstractList<NameLinkElem> layers = gsreader.getLayers();
                    	if (layers != null)
                    		for (NameLinkElem layerLink : layers) {
                    			sortedLayerNames.add(layerLink.getName());
                    		}
                    } else {

                        if(StringUtils.isBlank(workspace))
                            throw new ApplicationException("A workspace name is needed");

                        sortedLayerNames = getWorkspaceLayers(gsreader, workspace);
                    }
                    // 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());
    }