List of usage examples for java.net MalformedURLException MalformedURLException
public MalformedURLException()
From source file:org.fourthline.cling.model.meta.Icon.java
public List<ValidationError> validate() { List<ValidationError> errors = new ArrayList<ValidationError>(); if (getMimeType() == null) { log.warning("UPnP specification violation of: " + getDevice()); log.warning("Invalid icon, missing mime type: " + this); }// ww w .j ava2s .c o m if (getWidth() == 0) { log.warning("UPnP specification violation of: " + getDevice()); log.warning("Invalid icon, missing width: " + this); } if (getHeight() == 0) { log.warning("UPnP specification violation of: " + getDevice()); log.warning("Invalid icon, missing height: " + this); } if (getDepth() == 0) { log.warning("UPnP specification violation of: " + getDevice()); log.warning("Invalid icon, missing bitmap depth: " + this); } if (getUri() == null) { errors.add(new ValidationError(getClass(), "uri", "URL is required")); } try { URL testURI = getUri().toURL(); if (testURI == null) throw new MalformedURLException(); } catch (MalformedURLException ex) { errors.add(new ValidationError(getClass(), "uri", "URL must be valid: " + ex.getMessage())); } catch (IllegalArgumentException ex) { // Relative URI is fine here! } return errors; }
From source file:org.globus.gsi.jsse.GlobusSSLHelper.java
private static InputStream getStream(String url) throws MalformedURLException, IOException { if (url.startsWith("classpath:")) { String resource = url.substring(10); URL u = ClassLoader.class.getResource(resource); if (u == null) { throw new MalformedURLException(); }// ww w.j ava 2 s . com return u.openStream(); } else if (url.startsWith("file:")) { URL u = new URL(url); File f; try { f = new File(u.toURI()); } catch (URISyntaxException e) { f = new File(u.getPath()); } return new FileInputStream(f); } else { return new URL(url).openStream(); } }
From source file:jettyClient.simpleClient.Parameters.java
/** * Attempts to create an URL from the given parameter. * /* www. j a va2 s .c o m*/ * @param string * A string value that will be turned into an URL. * @return An URL with the value of the given string. */ public static URL getURL(String string) { URL url = null; try { url = new URL(string); if (url.getPort() == -1) { System.out.println("Error: Missing port number in URL."); logger.info("Error: Missing port number in URL." + string); throw new MalformedURLException(); } } catch (MalformedURLException e) { url = null; logger.info("Malformed endpoint URL: " + string); } return url; }
From source file:org.pentaho.di.baserver.utils.web.HttpConnectionHelperTest.java
@Test public void testInvokePlatformEndpoint() throws Exception { Response r;//from www. j a v a2 s . c o m String endpointPath = "myEndpoint", httpMethod = "GET"; Map<String, String> queryParameters = new HashMap<String, String>(); queryParameters.put("param1", "value1"); queryParameters.put("param2", "value2"); queryParameters.put("param3", "value3"); RequestDispatcher requestDispatcher = mock(RequestDispatcher.class); ServletContext context = mock(ServletContext.class); doThrow(new NoClassDefFoundError()).when(httpConnectionHelperSpy).getContext(); r = httpConnectionHelperSpy.invokePlatformEndpoint(endpointPath, httpMethod, queryParameters); assertTrue(r.getResult().equals(new Response().getResult())); doReturn(context).when(httpConnectionHelperSpy).getContext(); doReturn(requestDispatcher).when(context).getRequestDispatcher("/api" + endpointPath); doThrow(new MalformedURLException()).when(httpConnectionHelperSpy).getUrl(); r = httpConnectionHelperSpy.invokePlatformEndpoint(endpointPath, httpMethod, queryParameters); assertTrue(r.getResult().equals(new Response().getResult())); String serverUrl = "http://localhost:8080/pentaho"; URL url = new URL(serverUrl); doReturn(url).when(httpConnectionHelperSpy).getUrl(); doThrow(new ServletException()).when(requestDispatcher).forward(any(InternalHttpServletRequest.class), any(InternalHttpServletResponse.class)); r = httpConnectionHelperSpy.invokePlatformEndpoint(endpointPath, httpMethod, queryParameters); assertTrue(r.getResult().equals(new Response().getResult())); doThrow(new IOException()).when(requestDispatcher).forward(any(InternalHttpServletRequest.class), any(InternalHttpServletResponse.class)); r = httpConnectionHelperSpy.invokePlatformEndpoint(endpointPath, httpMethod, queryParameters); assertTrue(r.getResult().equals(new Response().getResult())); doNothing().when(requestDispatcher).forward(any(InternalHttpServletRequest.class), any(InternalHttpServletResponse.class)); r = httpConnectionHelperSpy.invokePlatformEndpoint(endpointPath, httpMethod, queryParameters); assertEquals(r.getStatusCode(), 204); }
From source file:org.wandora.utils.DataURL.java
private void parseDataURL(String dataURL) throws MalformedURLException { if (dataURL != null && dataURL.length() > 0) { if (dataURL.startsWith("data:")) { dataURL = dataURL.substring("data:".length()); int mimeTypeEndIndex = dataURL.indexOf(';'); if (mimeTypeEndIndex > 0) { mimetype = dataURL.substring(0, mimeTypeEndIndex); dataURL = dataURL.substring(mimeTypeEndIndex + 1); }/*from w ww. ja va2s .co m*/ int encodingEndIndex = dataURL.indexOf(','); if (encodingEndIndex > 0) { encoding = dataURL.substring(0, encodingEndIndex); dataURL = dataURL.substring(encodingEndIndex + 1); } if ("base64".equalsIgnoreCase(encoding)) { data = Base64.decode(dataURL); } else { data = dataURL.getBytes(); } } else { throw new MalformedURLException(); } } else { throw new MalformedURLException(); } }
From source file:com.qddagu.app.meetreader.ui.MainActivity.java
private boolean validateUrl(String url) { boolean flag = true; try {//from ww w. j a v a 2 s . c o m if (!new URL(url).getPath().contains("meeting")) throw new MalformedURLException(); } catch (MalformedURLException e) { UIHelper.ToastMessage(this, "????"); } return flag; }
From source file:org.peterbaldwin.client.android.tinyurl.SendTinyUrlActivity.java
/** * {@inheritDoc}/*from w w w .j a v a2s . c o m*/ */ public void run() { if (!Util.isValidUrl(mUrl)) { sendError(new MalformedURLException()); return; } try { HttpClient client = new DefaultHttpClient(); String urlTemplate = "http://tinyurl.com/api-create.php?url=%s"; String uri = String.format(urlTemplate, URLEncoder.encode(mUrl)); HttpGet request = new HttpGet(uri); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); InputStream in = entity.getContent(); try { StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == HttpStatus.SC_OK) { // TODO: Support other encodings String enc = "utf-8"; Reader reader = new InputStreamReader(in, enc); BufferedReader bufferedReader = new BufferedReader(reader); String tinyUrl = bufferedReader.readLine(); if (tinyUrl != null) { sendUrl(tinyUrl); } else { throw new IOException("empty response"); } } else { String errorTemplate = "unexpected response: %d"; String msg = String.format(errorTemplate, statusCode); throw new IOException(msg); } } finally { in.close(); } } catch (IOException e) { sendError(e); } catch (RuntimeException e) { sendError(e); } catch (Error e) { sendError(e); } }
From source file:org.bibsonomy.webapp.controller.admin.AdminRecommenderController.java
private void handleEditRecommender(final AdminRecommenderViewCommand command) { try {//from w w w . j a v a2s . c o m // TODO: add a validator? if (!UrlUtils.isValid(command.getNewrecurl())) throw new MalformedURLException(); final URL newRecurl = new URL(command.getNewrecurl()); final long sid = command.getEditSid(); final boolean recommenderEnabled = mp.disableRecommender(sid); db.updateRecommenderUrl(command.getEditSid(), newRecurl); if (recommenderEnabled) mp.enableRecommender(sid); command.setAdminResponse( "Changed url of recommender #" + command.getEditSid() + " to " + command.getNewrecurl() + "."); } catch (final MalformedURLException ex) { command.setAdminResponse( "Could not edit recommender. Please check if '" + command.getNewrecurl() + "' is a valid url."); } catch (final SQLException e) { log.warn("SQLException while editing recommender", e); command.setAdminResponse(e.getMessage()); } command.setNewrecurl(null); command.setTab(Tab.ADD); }
From source file:org.sufficientlysecure.keychain.ui.dialog.AddKeyserverDialogFragment.java
public void verifyConnection(String keyserver) { new AsyncTask<String, Void, FailureReason>() { ProgressDialog mProgressDialog;/*from ww w.j a v a 2 s .co m*/ String mKeyserver; @Override protected void onPreExecute() { mProgressDialog = new ProgressDialog(getActivity()); mProgressDialog.setMessage(getString(R.string.progress_verifying_keyserver_url)); mProgressDialog.setCancelable(false); mProgressDialog.show(); } @Override protected FailureReason doInBackground(String... keyservers) { mKeyserver = keyservers[0]; FailureReason reason = null; try { // replace hkps/hkp scheme and reconstruct Uri Uri keyserverUri = Uri.parse(mKeyserver); String scheme = keyserverUri.getScheme(); String schemeSpecificPart = keyserverUri.getSchemeSpecificPart(); String fragment = keyserverUri.getFragment(); if (scheme == null) throw new MalformedURLException(); if (scheme.equalsIgnoreCase("hkps")) scheme = "https"; else if (scheme.equalsIgnoreCase("hkp")) scheme = "http"; URI newKeyserver = new URI(scheme, schemeSpecificPart, fragment); Log.d("Converted URL", newKeyserver.toString()); TlsHelper.openConnection(newKeyserver.toURL()).getInputStream(); } catch (TlsHelper.TlsHelperException e) { reason = FailureReason.CONNECTION_FAILED; } catch (MalformedURLException e) { Log.w(Constants.TAG, "Invalid keyserver URL entered by user."); reason = FailureReason.INVALID_URL; } catch (URISyntaxException e) { Log.w(Constants.TAG, "Invalid keyserver URL entered by user."); reason = FailureReason.INVALID_URL; } catch (IOException e) { Log.w(Constants.TAG, "Could not connect to entered keyserver url"); reason = FailureReason.CONNECTION_FAILED; } return reason; } @Override protected void onPostExecute(FailureReason failureReason) { mProgressDialog.dismiss(); if (failureReason == null) { addKeyserver(mKeyserver, true); } else { verificationFailed(failureReason); } } }.execute(keyserver); }