Java URI Parse parseServiceName(URI endpoint)

Here you can find the source of parseServiceName(URI endpoint)

Description

Parses the service name from an endpoint.

License

Open Source License

Declaration

@Deprecated
public static String parseServiceName(URI endpoint) 

Method Source Code

//package com.java2s;
/*/*w w w . j av a  2  s.  c om*/
 * Copyright 2015-2016 ksyun.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://ksyun.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

import java.net.URI;

public class Main {
    /**
     * Parses the service name from an endpoint. Can only handle endpoints of
     * the form 'service.[region.].api.ksyun.com'.
     *
     * @Deprecated This method currently doesn't support BJS endpoints. This
     * method is used only in AWS4Signer to identify the service name from an
     * endpoint. This method is broken as it no longer returns the service
     * name to used for signing for all KSC services. This method will be
     * removed as part of next major version upgrade.
     */
    @Deprecated
    public static String parseServiceName(URI endpoint) {
        String host = endpoint.getHost();

        // If we don't recognize the domain, throw an exception.
        if (!host.endsWith(".api.ksyun.com")) {
            throw new IllegalArgumentException(
                    "Cannot parse a service name from an unrecognized endpoint (" + host + ").");
        }

        String serviceAndRegion = host.substring(0, host.indexOf(".api.ksyun.com"));

        char separator = '.';

        // If we don't detect a separator between service name and region, then
        // assume that the region is not included in the hostname, and it's only
        // the service name (ex: "http://iam.ksyun.com").
        if (serviceAndRegion.indexOf(separator) == -1) {
            return serviceAndRegion;
        }

        String service = serviceAndRegion.substring(0, serviceAndRegion.indexOf(separator));

        return service;
    }
}

Related

  1. parseQueryString(URI uri, M queryParams)
  2. parseRegionName(URI endpoint)
  3. parseRegionName(URI endpoint)
  4. parseRegionName(URI endpoint)
  5. parseRepositoryItemUri(URI uri)
  6. parseServiceName(URI endpoint)
  7. parseURI(final String string)
  8. parseURI(final String value)
  9. parseURI(String connectionString, URI defaultURI)