package com.myyearbook.hudson.plugins.confluence;

import java.net.URI;
import java.util.logging.Logger;

/**
 * Utility methods
 *
 * @author Joe Hansche <jhansche@myyearbook.com>
 */
public class Util {
    private static final Logger LOGGER = Logger.getLogger(Util.class.getName());

    /** Relative path to resolve the XmlRpc endpoint URL */
    private static final String XML_RPC_URL_PATH = "/rpc/xmlrpc";

    /** Relative path to resolve the SOAP endpoint URL */
    private static final String SOAP_URL_PATH = "/rpc/soap-axis/confluenceservice-v1";

    /**
     * Convert a generic Confluence URL into the XmlRpc endpoint URL
     *
     * @param url
     * @return
     * @see #XML_RPC_URL_PATH
     */
    public static String confluenceUrlToXmlRpcUrl(String url) {
	URI uri = URI.create(url);
	return uri.resolve(uri.getPath() + XML_RPC_URL_PATH).normalize().toString();
    }

    /**
     * Convert a generic Confluence URL into the SOAP endpoint URL
     *
     * @param url
     * @return
     * @see #SOAP_URL_PATH
     */
    public static String confluenceUrlToSoapUrl(String url) {
	URI uri = URI.create(url);
	return uri.resolve(uri.getPath() + SOAP_URL_PATH).normalize().toString();
    }
}


package com.myyearbook.hudson.plugins.confluence;

import java.net.URI;

/**
 * Utility methods
 * 
 * @author Joe Hansche <jhansche@myyearbook.com>
 */
public class Util {
    /** Relative path to resolve the XmlRpc endpoint URL */
    private static final String XML_RPC_URL_PATH = "rpc/xmlrpc";

    /** Relative path to resolve the SOAP endpoint URL */
    private static final String SOAP_URL_PATH = "rpc/soap-axis/confluenceservice-v1";

    /**
     * Convert a generic Confluence URL into the XmlRpc endpoint URL
     * 
     * @param url
     * @return
     * @see #XML_RPC_URL_PATH
     */
    public static String confluenceUrlToXmlRpcUrl(String url) {
        URI uri = URI.create(url);
        return uri.resolve(XML_RPC_URL_PATH).normalize().toString();
    }

    /**
     * Convert a generic Confluence URL into the SOAP endpoint URL
     * 
     * @param url
     * @return
     * @see #SOAP_URL_PATH
     */
    public static String confluenceUrlToSoapUrl(String url) {
        URI uri = URI.create(url);
        return uri.resolve(SOAP_URL_PATH).normalize().toString();
    }
}

Fix bug with GH-1 for root-installations.
Fix bug with GH-1 for root-installations.

The change made in dd0ecf4 fixed the URLs for Confluence
installations in non-root paths (e.g., http://foo.example.com/confluence/*),
but that broke root installations, because URI#resolve()
interprets "//foo/bar" to mean that the host should become "foo".

Instead of using getPath(), and appending a /-anchored
RPC path, just pass a relative path to URI#resolve().
This should solve both problems.
