All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openstack4j.core.transport.functions.EndpointURIFromRequestFunction Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package org.openstack4j.core.transport.functions;

import static org.openstack4j.core.transport.ClientConstants.URI_SEP;

import org.openstack4j.core.transport.HttpRequest;

import com.google.common.base.Function;

/**
 * Builds a URI comprising of Endpoint and Path from a HttpRequest object
 * 
 * @author Jeremy Unruh
 */
public class EndpointURIFromRequestFunction implements Function, String> {

    /**
     * {@inheritDoc}
     */
    @Override
    public String apply(HttpRequest request) {
        if (request.getEndpoint().endsWith(URI_SEP) || request.getPath().startsWith(URI_SEP))
            return escape(request.getEndpoint() + request.getPath());
        
        return escape(request.getEndpoint() + URI_SEP + request.getPath());
    }
    
    private String escape(String uri) {
        return uri.replaceAll(" ", "%20");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy