List of usage examples for java.net MalformedURLException MalformedURLException
public MalformedURLException(String msg)
From source file:org.apache.cocoon.components.source.impl.ModuleSource.java
/** * Create a module source from a 'module:' uri and a the object model. * <p>The uri is of the form "module:attribute-type:attribute-name#xpath</p> *//*from w ww.java2s . c o m*/ public ModuleSource(Map objectModel, String uri, ServiceManager manager, Logger logger) throws MalformedURLException { this.objectModel = objectModel; this.manager = manager; this.logger = logger; setSystemId(uri); // Scheme int start = 0; int end = uri.indexOf(':'); if (end == -1) throw new MalformedURLException("Malformed uri for module source (cannot find scheme) : " + uri); String scheme = uri.substring(start, end); if (!SCHEME.equals(scheme)) throw new MalformedURLException("Malformed uri for a module source : " + uri); setScheme(scheme); // Attribute type start = end + 1; end = uri.indexOf(':', start); if (end == -1) { throw new MalformedURLException( "Malformed uri for module source (cannot find attribute type) : " + uri); } this.attributeType = uri.substring(start, end); // Attribute name start = end + 1; end = uri.indexOf('#', start); if (end == -1) end = uri.length(); if (end == start) throw new MalformedURLException( "Malformed uri for module source (cannot find attribute name) : " + uri); this.attributeName = uri.substring(start, end); // xpath start = end + 1; this.xPath = start < uri.length() ? uri.substring(start) : ""; }
From source file:com.ikanow.infinit.e.harvest.extraction.document.file.InfiniteFile.java
protected InfiniteFile(String url) throws IOException { try {/*w ww .jav a 2s .com*/ if (url.startsWith("file://")) { _localFile = new File(url.substring(7)); // ie "file://", path is relative to ~tomcat I guess } else if (url.startsWith("file:")) { // (apparently the jcifs doesn't need the "//" bit in file) _localFile = new File(url.substring(5)); // ie "file:", path is relative to ~tomcat I guess } else { _smbFile = new SmbFile(url); if (!_smbFile.exists()) { throw new MalformedURLException(url + " NOT FOUND"); } } } catch (SmbException e) { throw new IOException(e.getMessage(), e); } }
From source file:com.android.yijiang.kzx.http.AsyncHttpRequest.java
private void makeRequest() throws IOException { if (isCancelled()) { return;/*from w w w.j ava 2 s . c om*/ } // Fixes #115 if (request.getURI().getScheme() == null) { // subclass of IOException so processed in the caller throw new MalformedURLException("No valid URI scheme was provided"); } HttpResponse response = client.execute(request, context); if (!isCancelled() && responseHandler != null) { responseHandler.sendResponseMessage(response); } }
From source file:com.ab.http.AsyncHttpRequest.java
/** * Make request./*from w w w .ja v a 2s . c om*/ * * @throws IOException Signals that an I/O exception has occurred. */ private void makeRequest() throws IOException { if (!Thread.currentThread().isInterrupted()) { // Fixes #115 if (request.getURI().getScheme() == null) { // subclass of IOException so processed in the caller throw new MalformedURLException("No valid URI scheme was provided"); } HttpResponse response = client.execute(request, context); if (!Thread.currentThread().isInterrupted()) { if (responseHandler != null) { responseHandler.sendResponseMessage(response); } } } }
From source file:com.messi.languagehelper_ja.http.AsyncHttpRequest.java
private void makeRequest() throws IOException { if (isCancelled()) { return;/*from w w w .j a v a 2s . c om*/ } // Fixes #115 if (request.getURI().getScheme() == null) { // subclass of IOException so processed in the caller throw new MalformedURLException("No valid URI scheme was provided"); } LogUtil.DefalutLog("request:" + request.getURI()); HttpResponse response = client.execute(request, context); if (!isCancelled() && responseHandler != null) { responseHandler.sendResponseMessage(response); } }
From source file:com.lhtechnologies.DoorApp.AuthenticatorService.java
@Override protected void onHandleIntent(Intent intent) { if (intent.getAction().equals(stopAction)) { stopSelf();//w w w . ja va 2 s .c o m } else if (intent.getAction().equals(authenticateAction)) { //Check if we want to open the front door or flat door String doorToOpen = FrontDoor; String authCode = null; if (intent.hasExtra(FlatDoor)) { doorToOpen = FlatDoor; authCode = intent.getCharSequenceExtra(FlatDoor).toString(); } if (intent.hasExtra(LetIn)) { doorToOpen = LetIn; } //Now run the connection code (Hope it runs asynchronously and we do not need AsyncTask --- NOPE --YES urlConnection = null; URL url; //Prepare the return intent Intent broadcastIntent = new Intent(AuthenticationFinishedBroadCast); try { //Try to create the URL, return an error if it fails url = new URL(address); if (!url.getProtocol().equals("https")) { throw new MalformedURLException("Please only use https protocol!"); } String password = "password"; KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(getResources().getAssets().open("LH Technologies Root CA.bks"), password.toCharArray()); TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509"); tmf.init(keyStore); SSLContext context = SSLContext.getInstance("TLS"); context.init(null, tmf.getTrustManagers(), null); urlConnection = (HttpsURLConnection) url.openConnection(); urlConnection.setSSLSocketFactory(context.getSocketFactory()); urlConnection.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); urlConnection.setConnectTimeout(15000); urlConnection.setRequestMethod("POST"); urlConnection.setDoOutput(true); urlConnection.setChunkedStreamingMode(0); OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream()); //Write our stuff to the output stream; out.write("deviceName=" + deviceName + "&udid=" + udid + "&secret=" + secret + "&clientVersion=" + clientVersion + "&doorToOpen=" + doorToOpen); if (doorToOpen.equals(FlatDoor)) { out.write("&authCode=" + authCode); //Put an extra in so the return knows we opened the flat door broadcastIntent.putExtra(FlatDoor, FlatDoor); } out.close(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); //Read the answer String decodedString; String returnString = ""; while ((decodedString = in.readLine()) != null) { returnString += decodedString; } in.close(); broadcastIntent.putExtra(AuthenticatorReturnCode, returnString); } catch (MalformedURLException e) { broadcastIntent.putExtra(AuthenticatorReturnCode, ClientErrorMalformedURL); } catch (Exception e) { broadcastIntent.putExtra(AuthenticatorReturnCode, ClientErrorUndefined); broadcastIntent.putExtra(AuthenticatorErrorDescription, e.getLocalizedMessage()); } finally { if (urlConnection != null) urlConnection.disconnect(); //Now send a broadcast with the result sendOrderedBroadcast(broadcastIntent, null); Log.e(this.getClass().getSimpleName(), "Send Broadcast!"); } } }
From source file:uk.ac.ucl.cs.cmic.giftcloud.restserver.GiftCloudServer.java
public boolean matchesServer(final String giftCloudUrl) throws MalformedURLException { try {/*from www .java 2 s . c o m*/ final URI uri = new URI(giftCloudUrl); return (uri.equals(giftCloudUri)); } catch (URISyntaxException e) { throw new MalformedURLException("The GIFT-Cloud server name " + giftCloudUrl + " is not a valid URL."); } }
From source file:org.wso2.appserver.integration.common.clients.AARServiceUploaderClient.java
private DataHandler createDataHandler(String filePath) throws MalformedURLException { URL url = null;//from ww w. ja va 2 s . co m try { url = new URL("file://" + filePath); } catch (MalformedURLException e) { log.error("File path URL is invalid" + e); throw new MalformedURLException("File path URL is invalid" + e); } DataHandler dh = new DataHandler(url); return dh; }
From source file:org.cruk.genologics.api.impl.URLInputStreamResource.java
/** * Create a new resource around the given URL. * * @param url The URL of the resource.//from w ww.java 2 s . c o m * @param bufferSize The size of the buffer around the URL's input * stream. If this is zero or less, no buffer will be put in place. * * @throws IOException if the resource cannot be accessed or the * URL does not allow connection. */ public URLInputStreamResource(URL url, int bufferSize) throws IOException { if (url == null) { throw new IllegalArgumentException("url cannot be null"); } this.url = url; try { uri = url.toURI(); } catch (URISyntaxException e) { throw new MalformedURLException(e.getMessage()); } connection = url.openConnection(); inputStream = connection.getInputStream(); if (bufferSize > 0) { inputStream = new BufferedInputStream(inputStream, bufferSize); } try { httpConnection = (HttpURLConnection) connection; exists = httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK; } catch (ClassCastException e) { // Fine, not HTTP. } if ("file".equals(url.getProtocol())) { try { file = new File(url.toURI()); } catch (URISyntaxException e) { throw new MalformedURLException(e.getMessage()); } catch (IllegalArgumentException e) { throw new FileNotFoundException(url + " cannot be resolved to a local file path."); } } }
From source file:com.ikanow.infinit.e.harvest.extraction.document.file.InfiniteFile.java
protected InfiniteFile(String url, NtlmPasswordAuthentication auth) throws IOException { try {/*from w w w .j a v a 2s. co m*/ _smbFile = new SmbFile(url, auth); _auth = auth; if (!_smbFile.exists()) { throw new MalformedURLException(url + " NOT FOUND"); } } catch (SmbException e) { throw new IOException(e.getMessage(), e); } }