List of usage examples for java.net URI toURL
public URL toURL() throws MalformedURLException
From source file:org.wso2.carbon.bpel.core.ode.integration.utils.AxisServiceUtils.java
private static WSDL11ToAxisServiceBuilder createAxisServiceBuilder(BPELProcessProxy processProxy) throws AxisFault { Definition wsdlDef = processProxy.getWsdlDefinition(); QName serviceName = processProxy.getServiceName(); String portName = processProxy.getPort(); ProcessConf pConf = processProxy.getProcessConfiguration(); QName pid = pConf.getProcessId(); InputStream wsdlInStream = null; URI wsdlBaseURI = pConf.getBaseURI().resolve(wsdlDef.getDocumentBaseURI()); try {//from w w w .j a va 2 s .c o m wsdlInStream = wsdlBaseURI.toURL().openStream(); } catch (MalformedURLException e) { String errMsg = "Malformed WSDL base URI."; handleException(pid, errMsg, e); } catch (IOException e) { String errMsg = "Error opening stream."; handleException(pid, errMsg, e); } WSDL11ToAxisServiceBuilder serviceBuilder = new WSDL11ToAxisPatchedBuilder(wsdlInStream, serviceName, portName); serviceBuilder.setBaseUri(wsdlBaseURI.toString()); serviceBuilder.setCustomResolver(new Axis2UriResolver()); try { serviceBuilder.setCustomWSDLResolver(new Axis2WSDLLocator(wsdlBaseURI)); } catch (URISyntaxException e) { String errorMessage = "URI syntax invalid."; handleException(pid, errorMessage, e); } serviceBuilder.setServerSide(true); return serviceBuilder; }
From source file:eu.trentorise.smartcampus.network.RemoteConnector.java
private static String normalizeURL(String uriString) throws RemoteException { try {//from w w w. ja va2s .c o m URL url = new URL(uriString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); uriString = uri.toURL().toString(); } catch (Exception e) { throw new RemoteException(e.getMessage()); } return uriString; }
From source file:org.loklak.api.search.GithubProfileScraper.java
public static SusiThought scrapeGithub(String profile) { Document html = null;// ww w . j a va 2 s. c o m JSONObject githubProfile = new JSONObject(); try { html = Jsoup.connect("https://github.com/" + profile).get(); } catch (IOException e) { URI uri = null; try { uri = new URI("https://api.github.com/search/users?q=" + profile); } catch (URISyntaxException e1) { e1.printStackTrace(); } JSONTokener tokener = null; try { tokener = new JSONTokener(uri.toURL().openStream()); } catch (Exception e1) { e1.printStackTrace(); } JSONObject obj = new JSONObject(tokener); JSONArray arr = new JSONArray(); arr.put(obj); SusiThought json = new SusiThought(); json.setData(arr); return json; } String avatarUrl = html.getElementsByAttributeValue("class", "avatar rounded-2").attr("src"); githubProfile.put("avatar_url", avatarUrl); String fullName = html.getElementsByAttributeValue("class", "vcard-fullname").text(); githubProfile.put("full_name", fullName); String userName = html.getElementsByAttributeValue("class", "vcard-username").text(); githubProfile.put("user_name", userName); String bio = html.getElementsByAttributeValue("class", "user-profile-bio").text(); githubProfile.put("bio", bio); String atomFeedLink = html.getElementsByAttributeValue("type", "application/atom+xml").attr("href"); githubProfile.put("atom_feed_link", "https://github.com" + atomFeedLink); String worksFor = html.getElementsByAttributeValue("itemprop", "worksFor").text(); githubProfile.put("works_for", worksFor); String homeLocation = html.getElementsByAttributeValue("itemprop", "homeLocation").attr("title"); githubProfile.put("home_location", homeLocation); String email = html.getElementsByAttributeValue("itemprop", "email").text(); githubProfile.put("email", email); String specialLink = html.getElementsByAttributeValue("itemprop", "url").text(); githubProfile.put("special_link", specialLink); String joiningDate = html.getElementsByAttributeValue("class", "join-date").attr("datetime"); githubProfile.put("joining_date", joiningDate); /* If Individual User */ if (html.getElementsByAttributeValue("class", "vcard-stat").size() != 0) { String followersUrl = html.getElementsByAttributeValue("class", "vcard-stat").get(0).attr("href"); githubProfile.put("followers_url", "https://github.com" + followersUrl); String followers = html.getElementsByAttributeValue("class", "vcard-stat").get(0).tagName("strong") .text(); githubProfile.put("followers", followers); String starredUrl = html.getElementsByAttributeValue("class", "vcard-stat").get(1).attr("href"); githubProfile.put("starred_url", "https://github.com" + starredUrl); String starred = html.getElementsByAttributeValue("class", "vcard-stat").get(1).tagName("strong") .text(); githubProfile.put("starred", starred); String followingUrl = html.getElementsByAttributeValue("class", "vcard-stat").get(2).attr("href"); githubProfile.put("following_url", "https://github.com" + followingUrl); String following = html.getElementsByAttributeValue("class", "vcard-stat").get(2).tagName("strong") .text(); githubProfile.put("following", following); } String gistsUrl = "https://api.github.com/users/" + profile + "/gists"; githubProfile.put("gists_url", gistsUrl); String subscriptionsUrl = "https://api.github.com/users/" + profile + "/subscriptions"; githubProfile.put("subscriptions_url", subscriptionsUrl); String reposUrl = "https://api.github.com/users/" + profile + "/repos"; githubProfile.put("repos_url", reposUrl); String eventsUrl = "https://api.github.com/users/" + profile + "/events"; githubProfile.put("events_url", eventsUrl); String receivedEventsUrl = "https://api.github.com/users/" + profile + "/received_events"; githubProfile.put("received_events_url", receivedEventsUrl); JSONArray organizations = new JSONArray(); Elements orgs = html.getElementsByAttributeValue("itemprop", "follows"); for (Element e : orgs) { JSONObject obj = new JSONObject(); String label = e.attr("aria-label"); obj.put("label", label); String link = e.attr("href"); obj.put("link", "https://github.com" + link); String imgLink = e.children().attr("src"); obj.put("img_link", imgLink); String imgAlt = e.children().attr("alt"); obj.put("img_Alt", imgAlt); organizations.put(obj); } githubProfile.put("organizations", organizations); /* If Organization */ Elements navigation = html.getElementsByAttributeValue("class", "orgnav"); for (Element e : navigation) { String orgRepositoriesLink = e.child(0).tagName("a").attr("href"); githubProfile.put("organization_respositories_link", "https://github.com" + orgRepositoriesLink); String orgPeopleLink = e.child(1).tagName("a").attr("href"); githubProfile.put("organization_people_link", "https://github.com" + orgPeopleLink); String orgPeopleNumber = e.child(1).tagName("a").child(1).text(); githubProfile.put("organization_people_number", orgPeopleNumber); } JSONArray jsonArray = new JSONArray(); jsonArray.put(githubProfile); SusiThought json = new SusiThought(); json.setData(jsonArray); return json; }
From source file:org.jactr.eclipse.runtime.launching.ACTRLaunchConfigurationUtils.java
/** * set up the attributes that we just apply after Apply is clicked in the * config dialog/*from w w w. j a v a2 s . co m*/ * * @param workingCopy */ static public void setupPersistentAttributes(ILaunchConfigurationWorkingCopy workingCopy) throws CoreException { /* * we will use the default configuration location, which should be the * current environment's.. the name is RUNTYPE:runName.. */ IProject project = getProject(workingCopy); String configName = workingCopy.getName(); workingCopy.setAttribute(org.eclipse.pde.launching.IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA, false); workingCopy.setAttribute(org.eclipse.pde.launching.IPDELauncherConstants.CONFIG_LOCATION, ACTRLaunchConstants.NORMAL_CONFIGURATION_LOCATION + project.getName() + "/" + configName); /* * what about core logging? that needs to be set up by the tab but for now.. */ boolean logging = workingCopy.getAttribute(ACTRLaunchConstants.ATTR_DEBUG_CORE_ENABLED, false); if (logging) { IResource logFile = project.findMember(workingCopy.getAttribute( ACTRLaunchConstants.ATTR_DEBUG_CORE_LOG_CONF, ACTRLaunchConstants.DEFAULT_CORE_LOG_CONF)); if (logFile != null && logFile.exists()) { StringBuilder vmArg = new StringBuilder(" -Dorg.apache.commons.logging.log="); vmArg.append(workingCopy.getAttribute(ACTRLaunchConstants.ATTR_DEBUG_CORE_LOGGER, ACTRLaunchConstants.DEFAULT_CORE_LOGGER)); vmArg.append(" -Dlog4j.configuration="); try { URI uri = logFile.getRawLocationURI(); vmArg.append(uri.toURL()).append(" ").append( workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "")); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArg.toString()); } catch (Exception e) { CorePlugin.debug("failed to transform url " + logFile, e); logging = false; } } else logging = false; } if (!logging) workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "-Dorg.apache.commons.logging.log=org.apache.commons.logging.impl.SimpleLog " + workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "")); if (LOGGER.isDebugEnabled()) LOGGER.debug("Applied persistent attributes " + workingCopy); }
From source file:io.github.swagger2markup.Swagger2MarkupConverter.java
/** * Creates a Swagger2MarkupConverter.Builder from a URI. * * @param swaggerUri the URI// w w w . j a v a 2 s. co m * @return a Swagger2MarkupConverter */ public static Builder from(URI swaggerUri) { Validate.notNull(swaggerUri, "swaggerUri must not be null"); String scheme = swaggerUri.getScheme(); if (scheme != null && swaggerUri.getScheme().startsWith("http")) { try { return from(swaggerUri.toURL()); } catch (MalformedURLException e) { throw new RuntimeException("Failed to convert URI to URL", e); } } else if (scheme != null && swaggerUri.getScheme().startsWith("file")) { return from(Paths.get(swaggerUri)); } else { return from(URIUtils.convertUriWithoutSchemeToFileScheme(swaggerUri)); } }
From source file:com.skcraft.launcher.util.HttpRequest.java
/** * URL may contain spaces and other nasties that will cause a failure. * * @param existing the existing URL to transform * @return the new URL, or old one if there was a failure *//*from w ww . j a v a 2 s. co m*/ private static URL reformat(URL existing) { try { URL url = new URL(existing.toString()); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); url = uri.toURL(); return url; } catch (MalformedURLException e) { return existing; } catch (URISyntaxException e) { return existing; } }
From source file:ninja.standalone.StandaloneHelper.java
static public InputStream openKeyStoreInput(URI uri) throws IOException { if (uri.getScheme().equals(URI_SCHEME_CLASSPATH)) { String resourceName = uri.getPath(); log.debug("Opening keystore on classpath with resource {}", resourceName); InputStream stream = StandaloneHelper.class.getResourceAsStream(resourceName); if (stream == null) { throw new IOException("Resource '" + resourceName + "' not found on classpath"); }/*from w w w . j a va 2s .c o m*/ return stream; } else { URL url = uri.toURL(); log.debug("Opening keystore with url {}", url); return url.openStream(); } }
From source file:com.evilisn.DAO.CertMapper.java
public static byte[] httpGetBin(URI uri, boolean bActiveCheckUnknownHost) throws Exception { InputStream is = null;/*from w ww. java 2s. c o m*/ InputStream is_temp = null; try { if (uri == null) return null; URL url = uri.toURL(); if (bActiveCheckUnknownHost) { url.getProtocol(); String host = url.getHost(); int port = url.getPort(); if (port == -1) port = url.getDefaultPort(); InetSocketAddress isa = new InetSocketAddress(host, port); if (isa.isUnresolved()) { //fix JNLP popup error issue throw new UnknownHostException("Host Unknown:" + isa.toString()); } } HttpURLConnection uc = (HttpURLConnection) url.openConnection(); uc.setDoInput(true); uc.setAllowUserInteraction(false); uc.setInstanceFollowRedirects(true); setTimeout(uc); String contentEncoding = uc.getContentEncoding(); int len = uc.getContentLength(); // is = uc.getInputStream(); if (contentEncoding != null && contentEncoding.toLowerCase().indexOf("gzip") != -1) { is_temp = uc.getInputStream(); is = new GZIPInputStream(is_temp); } else if (contentEncoding != null && contentEncoding.toLowerCase().indexOf("deflate") != -1) { is_temp = uc.getInputStream(); is = new InflaterInputStream(is_temp); } else { is = uc.getInputStream(); } if (len != -1) { int ch = 0, i = 0; byte[] res = new byte[len]; while ((ch = is.read()) != -1) { res[i++] = (byte) (ch & 0xff); } return res; } else { ArrayList<byte[]> buffer = new ArrayList<byte[]>(); int buf_len = 1024; byte[] res = new byte[buf_len]; int ch = 0, i = 0; while ((ch = is.read()) != -1) { res[i++] = (byte) (ch & 0xff); if (i == buf_len) { //rotate buffer.add(res); i = 0; res = new byte[buf_len]; } } int total_len = buffer.size() * buf_len + i; byte[] buf = new byte[total_len]; for (int j = 0; j < buffer.size(); j++) { System.arraycopy(buffer.get(j), 0, buf, j * buf_len, buf_len); } if (i > 0) { System.arraycopy(res, 0, buf, buffer.size() * buf_len, i); } return buf; } } catch (Exception e) { e.printStackTrace(); return null; } finally { closeInputStream(is_temp); closeInputStream(is); } }
From source file:org.jactr.eclipse.runtime.launching.ACTRLaunchConfigurationUtils.java
/** * set up the information that is set strictly for the immediate launch. this * includes the working directory, environment file, program args * /*www. j ava2 s . c om*/ * @param workingCopy * @param mode * @param environmentFile */ static public void setupTemporaryAttributes(ILaunchConfigurationWorkingCopy workingCopy, String mode, IResource environmentFile) throws CoreException { StringBuilder arguments = new StringBuilder(); /* * make sure no splash screen is shown */ arguments.append("-name jACTR -nosplash "); /** * here's a mac specific bit of code * https://bugs.eclipse.org/bugs/show_bug.cgi?id=133072. The deal is that * eclipse (SWT) needs -ws carbon to run correctly. However if this is * provided, Swing/AWT calls will result in deadlock. The PDE tools * automatically add the -ws option, unless * IPDEUIConstants.APPEND_ARGS_EXPLICITLY is true (i.e. the program added it * already). So, if this is the mac, we explicitly add the program args, * excluding -ws. <br> * <br> * This works fine since we are launching within eclipse. If we were to * build a standalone app, on the mac, we'd need to add * --launcher.secondThread to the command line so to achieve a similar * effect. */ if (TargetPlatform.getWS().equals("carbon") || TargetPlatform.getWS().equals("cocoa")) { workingCopy.setAttribute(IPDEConstants.APPEND_ARGS_EXPLICITLY, true); // arguments.append("--launcher.secondThread "); arguments.append("-os ").append(TargetPlatform.getOS()).append(" "); arguments.append("-arch ").append(TargetPlatform.getOSArch()).append(" "); } if (workingCopy.getType().getIdentifier().equals("org.jactr.eclipse.runtime.launching.cr")) arguments.append(ACTRLaunchConstants.DEFAULT_CR_RUN_ARG); else if (workingCopy.getAttribute(ACTRLaunchConstants.ATTR_ITERATIONS, 0) != 0) arguments.append(ACTRLaunchConstants.ITERATIVE_APPLICATION_ARG); else if (ILaunchManager.DEBUG_MODE.equals(mode)) arguments.append(ACTRLaunchConstants.DEFAULT_APPLICATION_DEBUG_ARG); else arguments.append(ACTRLaunchConstants.DEFAULT_APPLICATION_RUN_ARG); arguments.append(" "); try { URI uri = environmentFile.getRawLocationURI(); arguments.append(uri.toURL()).append(" ") .append(workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "")); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, arguments.toString()); } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, RuntimePlugin.PLUGIN_ID, "Could not get a valid url from " + environmentFile, e)); } /* * working directory - where the JVM is run from */ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, environmentFile.getParent().getLocation().toOSString()); /* * now for the fun.. we need to get the plugin dependencies. first we get * the dependencies for the application.. we do this temporarily because.. * well, things change. */ Set<String> workspace = new TreeSet<String>(); Set<String> target = new TreeSet<String>(); computeBundleDependencies(workingCopy, workspace, target); StringBuilder workspaceBundles = new StringBuilder(); StringBuilder targetBundles = new StringBuilder(); for (String bundle : workspace) workspaceBundles.append(bundle).append(","); for (String bundle : target) targetBundles.append(bundle).append(","); if (workspaceBundles.length() > 0) workspaceBundles.delete(workspaceBundles.length() - 1, workspaceBundles.length()); if (targetBundles.length() > 0) targetBundles.delete(targetBundles.length() - 1, targetBundles.length()); workingCopy.setAttribute(org.eclipse.pde.launching.IPDELauncherConstants.SELECTED_WORKSPACE_PLUGINS, workspaceBundles.toString()); workingCopy.setAttribute(org.eclipse.pde.launching.IPDELauncherConstants.SELECTED_TARGET_PLUGINS, targetBundles.toString()); if (LOGGER.isDebugEnabled()) LOGGER.debug("Applied temporary attributes " + workingCopy); }
From source file:org.moe.cli.utils.GrabUtils.java
/** * The method downloads file from given URI. * URI can be a path to local file/directory, remote archive or a file in remote .git repository. Output file should have same format to the input. * <br>Path to the file in remote .git repository should be in the format: <path to repo>.git#<tag/commit>:<path to file from repo's root> * <br>Example: https://github.com/NatJPods/Bindings.git#Example:Bindings/Google/1.3.2 * /*from ww w . jav a 2 s . c o m*/ * @param link file to download * @param dest destination * @throws FileAlreadyExistsException if file has already exists * @throws FileNotFoundException if source doesn't exist * @throws UnsupportedTypeException if URI links to file with unsupported type * @throws URISyntaxException if URI have unsupported or wrong format * @throws IOException if operation couldn't be successfully completed because of other reasons */ public static void download(@NonNull URI link, @NonNull File dest) throws FileAlreadyExistsException, FileNotFoundException, UnsupportedTypeException, URISyntaxException, IOException { if (dest.exists()) { throw new FileAlreadyExistsException(dest.toString() + " has already exists"); } String scheme = link.getScheme(); if (scheme == null) { //assume that FileUtils can handle it URL url = link.toURL(); FileUtils.copyURLToFile(url, dest); } else { String[] gitRepo = parseGitURI(link); if (gitRepo != null) { //try to parse it like a git repo URI git = new URI(gitRepo[0]); String tag = gitRepo[1]; Path file = Paths.get(gitRepo[2]); downloadFileFromGit(git, tag, file, dest); } else if (scheme.equals("file")) { File local = new File(link); if (local.exists()) { if (local.isDirectory()) { FileUtils.copyDirectory(local, dest); } else { FileUtils.copyFile(local, dest); } } else { throw new FileNotFoundException(local.toString() + " doesn't exists"); } } else {//this isn't a local or git repository downloadFileFromRemote(link, dest); } } }