Search in sources :

Example 1 with DefaultOperationRequestAddress

use of org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress in project teiid by teiid.

the class AdminFactory method createAdmin.

/**
 * Creates a ServerAdmin with the specified connection properties.
 * @param userName
 * @param password
 * @param serverURL
 * @param applicationName
 * @return
 * @throws AdminException
 */
public Admin createAdmin(String host, int port, String userName, char[] password) throws AdminException {
    if (host == null) {
        // $NON-NLS-1$
        host = "localhost";
    }
    if (port < 0) {
        port = 9990;
    }
    try {
        CallbackHandler cbh = new AuthenticationCallbackHandler(userName, password);
        ModelControllerClient newClient = ModelControllerClient.Factory.create(host, port, cbh);
        List<String> nodeTypes = Util.getNodeTypes(newClient, new DefaultOperationRequestAddress());
        if (!nodeTypes.isEmpty()) {
            // $NON-NLS-1$
            boolean domainMode = nodeTypes.contains("server-group");
            LOGGER.info(// $NON-NLS-1$
            "Connected to " + // $NON-NLS-1$ //$NON-NLS-2$
            (domainMode ? "domain controller at " : "standalone controller at ") + host + ":" + // $NON-NLS-1$
            port);
            return new AdminImpl(newClient);
        }
        LOGGER.info(AdminPlugin.Util.gs(AdminPlugin.Event.TEIID70051, host, port));
    } catch (UnknownHostException e) {
        throw new AdminProcessingException(AdminPlugin.Event.TEIID70000, AdminPlugin.Util.gs(AdminPlugin.Event.TEIID70000, host, e.getLocalizedMessage()));
    }
    return null;
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) UnknownHostException(java.net.UnknownHostException) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress)

Example 2 with DefaultOperationRequestAddress

use of org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress in project eap-additional-testsuite by jboss-set.

the class AddressOnlyParsingTestCase method testRootCharInTheMiddle.

@Test
public void testRootCharInTheMiddle() throws Exception {
    OperationRequestAddress prefix = new DefaultOperationRequestAddress();
    prefix.toNode("a", "b");
    DefaultCallbackHandler handler = new DefaultCallbackHandler(prefix);
    parser.parse("/", handler);
    assertTrue(handler.hasAddress());
    assertFalse(handler.hasOperationName());
    assertFalse(handler.hasProperties());
    assertFalse(handler.endsOnAddressOperationNameSeparator());
    assertFalse(handler.endsOnPropertyListStart());
    assertFalse(handler.endsOnPropertySeparator());
    assertFalse(handler.endsOnPropertyValueSeparator());
    assertTrue(handler.endsOnNodeSeparator());
    assertFalse(handler.endsOnNodeTypeNameSeparator());
    assertFalse(handler.isRequestComplete());
    OperationRequestAddress address = handler.getAddress();
    address.isEmpty();
    try {
        handler.reset();
        parser.parse("//", handler);
        Assert.fail("Shouldn't allow root character in the middle of the path");
    } catch (CommandFormatException e) {
    // expected
    }
    try {
        handler.reset();
        parser.parse("./a/", handler);
        Assert.fail("Shouldn't allow root character in the middle of the path");
    } catch (CommandFormatException e) {
    // expected
    }
    handler.reset();
    parser.parse("./a=b/", handler);
    try {
        handler.reset();
        parser.parse("./a=b//", handler);
        Assert.fail("Shouldn't allow root character in the middle of the path");
    } catch (CommandFormatException e) {
    // expected
    }
    try {
        handler.reset();
        parser.parse("./a=b//a=b", handler);
        Assert.fail("Shouldn't allow root character in the middle of the path");
    } catch (CommandFormatException e) {
    // expected
    }
}
Also used : DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) CommandFormatException(org.jboss.as.cli.CommandFormatException) DefaultCallbackHandler(org.jboss.as.cli.operation.impl.DefaultCallbackHandler) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress) Test(org.junit.Test)

Aggregations

DefaultOperationRequestAddress (org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress)2 UnknownHostException (java.net.UnknownHostException)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 CommandFormatException (org.jboss.as.cli.CommandFormatException)1 OperationRequestAddress (org.jboss.as.cli.operation.OperationRequestAddress)1 DefaultCallbackHandler (org.jboss.as.cli.operation.impl.DefaultCallbackHandler)1 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)1 Test (org.junit.Test)1