Java Code Examples for java.net.URISyntaxException#printStackTrace()

The following examples show how to use java.net.URISyntaxException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FetchDocListTask.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override protected String call() throws Exception {
    System.out.println("---- FetchDocListTask  docsUrl = "+docsDirUrl);
    StringBuilder builder = new StringBuilder();
    try {
        URI uri = new URI(docsDirUrl + "allclasses-frame.html");
        URL url = uri.toURL();
        URLConnection urlConnection = url.openConnection();
        urlConnection.setConnectTimeout(5000); //set timeout to 5 secs
        InputStream in = urlConnection.getInputStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line);
            builder.append('\n');
        }
        reader.close();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return builder.toString();
}
 
Example 2
Source File: UpdateController.java    From standalone-app with Apache License 2.0 6 votes vote down vote up
public File getHeliosLocation() {
    ProtectionDomain pd = getClass().getProtectionDomain();
    if (pd != null) {
        CodeSource cs = pd.getCodeSource();
        if (cs != null) {
            URL location = cs.getLocation();
            if (location != null) {
                try {
                    File file = new File(location.toURI().getPath());
                    if (file.isFile()) {
                        return file;
                    }
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                    return null;
                }
            }
        }
    }
    return null;
}
 
Example 3
Source File: SpeechToText.java    From speech-android-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Start recording audio
 */
