List of usage examples for java.net URI getAuthority
public String getAuthority()
From source file:eu.planets_project.tb.impl.properties.ManuallyMeasuredPropertyHandlerImpl.java
/** * Creates a digital object for storing a user's manual properties * in the user's config path and returns the digo's data manager URI * @param userName/*from ww w . ja v a 2 s. co m*/ * @return */ private URI createAndStoreEmptyUserConfigDigo(String userName) throws Exception { URI drManagerID = DataRegistryFactory .createDataRegistryIdFromName("/experiment-files/testbed/users/" + userName).normalize(); URI storageURI = new URI(drManagerID.getScheme(), drManagerID.getAuthority(), drManagerID.getPath() + "/config/userproperties.xml", null, null).normalize(); //Create temp file. File temp = File.createTempFile("userproperties", ".xml"); //create and store the digital object DigitalObject userpropertiesXML = new DigitalObject.Builder(Content.byValue(temp)).title("userproperties") .build(); URI uriStored = dataRegistry.getDigitalObjectManager(drManagerID).storeAsNew(storageURI, userpropertiesXML); temp.delete(); log.info("created storage space for user defined manual properties"); return uriStored; }
From source file:com.twitter.distributedlog.service.DistributedLogClientBuilder.java
/** * URI to access proxy services. Assuming the write proxies are announced under `.write_proxy` of * the provided namespace uri./*w w w. ja va2 s. co m*/ * <p> * The builder will convert the dl uri (e.g. distributedlog://{zkserver}/path/to/namespace) to * zookeeper serverset based finagle name str (`zk!{zkserver}!/path/to/namespace/.write_proxy`) * * @param uri namespace uri to access the serverset of write proxies * @return distributedlog builder */ public DistributedLogClientBuilder uri(URI uri) { DistributedLogClientBuilder newBuilder = newBuilder(this); String zkServers = uri.getAuthority().replace(";", ","); String[] zkServerList = StringUtils.split(zkServers, ','); String finagleNameStr = String.format("zk!%s!%s/.write_proxy", zkServerList[random.nextInt(zkServerList.length)], // zk server uri.getPath()); newBuilder._routingServiceBuilder = RoutingUtils.buildRoutingService(finagleNameStr); newBuilder._enableRegionStats = false; return newBuilder; }
From source file:eu.planets_project.tb.impl.properties.ManuallyMeasuredPropertyHandlerImpl.java
/** * Checks if we can access the digital object containing the user's manual property definitions * @param userName//www . j a va 2s .c om * @return */ private boolean isUserPropConfigDigoExisting(String userName) { try { URI drManagerID = DataRegistryFactory .createDataRegistryIdFromName("/experiment-files/testbed/users/" + userName).normalize(); URI storageURI = new URI(drManagerID.getScheme(), drManagerID.getAuthority(), drManagerID.getPath() + "/config/userproperties.xml", null, null).normalize(); //retrieve the user specific properties xml file from his storage space dataRegistry.getDigitalObjectManager(drManagerID).retrieve(storageURI); return true; } catch (Exception e) { //we need to create the user's digital object containing his manual properties return false; } }
From source file:org.apache.flink.runtime.fs.maprfs.MapRFileSystem.java
@Override public void initialize(final URI path) throws IOException { if (LOG.isInfoEnabled()) { LOG.info(String.format("Initializing MapR file system for path %s", path.toString())); }//w w w . j a v a 2 s . co m final String authority = path.getAuthority(); if (authority == null || authority.isEmpty()) { // Use the default constructor to instantiate MapR file system // object try { this.fs = this.fsClass.newInstance(); } catch (Exception e) { throw new IOException(e); } } else { // We have an authority, check the MapR cluster configuration to // find the CLDB locations. final String[] cldbLocations = getCLDBLocations(authority); // Find the appropriate constructor final Constructor<? extends org.apache.hadoop.fs.FileSystem> constructor; try { constructor = this.fsClass.getConstructor(String.class, String[].class); } catch (NoSuchMethodException e) { throw new IOException(e); } // Instantiate the file system object try { this.fs = constructor.newInstance(authority, cldbLocations); } catch (Exception e) { throw new IOException(e); } } this.fs.initialize(path, this.conf); }
From source file:eu.planets_project.tb.impl.properties.ManuallyMeasuredPropertyHandlerImpl.java
/** * Takes a list of user defined properties and writes them back to the user config space using * the update operation on the digital object manager * @param userName//from w ww. j av a 2s. c o m * @param lProps */ private void updateUserConfigProps(String userName, List<ManuallyMeasuredProperty> lProps) throws Exception { URI drManagerID = DataRegistryFactory .createDataRegistryIdFromName("/experiment-files/testbed/users/" + userName).normalize(); URI storageURI = new URI(drManagerID.getScheme(), drManagerID.getAuthority(), drManagerID.getPath() + "/config/userproperties.xml", null, null).normalize(); //Create temp file, build and write xml content to file File temp = File.createTempFile("userproperties", ".xml"); BufferedWriter writer = new BufferedWriter(new FileWriter(temp)); writer.write("<userDefinedProperties>\n"); for (ManuallyMeasuredProperty p : lProps) { writer.write("<property tburi=\"" + p.getURI() + "\">\n"); writer.write("<name>" + p.getName() + "</name>\n"); writer.write("<description>" + p.getDescription() + "</description>\n"); writer.write("</property>\n"); } writer.write("</userDefinedProperties>"); writer.close(); //build a digital object DigitalObject digoManualProps = new DigitalObject.Builder(Content.byValue(temp)).title("userproperties") .build(); //call update on the digital object manager dataRegistry.getDigitalObjectManager(drManagerID).updateExisting(storageURI, digoManualProps); temp.delete(); log.info("updated storage space for user defined manual properties"); }
From source file:org.mariotaku.twidere.util.httpclient.HttpClientImpl.java
@Override public twitter4j.http.HttpResponse request(final twitter4j.http.HttpRequest req) throws TwitterException { try {/*from ww w .j a v a 2s. c o m*/ HttpRequestBase commonsRequest; final HostAddressResolver resolver = conf.getHostAddressResolver(); final String url_string = req.getURL(); final URI url_orig; try { url_orig = new URI(url_string); } catch (final URISyntaxException e) { throw new TwitterException(e); } final String host = url_orig.getHost(), authority = url_orig.getAuthority(); final String resolved_host = resolver != null ? resolver.resolve(host) : null; final String resolved_url = !isEmpty(resolved_host) ? url_string.replace("://" + host, "://" + resolved_host) : url_string; if (req.getMethod() == RequestMethod.GET) { commonsRequest = new HttpGet(resolved_url); } else if (req.getMethod() == RequestMethod.POST) { final HttpPost post = new HttpPost(resolved_url); // parameter has a file? boolean hasFile = false; final HttpParameter[] params = req.getParameters(); if (params != null) { for (final HttpParameter parameter : params) { if (parameter.isFile()) { hasFile = true; break; } } if (!hasFile) { if (params.length > 0) { post.setEntity(new UrlEncodedFormEntity(params)); } } else { final MultipartEntity me = new MultipartEntity(); for (final HttpParameter parameter : params) { if (parameter.isFile()) { final ContentBody body = new FileBody(parameter.getFile(), parameter.getContentType()); me.addPart(parameter.getName(), body); } else { final ContentBody body = new StringBody(parameter.getValue(), "text/plain; charset=UTF-8", Charset.forName("UTF-8")); me.addPart(parameter.getName(), body); } } post.setEntity(me); } } post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); commonsRequest = post; } else if (req.getMethod() == RequestMethod.DELETE) { commonsRequest = new HttpDelete(resolved_url); } else if (req.getMethod() == RequestMethod.HEAD) { commonsRequest = new HttpHead(resolved_url); } else if (req.getMethod() == RequestMethod.PUT) { commonsRequest = new HttpPut(resolved_url); } else throw new TwitterException("Unsupported request method " + req.getMethod()); final Map<String, String> headers = req.getRequestHeaders(); for (final String headerName : headers.keySet()) { commonsRequest.addHeader(headerName, headers.get(headerName)); } String authorizationHeader; if (req.getAuthorization() != null && (authorizationHeader = req.getAuthorization().getAuthorizationHeader(req)) != null) { commonsRequest.addHeader("Authorization", authorizationHeader); } if (!isEmpty(resolved_host) && !resolved_host.equals(host)) { commonsRequest.addHeader("Host", authority); } final ApacheHttpClientHttpResponseImpl res; try { res = new ApacheHttpClientHttpResponseImpl(client.execute(commonsRequest), conf); } catch (final IllegalStateException e) { throw new TwitterException("Please check your API settings.", e); } catch (final NullPointerException e) { // Bug http://code.google.com/p/android/issues/detail?id=5255 throw new TwitterException("Please check your APN settings, make sure not to use WAP APNs.", e); } catch (final OutOfMemoryError e) { // I don't know why OOM thown, but it should be catched. System.gc(); throw new TwitterException("Unknown error", e); } final int statusCode = res.getStatusCode(); if (statusCode < OK || statusCode > ACCEPTED) throw new TwitterException(res.asString(), req, res); return res; } catch (final IOException e) { throw new TwitterException(e); } }
From source file:org.lockss.util.UrlUtil.java
/** Resolve child relative to base */ // This version is a wrapper for java.net.URI.resolve(). Java class has // two undesireable behaviors: it resolves ("http://foo.bar", "a.html") // to "http://foo.bara.html" (fails to supply missing "/" to base with no // path), and it resolves ("http://foo.bar/xxx.php", "?foo=bar") to // "http://foo.bar/?foo=bar" (in accordance with RFC 2396), while all the // browsers resolve it to "http://foo.bar/xxx.php?foo=bar" (in accordance // with RFC 1808). This mimics enough of the logic of // java.net.URI.resolve(URI, URI) to detect those two cases, and defers // to the URI code for other cases. private static java.net.URI resolveUri0(java.net.URI base, java.net.URI child) throws MalformedURLException { // check if child is opaque first so that NPE is thrown // if child is null. if (child.isOpaque() || base.isOpaque()) { return child; }/*www .ja va 2s .co m*/ try { String scheme = base.getScheme(); String authority = base.getAuthority(); String path = base.getPath(); String query = base.getQuery(); String fragment = child.getFragment(); // If base has null path, ensure authority is separated from path in // result. (java.net.URI resolves ("http://foo.bar", "x.y") to // http://foo.barx.y) if (StringUtil.isNullString(base.getPath())) { path = "/"; base = new java.net.URI(scheme, authority, path, query, fragment); } // Absolute child if (child.getScheme() != null) return child; if (child.getAuthority() != null) { // not relative, defer to URI return base.resolve(child); } // Fragment only, return base with this fragment if (child.getPath().equals("") && (child.getFragment() != null) && (child.getQuery() == null)) { if ((base.getFragment() != null) && child.getFragment().equals(base.getFragment())) { return base; } java.net.URI ru = new java.net.URI(scheme, authority, path, query, fragment); return ru; } query = child.getQuery(); authority = base.getAuthority(); if (StringUtil.isNullString(child.getPath())) { // don't truncate base path if child has no path path = base.getPath(); } else if (child.getPath().charAt(0) == '/') { // Absolute child path path = child.getPath(); } else { // normal relative path, defer to URI return base.resolve(child); } // create URI from relativized components java.net.URI ru = new java.net.URI(scheme, authority, path, query, fragment); return ru; } catch (URISyntaxException e) { throw newMalformedURLException(e); } }
From source file:org.eclipse.orion.internal.server.search.SearchActivator.java
public void addAtributesFor(HttpServletRequest request, URI resource, JSONObject representation) { String service = request.getServletPath(); if (!("/file".equals(service) || "/workspace".equals(service))) //$NON-NLS-1$ //$NON-NLS-2$ return;//from w w w . ja va 2s.c o m try { // we can also augment with a query argument that includes the resource path URI result = new URI(resource.getScheme(), resource.getAuthority(), "/filesearch", "q=", null); //$NON-NLS-1$//$NON-NLS-2$ representation.put(ProtocolConstants.KEY_SEARCH_LOCATION, result); } catch (URISyntaxException e) { LogHelper.log(e); } catch (JSONException e) { // key and value are well-formed strings so this should not happen throw new RuntimeException(e); } }
From source file:eu.planets_project.tb.impl.properties.ManuallyMeasuredPropertyHandlerImpl.java
/** * Loads all property definitions which are stored as XML in the user's storage area * @return//from ww w . ja v a 2s . co m */ public List<ManuallyMeasuredProperty> loadAllUserDefinedManualProperties(String userName) { log.info("loading all manually defined user properties for: " + userName); List<ManuallyMeasuredProperty> ret = new ArrayList<ManuallyMeasuredProperty>(); try { URI drManagerID = DataRegistryFactory .createDataRegistryIdFromName("/experiment-files/testbed/users/" + userName).normalize(); URI storageURI = new URI(drManagerID.getScheme(), drManagerID.getAuthority(), drManagerID.getPath() + "/config/userproperties.xml", null, null).normalize(); //retrieve the user specific properties xml file from his storage space DigitalObject digoUserProps = dataRegistry.getDigitalObjectManager(drManagerID).retrieve(storageURI); //parse the XML and extract the Properties DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbfactory.newDocumentBuilder(); java.io.InputStream userDefinedPropsXML = digoUserProps.getContent().getInputStream(); Document doc = builder.parse(userDefinedPropsXML); Element root = doc.getDocumentElement(); //read the properties from the xml-file ret = parseManualPropertiesXML(root, true); userDefinedPropsXML.close(); log.info("successfully extracted " + ret.size() + " manual property definitions for user: " + userName); return ret; } catch (Exception e) { log.debug("unable to retrieve user specific manual properties definitions for: " + userName + " " + e); return ret; } }
From source file:org.jvoicexml.documentserver.schemestrategy.HttpSchemeStrategy.java
/** * {@inheritDoc}/* ww w .j a v a 2 s . c o m*/ */ @Override public InputStream getInputStream(final String sessionId, final URI uri, final RequestMethod method, final long timeout, final Collection<KeyValuePair> parameters) throws BadFetchError { final HttpClient client = SESSION_STORAGE.getSessionIdentifier(sessionId); final URI fullUri; try { final URI fragmentLessUri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(), null); fullUri = addParameters(parameters, fragmentLessUri); } catch (URISyntaxException e) { throw new BadFetchError(e.getMessage(), e); } catch (SemanticError e) { throw new BadFetchError(e.getMessage(), e); } final String url = fullUri.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("connecting to '" + url + "'..."); } final HttpUriRequest request; if (method == RequestMethod.GET) { request = new HttpGet(url); } else { request = new HttpPost(url); } attachFiles(request, parameters); try { final HttpParams params = client.getParams(); setTimeout(timeout, params); final HttpResponse response = client.execute(request); final StatusLine statusLine = response.getStatusLine(); final int status = statusLine.getStatusCode(); if (status != HttpStatus.SC_OK) { throw new BadFetchError(statusLine.getReasonPhrase() + " (HTTP error code " + status + ")"); } final HttpEntity entity = response.getEntity(); return entity.getContent(); } catch (IOException e) { throw new BadFetchError(e.getMessage(), e); } }