List of usage examples for java.net MalformedURLException getMessage
public String getMessage()
From source file:com.recomdata.transmart.data.export.util.FileWriterUtil.java
public void writeFile(String url, File outputURLFile) { try {//from www . j av a 2s .c o m URL celFileURL = new URL(url); ReadableByteChannel rbc = Channels.newChannel(celFileURL.openStream()); FileOutputStream fos = new FileOutputStream(outputURLFile); fos.getChannel().transferFrom(rbc, 0, 1 << 24); } catch (MalformedURLException e) { log.info("Bad URL: " + url); } catch (IOException e) { log.info("IO Error:" + e.getMessage()); } }
From source file:org.openintents.lib.DeliciousApiHelper.java
public boolean addPost(String itemUrl, String description, String extended, String[] tags, boolean shared) throws java.io.IOException { String rpc = mAPI + "posts/add?"; StringBuffer rpcBuf = new StringBuffer(); StringBuffer tagsBuf = new StringBuffer(); Element tag;// w ww .j a va 2 s . c om URL u = null; String dateStamp; //TODO: timestamps if (description == null || description.equals("")) { description = "no description"; } if (extended == null) { extended = new String(); } try { rpcBuf.append("&url=" + itemUrl); rpcBuf.append("&description=" + URLEncoder.encode(description, "UTF8")); rpcBuf.append("&extendend=" + URLEncoder.encode(extended, "UTF8")); int tagsLen = tags.length; if (mAPI.equals(MAGNOLIA_API)) { //Magnolia uses comma as tag separator,.. for (int i = 0; i < tagsLen; i++) { tagsBuf.append(URLEncoder.encode(tags[i]) + ","); } } else if (mAPI.equals(DELICIOUS_API)) { //while Delicious uses spaces for (int i = 0; i < tagsLen; i++) { tagsBuf.append(URLEncoder.encode(tags[i]) + " "); } } rpcBuf.append("&tags=" + tagsBuf.toString()); if (shared) { rpcBuf.append("&shared=yes"); } else { rpcBuf.append("&shared=no"); } rpcBuf.append("&replace=no"); } catch (Exception e) { Log.e(_TAG, "ERROR Encoding URL Parameters"); e.printStackTrace(); } rpc += rpcBuf.toString(); //rpc=rpcBuf.toString(); System.out.println("\n" + rpc + "\n"); try { u = new URL(rpc); } catch (java.net.MalformedURLException mu) { System.out.println("Malformed URL>>" + mu.getMessage()); } String s = ""; try { javax.net.ssl.HttpsURLConnection connection = (javax.net.ssl.HttpsURLConnection) u.openConnection(); //that's actualy pretty ugly to do, but a neede workaround for m5.rc15 javax.net.ssl.HostnameVerifier v = new org.apache.http.conn.ssl.AllowAllHostnameVerifier(); connection.setHostnameVerifier(v); //tru3 3v1l h4ack1ng ;) s = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next(); } catch (java.io.IOException ioe) { System.out.println("Error >>" + ioe.getMessage()); Log.e(_TAG, "Error >>" + ioe.getMessage()); } catch (Exception e) { Log.e(_TAG, "Error while excecuting HTTP method. URL is: " + u); System.out.println("Error while excecuting HTTP method. URL is: " + u); e.printStackTrace(); } if (s.equals("<result code=\"done\" />")) { // System.out.println("YEA!"); return true; } //System.out.println(s); return false; }
From source file:es.tekniker.framework.ktek.questionnaire.mng.server.OrionContextBrokerClient.java
public String queryContext(String codUser) { String strJSON = null;/*from w ww. j ava 2 s . c o m*/ HttpURLConnection conn = null; StringBuffer strBOutput = new StringBuffer(); boolean boolOK = true; String input = null; StringBuffer stbInput = new StringBuffer(); try { log.debug("queryContext Start "); conn = getOrionContextBrokerGEConnection(this.methodQueryContext, this.endpointOrionContextBroker, this.headerContentTypeJSON); stbInput.append("{\"entities\": [ {\"type\": \"" + this.typeContextValue + "\", \"isPattern\": \"false\", \"id\": \"" + codUser + "\"}]}"); input = stbInput.toString(); log.debug(input); OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); if (conn.getResponseCode() == 200) { log.debug("queryContext Response code " + conn.getResponseCode()); } else if (conn.getResponseCode() != 201) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } log.debug("queryContext OutputStream wrote"); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); log.debug("queryContext Waiting server response "); log.debug("queryContext Output from Server .... \n"); String output; while ((output = br.readLine()) != null) { strBOutput.append(output); log.debug(output); } conn.disconnect(); strJSON = strBOutput.toString(); boolOK = true; } catch (MalformedURLException e) { log.error("queryContext MalformedURLException " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { log.error("queryContext IOException " + e.getMessage()); e.printStackTrace(); } return strJSON; }
From source file:com.risevision.ui.server.utils.MakeRequestServlet.java
public RequestResponse makeRequest(HttpServletRequest request) throws Exception { RequestResponse response = new RequestResponse(); String requestUrl = request.getParameter("url"); if ((requestUrl != null) && (!requestUrl.isEmpty())) { try {/*ww w . ja va 2 s . c om*/ URL payload_url = new URL(requestUrl.replace(" ", "+")); HttpURLConnection urlConnection = (HttpURLConnection) payload_url.openConnection(); urlConnection.setReadTimeout(20000); urlConnection.setRequestMethod("GET"); // if ("oauth".equals(request.getParameter("authz")) && requestUrl.contains("api.twitter.com/1.1")) { // signTwitterRequest(request, urlConnection); // } response.responseBody = getResponseAsJson(urlConnection); response.responseCode = urlConnection.getResponseCode(); } catch (MalformedURLException e) { e.printStackTrace(); throw new Exception("Malformed URL, " + e.getMessage()); } catch (Exception e) { // e.printStackTrace(); log.log(Level.SEVERE, e.getMessage(), e); // log.severe("Exception - " + e.getMessage(), e); } } return response; }
From source file:ch.cyberduck.core.local.Local.java
@Override public String toURL() { try {//ww w.j a v a2s.c o m return new File(path).toURI().toURL().toString(); } catch (MalformedURLException e) { log.error(e.getMessage()); return null; } }
From source file:org.jboss.aerogear.android.unifiedpush.gcm.AeroGearGCMPushRegistrar.java
public AeroGearGCMPushRegistrar(AeroGearGCMPushConfiguration config) { this.senderIds = config.getSenderIds(); this.deviceToken = config.getDeviceToken(); this.variantId = config.getVariantID(); this.secret = config.getSecret(); this.deviceType = config.getDeviceType(); this.alias = config.getAlias(); this.operatingSystem = config.getOperatingSystem(); this.osVersion = config.getOsVersion(); this.categories = new ArrayList<String>(config.getCategories()); try {//w ww . j ava 2 s. co m this.deviceRegistryURL = UrlUtils.appendToBaseURL(config.getPushServerURI().toURL(), registryDeviceEndpoint); } catch (MalformedURLException ex) { Log.e(TAG, ex.getMessage()); throw new IllegalStateException("pushserverUrl was not a valid URL"); } }
From source file:es.tekniker.framework.ktek.questionnaire.mng.server.OrionContextBrokerClient.java
public boolean subscribeContext(String codUser, String nameContext) { HttpURLConnection conn = null; StringBuffer strBOutput = new StringBuffer(); boolean boolOK = true; String input = null;/* ww w . j a v a 2s .com*/ StringBuffer stbInput = new StringBuffer(); try { log.debug("subscribeContext Start "); conn = getOrionContextBrokerGEConnection(this.methodSubscribeContext, this.endpointOrionContextBroker, this.headerContentTypeJSON); stbInput.append("{\"entities\": [{\"type\": \"" + this.typeContextValue + "\",\"isPattern\": \"false\",\"id\": \"" + codUser + "\" } ],"); stbInput.append("\"attributes\": [\"" + nameContext + "\"] ,"); stbInput.append("\"reference\": \"" + this.notificationEndpoint + "\","); stbInput.append("\"duration\": \"P1M\","); stbInput.append("\"notifyConditions\": [ {\"type\": \"ONCHANGE\",\"condValues\": [\"" + nameContext + "\"]}],\"throttling\": \"PT5S\"}"); input = stbInput.toString(); log.debug(input); OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); if (conn.getResponseCode() == 200) { log.debug("subscribeContext Response code " + conn.getResponseCode()); } else if (conn.getResponseCode() != 201) { throw new RuntimeException("subscribeContext Failed : HTTP error code : " + conn.getResponseCode()); } log.debug("subscribeContext OutputStream wrote"); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); log.debug("subscribeContext Waiting server response "); log.debug("subscribeContext Output from Server .... \n"); String output; while ((output = br.readLine()) != null) { strBOutput.append(output); log.debug(output); } conn.disconnect(); boolOK = true; } catch (MalformedURLException e) { log.error("subscribeContext MalformedURLException " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { log.error("subscribeContext IOException " + e.getMessage()); e.printStackTrace(); } return boolOK; }
From source file:com.finlay.geomonsters.MainActivity.java
public void connectSocket() { // Connect to the socket if (!socket.isConnected()) { try {// w ww .ja va 2 s .c om socket.connect(URL, new MyIOCallback(this)); } catch (MalformedURLException e) { Log.e(TAG, e.getMessage()); } } }
From source file:es.tekniker.framework.ktek.questionnaire.mng.server.OrionContextBrokerClient.java
public boolean updateContext(String codUser, String nameContext, String typeContext, String valueContext, boolean valueIsjson) { HttpURLConnection conn = null; StringBuffer strBOutput = new StringBuffer(); boolean boolOK = true; String input = null;/*from w w w . j a v a 2 s.co m*/ StringBuffer stbInput = new StringBuffer(); try { log.debug("updateContext Start "); conn = getOrionContextBrokerGEConnection(this.methodUpdateContext, this.endpointOrionContextBroker, this.headerContentTypeJSON); stbInput.append("{\"contextElements\": [{\"type\": \"" + this.typeContextValue + "\",\"isPattern\": \"false\",\"id\": \"" + codUser + "\",\"attributes\":"); if (valueIsjson) { stbInput.append(" [{\"name\": \"" + nameContext + "\",\"type\": \"" + typeContext + "\",\"value\": " + valueContext + "}]}]"); } else { stbInput.append(" [{\"name\": \"" + nameContext + "\",\"type\": \"" + typeContext + "\",\"value\": \"" + valueContext + "\"}]}]"); } stbInput.append(",\"updateAction\": \"APPEND\"}"); input = stbInput.toString(); log.debug(input); OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); if (conn.getResponseCode() == 200) { log.debug("updateContext Response code " + conn.getResponseCode()); } else if (conn.getResponseCode() != 201) { throw new RuntimeException("updateContext Failed : HTTP error code : " + conn.getResponseCode()); } log.debug("updateContext OutputStream wrote"); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); log.debug("updateContext Waiting server response "); log.debug("updateContext Output from Server .... \n"); String output; while ((output = br.readLine()) != null) { strBOutput.append(output); log.debug(output); } conn.disconnect(); boolOK = true; } catch (MalformedURLException e) { log.error("updateContext MalformedURLException " + e.getMessage()); e.printStackTrace(); boolOK = false; } catch (IOException e) { log.error("updateContext IOException " + e.getMessage()); e.printStackTrace(); boolOK = false; } return boolOK; }
From source file:net.bunselmeyer.mongo.maven.plugin.MigrateMojo.java
private URLClassLoader buildProjectClassLoader() throws MojoExecutionException { getLog().debug("adding all artifacts to classLoader"); List<URL> urls = new ArrayList<URL>(); for (Object artifact : getProject().getArtifacts()) { try {/* ww w.ja va 2 s.c om*/ urls.add(((Artifact) artifact).getFile().toURI().toURL()); } catch (MalformedURLException e) { throw new MojoExecutionException(e.getMessage(), e); } } urls.add(buildOutputDirectoryUrl()); getLog().debug("urls = \n" + urls.toString().replace(",", "\n")); return new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); }