Example usage for java.net URL getAuthority

List of usage examples for java.net URL getAuthority

Introduction

In this page you can find the example usage for java.net URL getAuthority.

Prototype

public String getAuthority() 

Source Link

Document

Gets the authority part of this URL .

Usage

From source file:org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.java

public void initZookeeperAddressIfNecessary(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    String[] beanNameArray = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanNameArray.length; i++) {
        String beanName = beanNameArray[i];
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        if (com.alibaba.dubbo.config.RegistryConfig.class.getName().equals(beanDef.getBeanClassName())) {
            MutablePropertyValues mpv = beanDef.getPropertyValues();
            PropertyValue protpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_PROTOCOL);
            PropertyValue addrpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_ADDRESS);

            String protocol = null;
            String address = null;
            if (addrpv == null) {
                throw new FatalBeanException("zookeeper address cannot be null!"); // should never happen
            } else if (protpv == null) {
                String value = String.valueOf(addrpv.getValue());
                try {
                    URL url = new URL(null, value, this);
                    protocol = url.getProtocol();
                    address = url.getAuthority();
                } catch (Exception ex) {
                    throw new FatalBeanException("Unsupported format!");
                }/*from  w ww  .  j  av  a  2  s  .c  om*/
            } else {
                protocol = String.valueOf(protpv.getValue());
                String value = StringUtils.trimToEmpty(String.valueOf(addrpv.getValue()));
                int index = value.indexOf(protocol);
                if (index == -1) {
                    address = value;
                } else if (index == 0) {
                    String str = StringUtils.trimToEmpty(value.substring(protocol.length()));
                    if (str.startsWith("://")) {
                        address = StringUtils.trimToEmpty(str.substring(3));
                    } else {
                        throw new FatalBeanException("Unsupported format!");
                    }
                } else {
                    throw new FatalBeanException("Unsupported format!");
                }
            }

            if (KEY_DUBBO_REGISTRY_ZOOKEEPER.equalsIgnoreCase(protocol) == false) {
                throw new FatalBeanException("Unsupported protocol!");
            }

            String addrKey = "zookeeperAddr";
            String[] watcherBeanArray = beanFactory
                    .getBeanNamesForType(org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.class);
            BeanDefinition watcherBeanDef = beanFactory.getBeanDefinition(watcherBeanArray[0]);
            MutablePropertyValues warcherMpv = watcherBeanDef.getPropertyValues();
            PropertyValue warcherPv = warcherMpv.getPropertyValue(addrKey);
            if (warcherPv == null) {
                warcherMpv.addPropertyValue(new PropertyValue(addrKey, address));
            } else {
                warcherMpv.removePropertyValue(addrKey);
                warcherMpv.addPropertyValue(new PropertyValue(addrKey, address));
            }

        }
    }
}

From source file:org.apache.hadoop.hdfs.qjournal.client.URLLogInputStream.java

@Override
public String getName() {
    URL url = log.getURL();
    String address = url.getAuthority();
    return Joiner.on("").join("[JN: ", address, ", firstTxid: ", getFirstTxId(), ", lastValidTxId: ",
            lastValidTxId, ", inProgress: ", isInProgress(), "]");
}

From source file:org.xwiki.portlet.controller.DispatchFilter.java

/**
 * @param expectedURL the expected URL//from   w  w w  .jav a2s .  c o m
 * @param actualURL the actual URL
 * @return {@code true} if the given URLs point to the same web server, {@code false} otherwise
 */
private boolean sameServer(URL expectedURL, URL actualURL) {
    return expectedURL.getProtocol().equals(actualURL.getProtocol())
            && expectedURL.getAuthority().equals(actualURL.getAuthority());
}

From source file:org.xwiki.contrib.authentication.internal.DefaultTrustedAuthenticationConfiguration.java

private String stripContextPathFromURL(URL url) {
    XWikiContext context = contextProvider.get();
    return StringUtils.removeStart(url.toExternalForm(),
            url.getProtocol() + "://" + url.getAuthority() + context.getWiki().getWebAppPath(context));
}

From source file:eionet.webq.web.interceptor.CdrAuthorizationInterceptor.java

/**
 * Gets host from url string.//from  ww  w . j  a v  a  2s. c om
 * Result will be in format protocol://host:port.
 *
 * @param url url to be checked
 * @return host or null if provided string is malformed URL
 */
private String getUrlHost(String url) {
    try {
        URL parsedUrl = new URL(url);
        return parsedUrl.getProtocol() + "://" + parsedUrl.getAuthority();
    } catch (MalformedURLException e) {
        return null;
    }
}

From source file:org.apache.http.impl.client.cache.CacheInvalidator.java

protected void flushUriIfSameHost(URL requestURL, URL targetURL) {
    URL canonicalTarget = getAbsoluteURL(cacheKeyGenerator.canonicalizeUri(targetURL.toString()));
    if (canonicalTarget == null)
        return;// ww w .j  a  v  a2 s  . c  om
    if (canonicalTarget.getAuthority().equalsIgnoreCase(requestURL.getAuthority())) {
        flushEntry(canonicalTarget.toString());
    }
}

