Search in sources :

Example 1 with XmlRpcNotAuthorizedException

use of org.apache.xmlrpc.common.XmlRpcNotAuthorizedException in project processdash by dtuma.

the class BoundXmlRpcConnection method openConnectionImpl.

protected XmlRpcClient openConnectionImpl(boolean printException) throws ErrorDataValueException {
    String username = null;
    String password = null;
    try {
        // look up the information needed to make the connection
        String baseUrl = this.baseUrl.getValue();
        String urlSuffix = this.urlSuffix.getValue();
        username = getUsername(this.username.getValue());
        password = getPassword(this.password.getValue());
        URL url = new URL(baseUrl.trim());
        if (StringUtils.hasValue(urlSuffix))
            url = new URL(url, urlSuffix);
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(url);
        config.setEnabledForExtensions(true);
        if (username != null && password != null) {
            config.setBasicUserName(username);
            config.setBasicPassword(password);
        }
        XmlRpcClient connection = new XmlRpcClient();
        connection.setConfig(config);
        if (StringUtils.hasValue(testMethodName))
            connection.execute(testMethodName, Collections.EMPTY_LIST);
        if (!validateCredentials(connection, username, password))
            throw new ErrorDataValueException(BAD_USERNAME_PASS, ErrorData.SEVERE);
        setError(null, ErrorData.NO_ERROR);
        return connection;
    } catch (MalformedURLException mue) {
        throw new ErrorDataValueException(INVALID_URL, ErrorData.SEVERE);
    } catch (XmlRpcNotAuthorizedException nae) {
        throw getBadCredentialsException(username, password);
    } catch (ErrorDataValueException edve) {
        throw edve;
    } catch (Exception e) {
        // we were unable to open a connection; return null.
        if (printException)
            e.printStackTrace();
        return null;
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) XmlRpcNotAuthorizedException(org.apache.xmlrpc.common.XmlRpcNotAuthorizedException) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) XmlRpcClientConfigImpl(org.apache.xmlrpc.client.XmlRpcClientConfigImpl) URL(java.net.URL) XmlRpcException(org.apache.xmlrpc.XmlRpcException) MalformedURLException(java.net.MalformedURLException) XmlRpcNotAuthorizedException(org.apache.xmlrpc.common.XmlRpcNotAuthorizedException)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 XmlRpcClient (org.apache.xmlrpc.client.XmlRpcClient)1 XmlRpcClientConfigImpl (org.apache.xmlrpc.client.XmlRpcClientConfigImpl)1 XmlRpcNotAuthorizedException (org.apache.xmlrpc.common.XmlRpcNotAuthorizedException)1