public void recognize() {
    Log.d(TAG, "recognize");
    try {
        HashMap<String, String> header = new HashMap<String, String>();
        header.put("Content-Type", sConfig.audioFormat);

        if(sConfig.isAuthNeeded) {
            if (this.tokenProvider != null) {
                header.put("X-Watson-Authorization-Token", this.tokenProvider.getToken());
                Log.d(TAG, "ws connecting with token based authentication");
            } else {
                String auth = "Basic " + Base64.encodeBytes((this.username + ":" + this.password).getBytes(Charset.forName("UTF-8")));
                header.put("Authorization", auth);
                Log.d(TAG, "ws connecting with Basic Authentication");
            }
        }

        if (sConfig.learningOptOut) {
            header.put("X-Watson-Learning-OptOut", "true");
            Log.d(TAG, "ws setting X-Watson-Learning-OptOut");
        }

        String wsURL = getHostURL().toString() + "/v1/recognize" + (this.model != null ? ("?model=" + this.model) : "");

        uploader = new WebSocketUploader(wsURL, header, sConfig);
        uploader.setDelegate(this.delegate);
        this.startRecording();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: XDMUtils.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
public static File getJarFile() {
	try {
		return new File(Main.class.getProtectionDomain().getCodeSource()
				.getLocation().toURI().getPath());
	} catch (URISyntaxException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
Example 5
Source File: UtilityTest.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
private static Scenario loadScenarioFromResources(String fileScenario, String suffix, boolean recreateDB, String chaseMode) {
    try {
        fileScenario = RESOURCES_FOLDER + fileScenario;
        URL scenarioURL = UtilityTest.class.getResource(fileScenario);
        Assert.assertNotNull("Load scenario " + fileScenario, scenarioURL);
        fileScenario = new File(scenarioURL.toURI()).getAbsolutePath();
        return loadScenario(fileScenario, suffix, recreateDB, chaseMode);
    } catch (URISyntaxException ex) {
        ex.printStackTrace();
        Assert.fail(ex.getLocalizedMessage());
        return null;
    }
}
 
Example 6
Source File: LocalOperationHandler.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<SingleCloverURI> resolve(SingleCloverURI wildcards, ResolveParameters params) {
	String uriString = wildcards.toString();
	if (!hasWildcards(uriString)) {
		return Arrays.asList(wildcards);
	}
	
	List<String> parts = getParts(uriString);
	try {
		File base = new File(new URI(parts.get(0)));
		if (!base.exists()) {
			return new ArrayList<SingleCloverURI>(0);
		}
		List<File> bases = Arrays.asList(base);
		for (Iterator<String> it = parts.listIterator(1); it.hasNext(); ) {
			String part = it.next();
			boolean hasPathSeparator = part.endsWith(URIUtils.PATH_SEPARATOR);
			if (hasPathSeparator) {
				part = part.substring(0, part.length()-1);
			}
			List<File> nextBases = new ArrayList<File>(bases.size());
			for (File f: bases) {
				nextBases.addAll(expand(f, part, it.hasNext() || hasPathSeparator));
			}
			bases = nextBases;
		}
		
		List<SingleCloverURI> result = new ArrayList<SingleCloverURI>(bases.size());
		for (File file: bases) {
			result.add(new SingleCloverURI(file.toURI()));
		}
		return result;
	} catch (URISyntaxException ex) {
		ex.printStackTrace(); // FIXME
	}
	
	return null;
}
 
Example 7
Source File: ChipsterGBrowserVisualisation.java    From chipster with MIT License 5 votes vote down vote up
protected void initialiseUserData(DataUrl data) throws IOException {
	if (data != null) {				
		try {
			data.getLocalFile();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
	}
}
 
Example 8
Source File: CarbonPolicyFinder.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void orderPolicyCache() {
    LinkedHashMap<URI, AbstractPolicy> policyMap = policyCollection.getPolicyMap();
    Collections.sort(policyCollectionOrder, new PolicyOrderComparator());
    LinkedHashMap<URI, AbstractPolicy> newPolicyMap = new LinkedHashMap<URI, AbstractPolicy>();
    Iterator<PolicyDTO> policyDTOIterator = policyCollectionOrder.iterator();
    while (policyDTOIterator.hasNext()) {
        try {
            URI policyURI = new URI(policyDTOIterator.next().getPolicyId());
            newPolicyMap.put(policyURI, policyMap.get(policyURI));

        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
}
 
Example 9
Source File: OpenURICommand.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link OpenURICommand}.
 *
 * @param title The title to use.
 * @param uri   The URI to open.
 */
public OpenURICommand(String title, String uri) {
    super(title, "OpenURL[" + uri + "]");
    try {
        mURI = new URI(uri);
    } catch (URISyntaxException exception) {
        exception.printStackTrace();
    }
}
 
Example 10
Source File: Inspect.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private File getInspectFile(){
    Path workingDirectory = null;
    try {
        workingDirectory= Paths.get(
                BeakerxWidget.class.getProtectionDomain().getCodeSource().getLocation().toURI()
        ).getParent().getParent();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return new File(workingDirectory.toFile(), inspectDataPath);
}
 
Example 11
Source File: RegionOperations.java    From chipster with MIT License 5 votes vote down vote up
public static void main(String[] args) throws FileNotFoundException, IOException, GBrowserException {
	RegionOperations tool = new RegionOperations();
	List<Feature> file1 = null;
	List<Feature> file2 = null;
	try {
		file1 = tool.loadFile(new File("test1.bed"));
		file2 = tool.loadFile(new File("test2.bed"));
	} catch (URISyntaxException e) {
		e.printStackTrace();
	}

	tool.print(tool.intersect(file1, file2, 1L, RegionOperations.LEFT_PAIR_POLICY_WITH_AUGMENTATION, false), System.out);
}
 
Example 12
Source File: MainActivity.java    From speech-android-sdk with Apache License 2.0 5 votes vote down vote up
public URI getHost(String url){
    try {
        return new URI(url);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 13
Source File: ServletUtil.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * The request base as a URI
 *
 * @param req the HttpServletRequest
 * @return parsed request as a URI
 */
public static URI getRequestURI(HttpServletRequest req) {
  try {
    return new URI(getRequestBase(req));
  } catch (URISyntaxException e) {
    e.printStackTrace();
    return null;
  }
}
 
Example 14
Source File: MedicinesLocalDataSource.java    From Medicine-Time- with Apache License 2.0 5 votes vote down vote up
@Override
public List<MedicineAlarm> getMedicineByPillName(String pillName) {
    try {
        return getMedicineByPill(pillName);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 15
Source File: WsURLConnectionImpl.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
public WsURLConnectionImpl(URL                                       location, 
                           Map<String, WebSocketExtensionFactorySpi> extensionFactories) {
    super(location);
    
    try {
        _webSocket = new WebSocketImpl(location.toURI(), extensionFactories);
    } 
    catch (URISyntaxException e) {
        e.printStackTrace();
    }
}
 
Example 16
Source File: KieService.java    From Liudao with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 规则集上线
 *
 * @param packageName
 */
public void addPackage(String packageName) {
    try {
        File path = new File(this.getClass().getClassLoader().getResource(packageName).toURI().getPath());
        if (path.isDirectory()) {
            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
            File[] files = path.listFiles();
            for (File file : files) {
                if (file.getName().endsWith(".drl")) {
                    kbuilder.add(ResourceFactory.newClassPathResource(packageName + "/" + file.getName()), ResourceType.DRL);
                    if (kbuilder.hasErrors()) {
                        logger.error("Unable to compile drl. " + packageName + file.getName());
                        return;
                    } else {
                        String ruleName = file.getName().replace(".drl", "");
                        if (kbase.getRule(packageName, ruleName) != null) {
                            logger.info("update rule: " + packageName + "." + ruleName);
                        } else {
                            logger.info("add rule: " + packageName + "." + ruleName);
                        }
                    }
                }
            }

            kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
            kieSession = kbase.newStatelessKieSession();
            setGlobal();
            printRules();
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}
 
Example 17
Source File: GamlModelBuilder.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public void loadURLs(final List<URL> URLs) {
	for (final URL url : URLs) {
		java.net.URI uri;
		try {
			uri = new java.net.URI(url.getProtocol(), url.getPath(), null).normalize();
			final URI resolvedURI = URI.createURI(uri.toString());
			buildResourceSet.getResource(resolvedURI, true);
		} catch (final URISyntaxException e) {
			e.printStackTrace();
		}
	}
}
 
Example 18
Source File: NvmfStorageEndpoint.java    From crail with Apache License 2.0 5 votes vote down vote up
public NvmfStorageEndpoint(NvmeEndpointGroup group, InetSocketAddress inetSocketAddress) throws IOException {
	this.inetSocketAddress = inetSocketAddress;
	endpoint = group.createEndpoint();
	try {
		URI url = new URI("nvmef://" + inetSocketAddress.getHostString() + ":" + inetSocketAddress.getPort() +
				"/0/" + NvmfStorageConstants.NAMESPACE + "?subsystem=nqn.2016-06.io.spdk:cnode1");
		LOG.info("Connecting to " + url.toString());
		endpoint.connect(url);
	} catch (URISyntaxException e) {
		//FIXME
		e.printStackTrace();
	}
	sectorSize = endpoint.getSectorSize();
	cache = new NvmfBufferCache();
	ioQeueueSize = endpoint.getIOQueueSize();
	freeCommands = new ArrayBlockingQueue<NvmeCommand>(ioQeueueSize);
	commands = new NvmeCommand[ioQeueueSize];
	for (int i = 0; i < ioQeueueSize; i++) {
		NvmeCommand command = endpoint.newCommand();
		command.setId(i);
		commands[i] = command;
		freeCommands.add(command);
	}
	futures = new NvmfStorageFuture[ioQeueueSize];
	completed = new ThreadLocal<long[]>() {
		public long[] initialValue() {
			return new long[ioQeueueSize];
		}
	};
}
 
Example 19
Source File: AuthorizeRestWebServiceEmbeddedTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Parameters({"authorizePath", "userId", "userSecret", "redirectUri"})
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationTokenCode(final String authorizePath, final String userId, final String userSecret,
                                          final String redirectUri) throws Exception {
    final String state = UUID.randomUUID().toString();

    List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.CODE);
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    String nonce = UUID.randomUUID().toString();

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId1, scopes,
            redirectUri, nonce);
    authorizationRequest.setState(state);
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);

    Builder request = ResteasyClientBuilder.newClient()
            .target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);

    Response response = request.get();
    String entity = response.readEntity(String.class);

    showResponse("requestAuthorizationTokenCode", response, entity);

    assertEquals(response.getStatus(), 302, "Unexpected response code.");
    assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

    if (response.getLocation() != null) {
        try {
            URI uri = new URI(response.getLocation().toString());
            assertNotNull(uri.getFragment(), "Fragment is null");

            Map<String, String> params = QueryStringDecoder.decode(uri.getFragment());

            assertNotNull(params.get(AuthorizeResponseParam.CODE), "The code is null");
            assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The access token is null");
            assertNotNull(params.get(AuthorizeResponseParam.TOKEN_TYPE), "The token type is null");
            assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
            assertEquals(params.get(AuthorizeResponseParam.STATE), state);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            fail("Response URI is not well formed");
        }
    }
}
 
Example 20
Source File: AuthorizeWithResponseModeEmbeddedTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationCodeWithResponseModeQuery(final String authorizePath, final String userId,
		final String userSecret, final String redirectUri) throws Exception {
	final String state = UUID.randomUUID().toString();

	List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
	List<String> scopes = Arrays.asList("openid", "profile", "address", "email");

	AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes,
			redirectUri, null);
	authorizationRequest.setState(state);
	authorizationRequest.getPrompts().add(Prompt.NONE);
	authorizationRequest.setAuthUsername(userId);
	authorizationRequest.setAuthPassword(userSecret);
	authorizationRequest.setResponseMode(ResponseMode.QUERY);

	Builder request = ResteasyClientBuilder.newClient()
			.target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
	request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
	request.header("Accept", MediaType.TEXT_PLAIN);

	Response response = request.get();
	String entity = response.readEntity(String.class);

	showResponse("requestAuthorizationCodeWithResponseModeQuery", response, entity);

	assertEquals(response.getStatus(), 302, "Unexpected response code.");
	assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

	try {
		URI uri = new URI(response.getLocation().toString());
		assertNotNull(uri.getQuery(), "Query string is null");

		Map<String, String> params = QueryStringDecoder.decode(uri.getQuery());

		assertNotNull(params.get(AuthorizeResponseParam.CODE), "The code is null");
		assertNotNull(params.get(AuthorizeResponseParam.SCOPE), "The scope is null");
		assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
		assertEquals(params.get(AuthorizeResponseParam.STATE), state);
	} catch (URISyntaxException e) {
		e.printStackTrace();
		fail("Response URI is not well formed");
	}
}