List of usage examples for java.net URI create
public static URI create(String str)
From source file:de.blizzy.documentr.system.Downloader.java
String getTextFromUrl(String url, Charset encoding) throws IOException { ClientHttpResponse response = null;//from w w w. ja va2s .c om try { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout((int) TIMEOUT); requestFactory.setReadTimeout((int) TIMEOUT); ClientHttpRequest request = requestFactory.createRequest(URI.create(url), HttpMethod.GET); response = request.execute(); HttpStatus status = response.getStatusCode(); if (status.series() == Series.SUCCESSFUL) { return IOUtils.toString(response.getBody(), encoding); } } finally { if (response != null) { response.close(); } } return null; }
From source file:org.piraso.client.net.HttpBasicAuthenticationTest.java
@Test public void testAuthenticate() throws Exception { AbstractHttpClient client = mock(AbstractHttpClient.class); HttpContext context = mock(HttpContext.class); CredentialsProvider credentials = mock(CredentialsProvider.class); doReturn(credentials).when(client).getCredentialsProvider(); HttpBasicAuthentication auth = new HttpBasicAuthentication(client, context); auth.setUserName("username"); auth.setPassword("password"); URI uri = URI.create("http://localhost:8080/test"); auth.setTargetHost(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme())); auth.execute();//from www .j a va 2 s . c om verify(credentials).setCredentials(Matchers.<AuthScope>any(), Matchers.<Credentials>any()); verify(context).setAttribute(Matchers.<String>any(), any()); }
From source file:com.streamsets.pipeline.stage.processor.kv.redis.RedisStore.java
public RedisStore(RedisLookupConfig conf) { this.conf = conf; final JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setBlockWhenExhausted(true); pool = new JedisPool(poolConfig, URI.create(conf.uri), conf.connectionTimeout); }
From source file:net.facework.core.streaming.misc.UriParser.java
public static void parse(String uri, Session session) throws IllegalStateException, IOException { boolean flash = false; int camera = CameraInfo.CAMERA_FACING_FRONT; Log.i("UriParser", "RTSP server received:" + uri); String[] uriItem = uri.split("/"); filename = uriItem[uriItem.length - 1]; List<NameValuePair> params = URLEncodedUtils.parse(URI.create(uri), "UTF-8"); if (params.size() > 0) { // Those parameters must be parsed first or else they won't necessarily be taken into account for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) { NameValuePair param = it.next(); // play file if (param.getName().equals("file")) { Log.i("UriParser", "file name:" + param.getValue()); session.setFile(param.getValue()); session.addFileVideoTrack(Session.FILE_VIDEO_H264); Log.i("UriParser", "RTSP work in FILE_VIDEO_H264 Mode. FILE:" + param.getValue()); session.addFileAudioTrack(Session.FILE_AUDIO_AAC); Log.i("UriParser", "RTSP work in FILE_AUDIO_AAC Mode. FILE:" + param.getValue()); session.setFileMode();//from ww w . j a v a 2 s .co m break; } // FLASH ON/OFF if (param.getName().equals("flash")) { if (param.getValue().equals("on")) flash = true; else flash = false; } // CAMERA -> the client can choose between the front facing camera and the back facing camera else if (param.getName().equals("camera")) { if (param.getValue().equals("back")) camera = CameraInfo.CAMERA_FACING_BACK; else if (param.getValue().equals("front")) camera = CameraInfo.CAMERA_FACING_FRONT; } // MULTICAST -> the stream will be sent to a multicast group // The default mutlicast address is 228.5.6.7, but the client can specify one else if (param.getName().equals("multicast")) { session.setRoutingScheme(Session.MULTICAST); if (param.getValue() != null) { try { InetAddress addr = InetAddress.getByName(param.getValue()); if (!addr.isMulticastAddress()) { throw new IllegalStateException("Invalid multicast address !"); } session.setDestination(addr); } catch (UnknownHostException e) { throw new IllegalStateException("Invalid multicast address !"); } } else { // Default multicast address session.setDestination(InetAddress.getByName("228.5.6.7")); } } // UNICAST -> the client can use this so specify where he wants the stream to be sent else if (param.getName().equals("unicast")) { if (param.getValue() != null) { try { InetAddress addr = InetAddress.getByName(param.getValue()); session.setDestination(addr); } catch (UnknownHostException e) { throw new IllegalStateException("Invalid destination address !"); } } } // TTL -> the client can modify the time to live of packets // By default ttl=64 else if (param.getName().equals("ttl")) { if (param.getValue() != null) { try { int ttl = Integer.parseInt(param.getValue()); if (ttl < 0) throw new IllegalStateException("The TTL must be a positive integer !"); session.setTimeToLive(ttl); } catch (Exception e) { throw new IllegalStateException("The TTL must be a positive integer !"); } } } // No tracks will be added to the session else if (param.getName().equals("stop")) { return; } } for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) { NameValuePair param = it.next(); // H264 if (param.getName().equals("h264")) { VideoQuality quality = VideoQuality.parseQuality(param.getValue()); session.addVideoTrack(Session.VIDEO_H264, camera, quality, flash); } // H263 else if (param.getName().equals("h263")) { VideoQuality quality = VideoQuality.parseQuality(param.getValue()); session.addVideoTrack(Session.VIDEO_H263, camera, quality, flash); } // AMRNB else if (param.getName().equals("amrnb") || param.getName().equals("amr")) { session.addAudioTrack(Session.AUDIO_AMRNB); } // AAC else if (param.getName().equals("aac")) { session.addAudioTrack(Session.AUDIO_AAC); } // Generic Audio Stream -> make use of api level 12 // TODO: Doesn't work :/ else if (param.getName().equals("testnewapi")) { session.addAudioTrack(Session.AUDIO_ANDROID_AMR); } } // The default behavior is to only add one video track if (session.getTrackCount() == 0) { session.addVideoTrack(); session.addAudioTrack(); } } else if (!filename.contains(":")) { if (filename.equals("h264.sdp")) { VideoQuality quality = VideoQuality.defaultVideoQualiy.clone(); session.addVideoTrack(Session.VIDEO_H264, camera, quality, flash); } else { Log.i("UriParser", "file name:" + filename + ";"); session.setFile(filename); session.addFileVideoTrack(Session.FILE_VIDEO_H264); Log.i("UriParser", "RTSP work in FILE_VIDEO_H264 Mode. FILE:" + filename); /*session.addFileAudioTrack(Session.FILE_AUDIO_AAC); Log.i("UriParser","RTSP work in FILE_AUDIO_AAC Mode. FILE:"+filename);*/ session.setFileMode(); } } // Uri has no parameters: the default behavior is to only add one video track else { session.addVideoTrack(); session.addAudioTrack(); } }
From source file:org.commonjava.cartographer.result.ProjectPathsResultTest.java
@Test public void jsonRoundTrip() throws Exception { ProjectPathsResult in = new ProjectPathsResult(); ProjectVersionRef ref = new SimpleProjectVersionRef("org.foo", "bar", "1"); in.addPath(ref,/*from ww w . j a va 2 s.co m*/ new ProjectPath( Collections.singletonList(new SimpleParentRelationship(URI.create("http://nowhere.com"), ref, new SimpleProjectVersionRef("org.dep", "project", "1.1"))))); ObjectMapper mapper = new ObjectMapper(); mapper.registerModules(new ProjectVersionRefSerializerModule(), new ProjectRelationshipSerializerModule()); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); String json = mapper.writeValueAsString(in); Logger logger = LoggerFactory.getLogger(getClass()); logger.debug(json); ProjectPathsResult out = mapper.readValue(json, ProjectPathsResult.class); }
From source file:es.tid.cosmos.platform.injection.server.ConfigurationTest.java
/** * //from w w w . j a va 2 s.co m * @throws Exception */ @Test public void shouldParseProperties() throws Exception { URL testConfig = getClass().getResource("test_config.properties"); Configuration instance = new Configuration(testConfig); assertEquals(2222, instance.getPort()); assertEquals(URI.create("hdfs://pshdp01:8011"), instance.getHdfsUrl()); assertEquals("pshdp01:8012", instance.getJobTrackerUrl()); assertEquals("jdbc:mysql:localhost", instance.getFrontendDbUrl()); assertEquals("database", instance.getDbName()); assertEquals("root", instance.getDbUser()); assertEquals("toor", instance.getDbPassword()); }
From source file:com.android.idtt.http.client.HttpRequest.java
public HttpRequest(HttpMethod method, String uri) { super(); this.method = method; setURI(URI.create(uri)); }
From source file:com.onemorecastle.util.HttpFetch.java
public static Bitmap fetchBitmap(String imageAddress, int sampleSize) throws MalformedURLException, IOException { Bitmap bitmap = null;/* w w w. j a v a 2 s .co m*/ DefaultHttpClient httpclient = null; try { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 2000); HttpConnectionParams.setSoTimeout(httpParameters, 5000); HttpConnectionParams.setSocketBufferSize(httpParameters, 512); HttpGet httpRequest = new HttpGet(URI.create(imageAddress)); httpclient = new DefaultHttpClient(); httpclient.setParams(httpParameters); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); InputStream instream = bufHttpEntity.getContent(); BitmapFactory.Options options = new BitmapFactory.Options(); //first decode with inJustDecodeBounds=true to check dimensions options.inJustDecodeBounds = true; options.inSampleSize = sampleSize; BitmapFactory.decodeStream(instream, null, options); //decode bitmap with inSampleSize set options.inSampleSize = calculateInSampleSize(options, MAX_WIDTH, MAX_HEIGHT); options.inPurgeable = true; options.inInputShareable = true; options.inDither = true; options.inJustDecodeBounds = false; //response=(HttpResponse)httpclient.execute(httpRequest); //entity=response.getEntity(); //bufHttpEntity=new BufferedHttpEntity(entity); instream = bufHttpEntity.getContent(); bitmap = BitmapFactory.decodeStream(instream, null, options); //close out stuff try { instream.close(); bufHttpEntity.consumeContent(); entity.consumeContent(); } finally { instream = null; bufHttpEntity = null; entity = null; } } catch (Exception x) { Log.e("HttpFetch.fetchBitmap", imageAddress, x); } finally { httpclient = null; } return (bitmap); }
From source file:com.yahoo.inmind.services.streaming.control.rtsp.UriParser.java
/** * Configures a Session according to the given URI. * Here are some examples of URIs that can be used to configure a Session: * <ul><li>rtsp://xxx.xxx.xxx.xxx:8086?h264&flash=on</li> * <li>rtsp://xxx.xxx.xxx.xxx:8086?h263&camera=front&flash=on</li> * <li>rtsp://xxx.xxx.xxx.xxx:8086?h264=200-20-320-240</li> * <li>rtsp://xxx.xxx.xxx.xxx:8086?aac</li></ul> * @param uri The URI//from ww w.ja va2s. co m * @throws IllegalStateException * @throws IOException * @return A Session configured according to the URI */ public static Session parse(String uri) throws IllegalStateException, IOException { SessionBuilder builder = SessionBuilder.getInstance().clone(); byte audioApi = 0, videoApi = 0; List<NameValuePair> params = URLEncodedUtilsHC4.parse(URI.create(uri), "UTF-8"); if (params.size() > 0) { builder.setAudioEncoder(SessionBuilder.AUDIO_NONE).setVideoEncoder(SessionBuilder.VIDEO_NONE); // Those parameters must be parsed first or else they won't necessarily be taken into account for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) { NameValuePair param = it.next(); // FLASH ON/OFF if (param.getName().equalsIgnoreCase("flash")) { if (param.getValue().equalsIgnoreCase("on")) builder.setFlashEnabled(true); else builder.setFlashEnabled(false); } // CAMERA -> the client can choose between the front facing camera and the back facing camera else if (param.getName().equalsIgnoreCase("camera")) { if (param.getValue().equalsIgnoreCase("back")) builder.setCamera(CameraInfo.CAMERA_FACING_BACK); else if (param.getValue().equalsIgnoreCase("front")) builder.setCamera(CameraInfo.CAMERA_FACING_FRONT); } // MULTICAST -> the stream will be sent to a multicast group // The default mutlicast address is 228.5.6.7, but the client can specify another else if (param.getName().equalsIgnoreCase("multicast")) { if (param.getValue() != null) { try { InetAddress addr = InetAddress.getByName(param.getValue()); if (!addr.isMulticastAddress()) { throw new IllegalStateException("Invalid multicast address !"); } builder.setDestination(param.getValue()); } catch (UnknownHostException e) { throw new IllegalStateException("Invalid multicast address !"); } } else { // Default multicast address builder.setDestination("228.5.6.7"); } } // UNICAST -> the client can use this to specify where he wants the stream to be sent else if (param.getName().equalsIgnoreCase("unicast")) { if (param.getValue() != null) { builder.setDestination(param.getValue()); } } // VIDEOAPI -> can be used to specify what api will be used to encode video (the MediaRecorder API or the MediaCodec API) else if (param.getName().equalsIgnoreCase("videoapi")) { if (param.getValue() != null) { if (param.getValue().equalsIgnoreCase("mr")) { videoApi = MediaStream.MODE_MEDIARECORDER_API; } else if (param.getValue().equalsIgnoreCase("mc")) { videoApi = MediaStream.MODE_MEDIACODEC_API; } } } // AUDIOAPI -> can be used to specify what api will be used to encode audio (the MediaRecorder API or the MediaCodec API) else if (param.getName().equalsIgnoreCase("audioapi")) { if (param.getValue() != null) { if (param.getValue().equalsIgnoreCase("mr")) { audioApi = MediaStream.MODE_MEDIARECORDER_API; } else if (param.getValue().equalsIgnoreCase("mc")) { audioApi = MediaStream.MODE_MEDIACODEC_API; } } } // TTL -> the client can modify the time to live of packets // By default ttl=64 else if (param.getName().equalsIgnoreCase("ttl")) { if (param.getValue() != null) { try { int ttl = Integer.parseInt(param.getValue()); if (ttl < 0) throw new IllegalStateException(); builder.setTimeToLive(ttl); } catch (Exception e) { throw new IllegalStateException("The TTL must be a positive integer !"); } } } // H.264 else if (param.getName().equalsIgnoreCase("h264")) { VideoQuality quality = VideoQuality.parseQuality(param.getValue()); builder.setVideoQuality(quality).setVideoEncoder(SessionBuilder.VIDEO_H264); } // H.263 else if (param.getName().equalsIgnoreCase("h263")) { VideoQuality quality = VideoQuality.parseQuality(param.getValue()); builder.setVideoQuality(quality).setVideoEncoder(SessionBuilder.VIDEO_H263); } // AMR else if (param.getName().equalsIgnoreCase("amrnb") || param.getName().equalsIgnoreCase("amr")) { AudioQuality quality = AudioQuality.parseQuality(param.getValue()); builder.setAudioQuality(quality).setAudioEncoder(SessionBuilder.AUDIO_AMRNB); } // AAC else if (param.getName().equalsIgnoreCase("aac")) { AudioQuality quality = AudioQuality.parseQuality(param.getValue()); builder.setAudioQuality(quality).setAudioEncoder(SessionBuilder.AUDIO_AAC); } } } if (builder.getVideoEncoder() == SessionBuilder.VIDEO_NONE && builder.getAudioEncoder() == SessionBuilder.AUDIO_NONE) { SessionBuilder b = SessionBuilder.getInstance(); builder.setVideoEncoder(b.getVideoEncoder()); builder.setAudioEncoder(b.getAudioEncoder()); } Session session = builder.build(); if (videoApi > 0 && session.getVideoTrack() != null) { session.getVideoTrack().setStreamingMethod(videoApi); } if (audioApi > 0 && session.getAudioTrack() != null) { session.getAudioTrack().setStreamingMethod(audioApi); } return session; }
From source file:com.conwet.silbops.api.impl.ConnectionFactoryImplTest.java
@Before public void setUp() throws Exception { server = new MockServer(); server.start();//ww w . j a v a 2 s . c o m factory = new ConnectionFactoryImpl(URI.create("silbops://localhost:" + server.getServerPort())); }