Search in sources :

Example 1 with RestHttpOperationInvoker

use of org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker in project geode by apache.

the class QueryNamesOverHttpDUnitTest method testQueryNameOverHttp.

@Test
public void testQueryNameOverHttp() throws Exception {
    LinkIndex links = new LinkIndex();
    links.add(new Link("mbean-query", new URI("http://localhost:" + locatorRule.getHttpPort() + "/gemfire/v1/mbean/query"), HttpMethod.POST));
    RestHttpOperationInvoker invoker = new RestHttpOperationInvoker(links, mock(Gfsh.class), new HashMap<>());
    ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,*");
    QueryExp query = Query.eq(Query.attr("Name"), Query.value("mock"));
    Set<ObjectName> names = invoker.queryNames(objectName, query);
    assertTrue(names.isEmpty());
}
Also used : LinkIndex(org.apache.geode.management.internal.web.domain.LinkIndex) RestHttpOperationInvoker(org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) QueryExp(javax.management.QueryExp) URI(java.net.URI) Link(org.apache.geode.management.internal.web.domain.Link) ObjectName(javax.management.ObjectName) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with RestHttpOperationInvoker

use of org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker in project geode by apache.

the class ShellCommands method httpConnect.

private Result httpConnect(Map<String, String> sslConfigProps, boolean useSsl, String url, String userName, String passwordToUse) {
    Gfsh gfsh = getGfsh();
    try {
        Map<String, String> securityProperties = new HashMap<String, String>();
        // at this point, if userName is not empty, password should not be empty either
        if (userName != null && userName.length() > 0) {
            securityProperties.put("security-username", userName);
            securityProperties.put("security-password", passwordToUse);
        }
        if (useSsl) {
            configureHttpsURLConnection(sslConfigProps);
            if (url.startsWith("http:")) {
                url = url.replace("http:", "https:");
            }
        }
        Iterator<String> it = sslConfigProps.keySet().iterator();
        while (it.hasNext()) {
            String secKey = it.next();
            securityProperties.put(secKey, sslConfigProps.get(secKey));
        }
        // This is so that SSL termination results in https URLs being returned
        String query = (url.startsWith("https")) ? "?scheme=https" : "";
        LogWrapper.getInstance().warning(String.format("Sending HTTP request for Link Index at (%1$s)...", url.concat("/index").concat(query)));
        LinkIndex linkIndex = new SimpleHttpRequester(gfsh, CONNECT_LOCATOR_TIMEOUT_MS, securityProperties).exchange(url.concat("/index").concat(query), LinkIndex.class);
        LogWrapper.getInstance().warning(String.format("Received Link Index (%1$s)", linkIndex.toString()));
        HttpOperationInvoker operationInvoker = new RestHttpOperationInvoker(linkIndex, gfsh, url, securityProperties);
        Initializer.init(operationInvoker);
        gfsh.setOperationInvoker(operationInvoker);
        LogWrapper.getInstance().info(CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS, operationInvoker.toString()));
        return ResultBuilder.createInfoResult(CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS, operationInvoker.toString()));
    } catch (Exception e) {
        // all other exceptions, just logs it and returns a connection error
        if (!(e instanceof SecurityException) && !(e instanceof AuthenticationFailedException)) {
            return handleExcpetion(e, null);
        }
        // connection error
        if (userName != null) {
            return handleExcpetion(e, null);
        }
        // otherwise, prompt for username and password and retry the conenction
        try {
            userName = gfsh.readText(CliStrings.CONNECT__USERNAME + ": ");
            passwordToUse = gfsh.readPassword(CliStrings.CONNECT__PASSWORD + ": ");
            return httpConnect(sslConfigProps, useSsl, url, userName, passwordToUse);
        } catch (IOException ioe) {
            return handleExcpetion(ioe, null);
        }
    } finally {
        Gfsh.redirectInternalJavaLoggers();
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) IOException(java.io.IOException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) LinkIndex(org.apache.geode.management.internal.web.domain.LinkIndex) RestHttpOperationInvoker(org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker) HttpOperationInvoker(org.apache.geode.management.internal.web.shell.HttpOperationInvoker) RestHttpOperationInvoker(org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker) SimpleHttpRequester(org.apache.geode.management.internal.web.http.support.SimpleHttpRequester) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh)

Aggregations

Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)2 LinkIndex (org.apache.geode.management.internal.web.domain.LinkIndex)2 RestHttpOperationInvoker (org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ObjectName (javax.management.ObjectName)1 QueryExp (javax.management.QueryExp)1 Link (org.apache.geode.management.internal.web.domain.Link)1 SimpleHttpRequester (org.apache.geode.management.internal.web.http.support.SimpleHttpRequester)1 HttpOperationInvoker (org.apache.geode.management.internal.web.shell.HttpOperationInvoker)1 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 Test (org.junit.Test)1