List of usage examples for java.net MalformedURLException getLocalizedMessage
public String getLocalizedMessage()
From source file:TimestreamsTests.java
/** * Tests posting to /context with valid parameters */// w w w. jav a 2s. c om @Test public void testPostContextLegit() { try { long time = new Date().getTime(); String now = Long.toString(time).substring(0, 10); String type = "place"; String value = "Nottingham"; String start = "2012-11-12 10:10:23"; String end = "2012-11-12 10:20:23"; String user = "1"; List<String> params = new ArrayList<String>(); params.add(PUBKEY); params.add(now); params.add(type); params.add(value); params.add(start); params.add(end); params.add(user); String hmac = getSecurityString(params); String paramsstr = "type=" + URLEncoder.encode(type, "UTF-8") + "&value=" + URLEncoder.encode(value, "UTF-8") + "&start=" + URLEncoder.encode(start, "UTF-8") + "&end=" + URLEncoder.encode(end, "UTF-8") + "&user=" + URLEncoder.encode(user, "UTF-8") + "&pubkey=" + URLEncoder.encode(PUBKEY, "UTF-8") + "&now=" + URLEncoder.encode(now, "UTF-8") + "&hmac=" + URLEncoder.encode(hmac, "UTF-8"); ; // System.out.println("paramsstr: " + paramsstr); URL url = new URL(BASEURL + "/context"); postTest(url, paramsstr); } catch (MalformedURLException e) { fail(e.getLocalizedMessage()); } catch (UnsupportedEncodingException e) { fail(e.getLocalizedMessage()); } }
From source file:TimestreamsTests.java
/** * Tests posting to /measurement_container with valid parameters *//*from w ww . ja v a2 s.co m*/ @Test public void testPostMCLegit() { try { long time = new Date().getTime(); String now = Long.toString(time).substring(0, 10); String name = "testPostMCLegit" + new Random().nextInt(); String measuretype = "testPostMCLegit"; String unit = "unit=text/x-data-test"; String device = "testDev"; String datatype = "DECIMAL(5,2)"; String siteid = "1"; String blogid = "1"; String userid = "1"; List<String> params = new ArrayList<String>(); params.add(PUBKEY); params.add(now); params.add(name); params.add(measuretype); params.add(unit); params.add(device); params.add(datatype); params.add(siteid); params.add(blogid); params.add(userid); String hmac = getSecurityString(params); String paramsstr = "name=" + URLEncoder.encode(name, "UTF-8") + "&measuretype=" + URLEncoder.encode(measuretype, "UTF-8") + "&unit=" + URLEncoder.encode(unit, "UTF-8") + "&device=" + URLEncoder.encode(device, "UTF-8") + "&datatype=" + URLEncoder.encode(datatype, "UTF-8") + "&siteid=" + URLEncoder.encode(siteid, "UTF-8") + "&blogid=" + URLEncoder.encode(blogid, "UTF-8") + "&userid=" + URLEncoder.encode(userid, "UTF-8") + "&pubkey=" + URLEncoder.encode(PUBKEY, "UTF-8") + "&now=" + URLEncoder.encode(now, "UTF-8") + "&hmac=" + URLEncoder.encode(hmac, "UTF-8"); // System.out.println("paramsstr: " + paramsstr); URL url = new URL(BASEURL + "/measurement_container"); postTest(url, paramsstr); } catch (MalformedURLException e) { fail(e.getLocalizedMessage()); } catch (UnsupportedEncodingException e) { fail(e.getLocalizedMessage()); } }
From source file:com.mindquarry.desktop.preferences.pages.ServerProfilesPage.java
private boolean checkProfileValidity(Profile profile, boolean currentlyDisplayed) { if (profile.getType() == Profile.Type.MindquarryServer) { // check server endpoint if (profile.getServerURL() == null) { if (!currentlyDisplayed) return false; setInvalid(I18N.get("Server URL must be set."), url); return false; } else {/* w w w. j a va 2s . c o m*/ try { new URL(profile.getServerURL()); } catch (MalformedURLException e) { if (!currentlyDisplayed) return false; setInvalid(I18N.get("Server URL is not a valid URL ({0})", e.getLocalizedMessage()), url); return false; } } // check login ID if (profile.getLogin() == null) { if (!currentlyDisplayed) return false; setInvalid(I18N.get("Login ID must be set."), login); return false; } else if (profile.getLogin().equals("")) { if (!currentlyDisplayed) return false; setInvalid(I18N.get("Login ID must not be empty."), login); return false; } // check password if (profile.getPassword() == null) { if (!currentlyDisplayed) return false; setInvalid(I18N.get("Password must be set."), pwd); return false; } else if (profile.getPassword().equals("")) { if (!currentlyDisplayed) return false; setInvalid(I18N.get("Password can not be empty."), pwd); return false; } // check workspace folder if (profile.getWorkspaceFolder() == null) { if (!currentlyDisplayed) return false; setInvalid(I18N.get("Workspace folder must be set."), folder); return false; } else { File file = new File(profile.getWorkspaceFolder()); if (!file.exists()) { if (!currentlyDisplayed) return false; setInvalid(I18N.get("Workspace folder does not exist."), folder); return false; } else if (!file.isDirectory()) { if (!currentlyDisplayed) return false; setInvalid(I18N.get("Workspace folder is a file, not a directory."), folder); return false; } } } return true; }
From source file:com.mindquarry.desktop.preferences.pages.ServerProfilesPage.java
private void createMindquarryServerSettings(Composite parent) { mqServerSettings = new Composite(parent, SWT.NORMAL); mqServerSettings.setLayoutData(new GridData(GridData.FILL_BOTH)); mqServerSettings.setLayout(new GridLayout(1, true)); // initialize server URL section CLabel quarryEndpointLabel = new CLabel(mqServerSettings, SWT.LEFT); quarryEndpointLabel.setText(I18N.get("URL of the Mindquarry Server:")); //$NON-NLS-1$ quarryEndpointLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Composite errorComp = createErrorBorderComposite(mqServerSettings, 1); url = new Text(errorComp, SWT.SINGLE | SWT.BORDER); registerErrorBorderComposite(errorComp, url); url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); url.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { String[] selection = profileList.getSelection(); if (selection.length > 0) { Profile profile = findByName(selection[0]); profile.setServerURL(url.getText()); performValidation();//from ww w .j a v a 2 s .c om } } }); url.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { url.selectAll(); } }); // initialize login section CLabel loginLabel = new CLabel(mqServerSettings, SWT.LEFT); loginLabel.setText(I18N.get("Your Login ID:")); //$NON-NLS-1$ loginLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); errorComp = createErrorBorderComposite(mqServerSettings, 1); login = new Text(errorComp, SWT.SINGLE | SWT.BORDER); registerErrorBorderComposite(errorComp, login); login.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); login.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { String[] selection = profileList.getSelection(); if (selection.length > 0) { Profile profile = findByName(selection[0]); profile.setLogin(login.getText()); performValidation(); } } }); login.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { login.selectAll(); } }); // initialize password section CLabel pwdLabel = new CLabel(mqServerSettings, SWT.LEFT); pwdLabel.setText(I18N.get("Your Password:")); //$NON-NLS-1$ pwdLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); errorComp = createErrorBorderComposite(mqServerSettings, 1); pwd = new Text(errorComp, SWT.PASSWORD | SWT.BORDER); registerErrorBorderComposite(errorComp, pwd); pwd.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); pwd.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { String[] selection = profileList.getSelection(); if (selection.length > 0) { Profile profile = findByName(selection[0]); profile.setPassword(pwd.getText()); performValidation(); } } }); pwd.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { pwd.selectAll(); } }); // init verify server button Composite verifyArea = new Composite(mqServerSettings, SWT.NONE); verifyArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout layout = new GridLayout(2, false); layout.marginBottom = 0; layout.marginTop = 0; layout.marginLeft = 0; layout.marginRight = 0; layout.marginHeight = 0; layout.marginWidth = 0; verifyArea.setLayout(layout); Button verifyServerButton = new Button(verifyArea, SWT.LEFT | SWT.PUSH); verifyServerButton.setText(I18N.get("Verify server settings")); final CLabel verifiedLabel = new CLabel(verifyArea, SWT.WRAP); verifiedLabel.setLayoutData(new GridData(300, 20)); verifyServerButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { try { HttpUtilities.CheckResult result = HttpUtilities.checkServerExistence(login.getText(), pwd.getText(), url.getText()); if (HttpUtilities.CheckResult.AUTH_REFUSED == result) { String msg = I18N.get("Login ID or password is incorrect."); setInvalid(msg, login, pwd); verifiedLabel.setText(msg); verifiedLabel.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR)); } else if (HttpUtilities.CheckResult.NOT_AVAILABLE == result) { String msg = I18N.get("Server could not be found."); setInvalid(msg, url); verifiedLabel.setText(msg); verifiedLabel.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR)); } else { setValid(); String msg = I18N.get("Server settings are correct."); setMessage(msg, INFORMATION); verifiedLabel.setText(msg); verifiedLabel.setImage(OK_IMAGE); } } catch (MalformedURLException murle) { String msg = I18N.get("Server URL is not a valid URL ({0})", murle.getLocalizedMessage()); setInvalid(msg, url); verifiedLabel.setText(msg); verifiedLabel.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR)); } verifiedLabel.getParent().layout(); } }); // initialize workspace folder section CLabel locationLabel = new CLabel(mqServerSettings, SWT.LEFT); locationLabel.setText(I18N.get("Folder for Workspaces:")); //$NON-NLS-1$ locationLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Composite locationArea = new Composite(mqServerSettings, SWT.NONE); locationArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); layout = new GridLayout(2, false); layout.marginBottom = 0; layout.marginTop = 0; layout.marginLeft = 0; layout.marginRight = 0; layout.marginHeight = 0; layout.marginWidth = 0; locationArea.setLayout(layout); errorComp = createErrorBorderComposite(locationArea, 1); folder = new Text(errorComp, SWT.BORDER); registerErrorBorderComposite(errorComp, folder); folder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); folder.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { String[] selection = profileList.getSelection(); if (selection.length > 0) { Profile profile = findByName(selection[0]); profile.setWorkspaceFolder(folder.getText()); performValidation(); } } }); folder.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { folder.selectAll(); } }); Button selectWSLocationButton = new Button(locationArea, SWT.PUSH); selectWSLocationButton.setText(I18N.get("Browse")); //$NON-NLS-1$ selectWSLocationButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { DirectoryDialog fd = new DirectoryDialog(getShell(), SWT.OPEN); fd.setText(I18N.get("Select folder for workspaces.")); //$NON-NLS-1$ String path = fd.open(); if (path != null) { folder.setText(path); } } }); }
From source file:com.mindquarry.desktop.client.MindClient.java
private boolean addNewProfile(String name, String endpoint, String login) { // add new profile entry Profile profile = new Profile(); profile.setName(name);// w ww. ja va 2 s . c om profile.setServerURL(endpoint); profile.setLogin(login); profile.setPassword(""); //$NON-NLS-1$ File wsFolder = new File(System.getProperty("user.home") //$NON-NLS-1$ + "/Mindquarry Workspaces"); //$NON-NLS-1$ if (!wsFolder.exists()) { wsFolder.mkdirs(); } URL url; try { url = new URL(endpoint); profile.setWorkspaceFolder(wsFolder.getAbsolutePath() + "/" + url.getHost()); } catch (MalformedURLException e) { MessageDialog.openError(getShell(), I18N.getString("Error"), e.getLocalizedMessage()); // FIXME: what should be done here??? // profile.setWorkspaceFolder(wsFolder.getAbsolutePath()); } return Profile.addProfile(store, profile); }
From source file:org.openhab.binding.megadevice.internal.MegaDeviceBinding.java
private void SendCommand(String itemName, String newState) { int state = 0; HttpURLConnection con;// ww w. j ava 2 s .c o m for (MegaDeviceBindingProvider provider : providers) { logger.debug("SendCommand exec"); for (String itemname : provider.getItemNames()) { // logger.debug(itemname +" has type "+ // provider.getItemType(itemName).toString()); if ((itemname.equals(itemName)) && (provider.getItemType(itemname).toString().contains("SwitchItem"))) { if (newState.equals("ON")) { state = 1; } else if (newState.equals("OFF")) { state = 0; } URL MegaURL; String Result = "http://" + provider.getIP(itemName) + "/" + provider.password(itemName) + "/?cmd=" + provider.getPORT(itemName) + ":" + state; logger.debug("Switch: " + Result); try { MegaURL = new URL(Result); con = (HttpURLConnection) MegaURL.openConnection(); // optional default is GET con.setRequestMethod("GET"); con.setConnectTimeout(500); con.setReadTimeout(500); // add request header con.setRequestProperty("User-Agent", "Mozilla/5.0"); if (con.getResponseCode() == 200) { logger.debug("OK"); } con.disconnect(); } catch (MalformedURLException e) { logger.debug("1" + e); e.printStackTrace(); } catch (ProtocolException e) { logger.debug("2" + e); e.printStackTrace(); } catch (IOException e) { logger.debug(e.getLocalizedMessage()); e.printStackTrace(); } } else if ((itemname.equals(itemName)) && (provider.getItemType(itemname).toString().contains("DimmerItem"))) { int result = (int) Math.round(Integer.parseInt(newState) * 2.55); logger.debug("Dimmer value-> " + result); URL MegaURL; String Result = "http://" + provider.getIP(itemName) + "/" + provider.password(itemName) + "/?cmd=" + provider.getPORT(itemName) + ":" + result; logger.debug("dimmer:", Result); try { MegaURL = new URL(Result); con = (HttpURLConnection) MegaURL.openConnection(); // optional default is GET con.setRequestMethod("GET"); con.setConnectTimeout(500); con.setReadTimeout(500); // add request header con.setRequestProperty("User-Agent", "Mozilla/5.0"); if (con.getResponseCode() == 200) { logger.debug("OK"); } con.disconnect(); } catch (MalformedURLException e) { logger.error("1" + e); e.printStackTrace(); } catch (ProtocolException e) { logger.error("2" + e); e.printStackTrace(); } catch (IOException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); } } else { // logger.error(itemname +"cannot determine type: " + // provider.getItemType(itemname).toString()); } } } }
From source file:org.silverpeas.core.importexport.control.ImportExport.java
/** * Mthode retournant l'arbre des objets mapps sur le fichier xml pass en paramtre. * @param xmlFileName le fichier xml interprt par JAXB * @return Un objet SilverPeasExchangeType contenant le mapping d'un fichier XML * @throws ImportExportException/*from w ww . j a v a 2 s.com*/ */ private SilverPeasExchangeType loadSilverpeasExchange(String xmlFileName) throws ImportExportException { try { File xmlInputSource = new File(xmlFileName); String xsdSystemId = settings.getString("xsdDefaultSystemId"); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new URL(xsdSystemId)); // Unmarshall the import model Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(new ImportExportErrorHandler()); SilverPeasExchangeType silverpeasExchange = (SilverPeasExchangeType) unmarshaller .unmarshal(xmlInputSource); return silverpeasExchange; } catch (JAXBException me) { throw new ImportExportException("ImportExport.loadSilverpeasExchange", "importExport.EX_UNMARSHALLING_FAILED", "XML Filename " + xmlFileName + ": " + me.getLocalizedMessage(), me); } catch (MalformedURLException ue) { throw new ImportExportException("ImportExport.loadSilverpeasExchange", "importExport.EX_UNMARSHALLING_FAILED", "XML Filename " + xmlFileName + ": " + ue.getLocalizedMessage(), ue); } catch (SAXException ve) { throw new ImportExportException("ImportExport.loadSilverpeasExchange", "importExport.EX_PARSING_FAILED", "XML Filename " + xmlFileName + ": " + ve.getLocalizedMessage(), ve); } }
From source file:org.apache.jmeter.JMeter.java
private void updatePath(String property, String sep, boolean cp) { String userpath = JMeterUtils.getPropDefault(property, "");// $NON-NLS-1$ if (userpath.length() <= 0) { return;/*w ww. java 2 s. c om*/ } log.info(property + "=" + userpath); //$NON-NLS-1$ StringTokenizer tok = new StringTokenizer(userpath, sep); while (tok.hasMoreTokens()) { String path = tok.nextToken(); File f = new File(path); if (!f.canRead() && !f.isDirectory()) { log.warn("Can't read " + path); } else { if (cp) { log.info("Adding to classpath and loader: " + path); try { NewDriver.addPath(path); } catch (MalformedURLException e) { log.warn("Error adding: " + path + " " + e.getLocalizedMessage()); } } else { log.info("Adding to loader: " + path); NewDriver.addURL(path); } } } }
From source file:edu.mit.mobile.android.locast.net.NetworkClient.java
/** * initializes//from w w w . j a va 2s .c o m */ protected synchronized void loadWithoutAccount() { final String baseUrlString = getBaseUrlFromPreferences(mContext); try { setBaseUrl(baseUrlString); } catch (final MalformedURLException e) { Log.e(TAG, e.getLocalizedMessage(), e); } }
From source file:com.mindquarry.desktop.client.MindClient.java
/** * Displays an error message and prompts the user to check their credentials * in the preferences dialog, or to cancel. * //w ww . j a va 2 s. com * @param exception * Contains the error message to be displayed. * @return True if and only if preferences dialog was shown to user which * means that the credentials were potentially updated. */ public boolean handleMalformedURLException(MalformedURLException exception) { // create custom error message with the option to open the preferences // dialog MessageDialog messageDialog = new MessageDialog(getShell(), I18N.getString("Error"), //$NON-NLS-1$ null, I18N.get( "Invalid server URL given: {0}\n\nPlease check your server settings in the preferences dialog.", exception.getLocalizedMessage()), MessageDialog.ERROR, new String[] { I18N.getString("Go to preferences"), //$NON-NLS-1$ I18N.getString("Cancel") //$NON-NLS-1$ }, 0); int buttonClicked = messageDialog.open(); switch (buttonClicked) { case 0: // go to preferences showPreferenceDialog(true); return true; case 1: // cancel displayNotConnected(); return false; } return false; }