Example usage for java.net URI getScheme

List of usage examples for java.net URI getScheme

Introduction

In this page you can find the example usage for java.net URI getScheme.

Prototype

public String getScheme() 

Source Link

Document

Returns the scheme component of this URI.

Usage

From source file:io.soabase.client.apache.WrappedHttpClient.java

private HttpHost toHost(URI uri) {
    return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
}

From source file:org.jclouds.http.apachehc.ApacheHCHttpCommandExecutorService.java

private org.apache.http.HttpResponse executeRequest(HttpUriRequest nativeRequest)
        throws IOException, ClientProtocolException {
    URI endpoint = URI.create(nativeRequest.getRequestLine().getUri());
    HttpHost host = new HttpHost(endpoint.getHost(), endpoint.getPort(), endpoint.getScheme());
    org.apache.http.HttpResponse nativeResponse = client.execute(host, nativeRequest);
    return nativeResponse;
}

From source file:org.fcrepo.apix.registry.impl.HttpRegistry.java

@Override
public boolean hasInDomain(final URI uri) {
    return uri.getScheme().startsWith("http");
}

From source file:com.sina.cloudstorage.util.URIBuilder.java

private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.schemeSpecificPart = uri.getSchemeSpecificPart();
    this.authority = uri.getAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.userInfo = uri.getUserInfo();
    this.path = uri.getPath();
    this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8);
    this.fragment = uri.getFragment();
}

From source file:fr.ippon.wip.http.hc.HttpClientDecorator.java

HttpHost getHttpHost(HttpUriRequest request) {
    URI uri = request.getURI();
    return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
}

From source file:cat.calidos.morfeu.utils.injection.DataFetcherModule.java

@Produces
public ListenableFuture<InputStream> fetchData(URI uri, @Named("httpData") Producer<InputStream> httpData,
        @Named("fileData") Producer<InputStream> fileData) throws FetchingException {
    if (uri.getScheme() != null && uri.getScheme().equals("file")) {
        return fileData.get();
    } else {/*from  w w  w .j av a2  s  .  c o  m*/
        return httpData.get();
    }
}

From source file:de.tuberlin.cit.livescale.messaging.endpoints.GCMEndpoint.java

@Override
protected void performSend(MessageManifest manifest) {
    for (de.tuberlin.cit.livescale.messaging.Message m : manifest.getMessages()) {
        try {//from w  ww . j  av a2  s  .c om
            Result result = this.sender.send(this.createMessage(m),
                    manifest.getTargetURI().getPath().substring(1), 5);
            // let's check for side conditions ...
            if (result.getMessageId() != null) {
                String canonicalRegId = result.getCanonicalRegistrationId();
                if (canonicalRegId != null) { // user has a new address
                    URI localURI = getLocalEndpointURI();
                    URI newTargetURI = new URI(localURI.getScheme(), localURI.getAuthority(), canonicalRegId,
                            "", "");
                    notifyListenersDeliveryEvent(new TargetMovedSuccess(manifest, newTargetURI));

                }
            } else { // User's gone.
                String error = result.getErrorCodeName();
                if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
                    notifyListenersDeliveryEvent(new TargetMovedFailure(manifest));
                }
            }
        } catch (IOException e) {
            notifyListenersDeliveryEvent(new ServiceUnavailableFailure(manifest));
        } catch (URISyntaxException e) {
            LOG.debug("Error building a new URI from the local one. THIS SHOULD NEVER HAPPEN!", e);
        }
    }
}

From source file:org.mobicents.servlet.sip.restcomm.interpreter.http.HttpRequestDescriptor.java

public HttpRequestDescriptor(final URI uri, final String method, final List<NameValuePair> parameters)
        throws UnsupportedEncodingException, URISyntaxException {
    super();// w  w  w .  j av  a 2s . co  m
    this.uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), null, null);
    this.method = method;
    final String query = uri.getQuery();
    if (query != null) {
        parameters.addAll(URLEncodedUtils.parse(uri, "UTF-8"));
    }
    this.parameters = parameters;
}

From source file:com.alibaba.antx.config.resource.DefaultAuthenticationHandler.java

private String getKey(URI uri) {
    StringBuffer buf = new StringBuffer();

    buf.append(uri.getScheme()).append("://");

    String user = ResourceUtil.getUsername(uri);
    if (!StringUtil.isEmpty(user)) {
        buf.append(user).append("@");
    }/*from  w w  w.  j  a va2 s  .com*/

    buf.append(uri.getHost());

    if (uri.getPort() > 0) {
        buf.append(":").append(uri.getPort());
    }

    return buf.toString();
}

From source file:com.vmware.identity.idm.server.ServerUtils.java