From source file:org.eclipse.smila.processing.pipelets.xmlprocessing.XmlSplitterPipelet.java

/**
 * Get the external InputStream to the given url or filee path.
 * // w ww  .j  a va2  s  .  c om
 * @param attrtibuteValue
 *          the attrtibuteValue denoting an URL or file path
 * @return a InputStream or null
 * @throws IOException
 *           if any error occurs
 */
private InputStream loadExternalInputStream(final String attrtibuteValue) throws IOException {
    InputStream stream = null;
    if (attrtibuteValue != null && attrtibuteValue.trim().length() > 0) {
        if (attrtibuteValue.startsWith("file")) {
            final URL url = new URL(attrtibuteValue);
            stream = new FileInputStream(url.getAuthority() + url.getPath());
        } else if (attrtibuteValue.startsWith("http")) {
            final URL url = new URL(attrtibuteValue);
            final HttpClient httpClient = new HttpClient();
            final GetMethod getMethod = new GetMethod(url.toString());
            httpClient.executeMethod(getMethod);
            stream = getMethod.getResponseBodyAsStream();
        } else {
            stream = new FileInputStream(attrtibuteValue);
        }
    } // if
    return stream;
}

From source file:org.apache.ranger.services.kms.client.KMSClient.java

private String[] createProvider(String uri) throws IOException, URISyntaxException {
    URI providerUri = new URI(uri);
    URL origUrl = new URL(extractKMSPath(providerUri).toString());
    String authority = origUrl.getAuthority();
    // check for ';' which delimits the backup hosts
    if (Strings.isNullOrEmpty(authority)) {
        throw new IOException("No valid authority in kms uri [" + origUrl + "]");
    }/*from w ww.  ja  va 2s .  c o m*/
    // Check if port is present in authority
    // In the current scheme, all hosts have to run on the same port
    int port = -1;
    String hostsPart = authority;
    if (authority.contains(":")) {
        String[] t = authority.split(":");
        try {
            port = Integer.parseInt(t[1]);
        } catch (Exception e) {
            throw new IOException("Could not parse port in kms uri [" + origUrl + "]");
        }
        hostsPart = t[0];
    }
    return createProvider(providerUri, origUrl, port, hostsPart);
}

From source file:ch.admin.hermes.etl.load.cmis.AlfrescoCMISClient.java

/**
 * Initialisierung, wird von JavaScript aufgerufen
 * @throws Exception Allgemeiner I/O Fehler
 *//*from  w w w.j  a  v  a 2  s . c om*/
private void init(String remote, String user, String pass) throws Exception {
    this.user = (user != null) ? user : this.user;
    this.pass = (pass != null) ? pass : this.pass;

    // Host und Path trennen, weil unterschiedlich verwendet.
    if (remote != null) {
        URL url = new URL(remote);
        this.host = url.getProtocol() + "://" + url.getAuthority();
        if (url.getPath() != null && url.getPath().trim().length() > 0)
            this.path = url.getPath();
    }

    SessionFactory sessionFactory = SessionFactoryImpl.newInstance();

    Map<String, String> params = new HashMap<String, String>();
    params.put(SessionParameter.USER, this.user);
    params.put(SessionParameter.PASSWORD, this.pass);
    params.put(SessionParameter.ATOMPUB_URL, this.host + CMIS);
    params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

    // session locale
    params.put(SessionParameter.LOCALE_ISO3166_COUNTRY, "");
    params.put(SessionParameter.LOCALE_ISO639_LANGUAGE, "de_CH");
    params.put(SessionParameter.LOCALE_VARIANT, "");

    // Set the alfresco object factory
    params.put(SessionParameter.OBJECT_FACTORY_CLASS,
            "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

    List<Repository> repos = sessionFactory.getRepositories(params);
    // Alfresco kennt keine Repositories?
    session = repos.get(0).createSession();

    // Zugriff auf http://www.hermes.admin.ch
    client = getHttpClient();
}

From source file:org.eclipse.smila.connectivity.framework.agent.jobfile.JobFileReader.java

/**
 * Get the InputStream to the given url.
 * //w ww  . j a v a 2s.  co  m
 * @param url
 *          the url
 * @return a InputStream or null
 * @throws IOException
 *           if any error occurs
 */
private InputStream getInputStream(final URL url) throws IOException {
    InputStream stream = null;
    if (url != null) {
        if (url.getProtocol().startsWith("file")) {
            stream = new FileInputStream(url.getAuthority() + url.getPath());
        } else {
            final HttpClient httpClient = new HttpClient();
            final GetMethod getMethod = new GetMethod(url.toString());
            httpClient.executeMethod(getMethod);
            stream = getMethod.getResponseBodyAsStream();
        }
    } // if
    return stream;
}