private static ILdapConnectionEx getLdapConnection(URI uri, String userName, String password,
        AuthenticationType authType, boolean useGcPort,
        LdapCertificateValidationSettings certValidationsettings) throws Exception {
    ValidateUtil.validateNotNull(uri, "uri");

    boolean isLdaps = uri.getScheme().compareToIgnoreCase(DirectoryStoreProtocol.LDAPS.getName()) == 0;

    List<LdapSetting> connOptions = null;
    List<LdapSetting> settings = new ArrayList<LdapSetting>();
    settings.add(new LdapSetting(LdapOption.LDAP_OPT_PROTOCOL_VERSION, LdapConstants.LDAP_VERSION3));
    settings.add(new LdapSetting(LdapOption.LDAP_OPT_REFERRALS, Boolean.FALSE));
    settings.add(new LdapSetting(LdapOption.LDAP_OPT_NETWORK_TIMEOUT, DEFAULT_LDAP_NETWORK_TIMEOUT));

    if (isLdaps) {
        //if is ldaps connection and certificate validation is enabled set the options for validation
        boolean isLdapsCertValidationEnabled = certValidationsettings != null
                && (certValidationsettings.isForceValidation()
                        || IdmServerConfig.getInstance().isLdapsCertValidationEnabled()
                        || !certValidationsettings.isLegacy());
        if (isLdapsCertValidationEnabled) {
            ISslX509VerificationCallback certVerifierCallback = certValidationsettings
                    .getCertVerificationCallback(uri);
            settings.add(new LdapSetting(LdapOption.LDAP_OPT_X_TLS_REQUIRE_CERT,
                    LdapConstants.LDAP_OPT_X_TLS_DEMAND));
            settings.add(/*w ww  . j a  v a2  s.  c o  m*/
                    new LdapSetting(LdapOption.LDAP_OPT_X_CLIENT_TRUSTED_FP_CALLBACK, certVerifierCallback));

            int sslMinProtocol = certValidationsettings.isLegacy()
                    ? LdapSSLProtocols.getDefaultLegacyMinProtocol().getCode()
                    : LdapSSLProtocols.getDefaultMinProtocol().getCode();
            settings.add(new LdapSetting(LdapOption.LDAP_OPT_X_TLS_PROTOCOL, sslMinProtocol));
        } else {
            settings.add(new LdapSetting(LdapOption.LDAP_OPT_X_TLS_REQUIRE_CERT,
                    LdapConstants.LDAP_OPT_X_TLS_NEVER));
        }
    }
    // When doing GSSAPI authentication, LDAP SASL binding by default does reverse DNS lookup to validate the
    // target name, this causes authentication failures because Most DNS servers in AD do not have PTR records
    // registered for all DCs, any of which could be the binding target.
    if (!SystemUtils.IS_OS_WINDOWS && authType == AuthenticationType.USE_KERBEROS
            || authType == AuthenticationType.SRP) {
        settings.add(new LdapSetting(LdapOption.LDAP_OPT_X_SASL_NOCANON, LdapConstants.LDAP_OPT_ON));
    }

    connOptions = Collections.unmodifiableList(settings);

    ILdapConnectionEx connection = null;

    // if No port# or the default port of 389 (ldap) or 636 (ldaps) is specified then useGcport takes effect;
    // otherwise, go with the explicit specified port#
    if (authType == AuthenticationType.SRP) {
        connection = (ILdapConnectionEx) LdapConnectionFactory.getInstance().getLdapConnection(uri, connOptions,
                true);
    } else if ((uri.getPort() == -1 || uri.getPort() == LdapConstants.LDAP_PORT
            || uri.getPort() == LdapConstants.LDAP_SSL_PORT) && useGcPort) {
        connection = LdapConnectionFactoryEx.getInstance().getLdapConnection(uri.getHost(),
                isLdaps ? LdapConstants.LDAP_SSL_GC_PORT : LdapConstants.LDAP_GC_PORT, connOptions);
    } else {
        connection = LdapConnectionFactoryEx.getInstance().getLdapConnection(uri, connOptions);
    }

    try {
        // All the client options are set, bind now

        long startTime = System.nanoTime();
        if (AuthenticationType.SRP == authType) {
            ValidateUtil.validateNotEmpty(userName, "userName");
            ValidateUtil.validateNotEmpty(password, "password");
            ((ILdapConnectionExWithGetConnectionString) connection).bindSaslSrpConnection(userName, password);
        } else if (AuthenticationType.USE_KERBEROS == authType) {
            String userUPN = null;
            int idxSep = 0;
            if (!ServerUtils.isNullOrEmpty(userName)) {
                userUPN = ValidateUtil.normalizeIdsKrbUserName(userName);
                idxSep = userUPN.indexOf(ValidateUtil.UPN_SEPARATOR);
            }

            connection.bindSaslConnection(
                    ServerUtils.isNullOrEmpty(userUPN) ? null : userUPN.substring(0, idxSep),
                    ServerUtils.isNullOrEmpty(userUPN) ? null : userUPN.substring(idxSep + 1), password);
        } else if (AuthenticationType.PASSWORD == authType) {
            ValidateUtil.validateNotEmpty(userName, "userName");
            ValidateUtil.validateNotEmpty(password, "password");
            connection.bindConnection(userName, password, LdapBindMethod.LDAP_BIND_SIMPLE);
        } else {
            String errMsg = String.format("Unsupported authenticationType to bind connection: [%s, %s]", uri,
                    userName);
            logger.warn(errMsg);
            throw new IllegalStateException(errMsg);
        }

        long delta = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        if (logger.isTraceEnabled()) {
            logger.trace(String.format("\tbinding connection took [%d] ms", delta));
        }
        if (IdmServer.getPerfDataSinkInstance() != null) {
            IdmServer.getPerfDataSinkInstance().addMeasurement(
                    new PerfBucketKey(PerfMeasurementPoint.LdapBindConnection, uri.toString()), delta);
        }
    } catch (Exception ex) {
        logger.warn(String.format("cannot bind connection: [%s, %s]", uri, userName));
        if (connection != null) {
            connection.close();
        }
        throw ex;
    }

    return connection;
}