Search in sources :

Example 1 with CommandFormatException

use of org.jboss.as.cli.CommandFormatException in project wildfly by wildfly.

the class CreateJMSResourceHandler method buildRequestWithoutHeaders.

@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws OperationFormatException {
    try {
        if (!ctx.getParsedCommandLine().hasProperties()) {
            throw new OperationFormatException("Arguments are missing");
        }
    } catch (CommandFormatException e) {
        throw new OperationFormatException(e.getLocalizedMessage());
    }
    // String target = null;
    String restype = null;
    // String description = null;
    String propsStr = null;
    // boolean enabled = false;
    String jndiName = null;
    String[] args = ctx.getArgumentsString().split("\\s+");
    int i = 0;
    while (i < args.length) {
        String arg = args[i++];
        if (arg.equals("--restype")) {
            if (i < args.length) {
                restype = args[i++];
            }
        } else if (arg.equals("--target")) {
        // if(i < args.length) {
        // target = args[i++];
        // }
        } else if (arg.equals("--description")) {
        // if(i < args.length) {
        // restype = args[i++];
        // }
        } else if (arg.equals("--property")) {
            if (i < args.length) {
                propsStr = args[i++];
            }
        } else if (arg.equals("--enabled")) {
        // if (i < args.length) {
        // enabled = Boolean.parseBoolean(args[i++]);
        // }
        } else {
            jndiName = arg;
        }
    }
    if (restype == null) {
        throw new OperationFormatException("Required parameter --restype is missing.");
    }
    if (jndiName == null) {
        throw new OperationFormatException("JNDI name is missing.");
    }
    String name = null;
    // TODO read server name from props
    String serverName = "default";
    final Map<String, String> props;
    if (propsStr != null) {
        props = new HashMap<String, String>();
        String[] propsArr = propsStr.split(":");
        for (String prop : propsArr) {
            int equalsIndex = prop.indexOf('=');
            if (equalsIndex < 0 || equalsIndex == prop.length() - 1) {
                throw new OperationFormatException("Failed to parse property '" + prop + "'");
            }
            String propName = prop.substring(0, equalsIndex).trim();
            String propValue = prop.substring(equalsIndex + 1).trim();
            if (propName.isEmpty()) {
                throw new OperationFormatException("Failed to parse property '" + prop + "'");
            }
            if (propName.equals("imqDestinationName") || propName.equalsIgnoreCase("name")) {
                name = propValue;
            } else if ("ClientId".equals(propName)) {
                props.put("client-id", propValue);
            }
        }
    } else {
        props = Collections.emptyMap();
    }
    if (name == null) {
        name = jndiName.replace('/', '_');
    }
    if (restype.equals("javax.jms.Queue")) {
        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
        builder.addNode("subsystem", "messaging-activemq");
        builder.addNode("server", serverName);
        builder.addNode("jms-queue", name);
        builder.setOperationName("add");
        builder.getModelNode().get("entries").add(jndiName);
        for (String prop : props.keySet()) {
            builder.addProperty(prop, props.get(prop));
        }
        return builder.buildRequest();
    } else if (restype.equals("javax.jms.Topic")) {
        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
        builder.addNode("subsystem", "messaging-activemq");
        builder.addNode("server", serverName);
        builder.addNode("jms-topic", name);
        builder.setOperationName("add");
        builder.getModelNode().get("entries").add(jndiName);
        for (String prop : props.keySet()) {
            builder.addProperty(prop, props.get(prop));
        }
        return builder.buildRequest();
    } else if (restype.equals("javax.jms.ConnectionFactory") || restype.equals("javax.jms.TopicConnectionFactory") || restype.equals("javax.jms.QueueConnectionFactory")) {
        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
        builder.addNode("subsystem", "messaging-activemq");
        builder.addNode("server", serverName);
        builder.addNode("connection-factory", name);
        builder.setOperationName("add");
        builder.getModelNode().get("entries").add(jndiName);
        for (String prop : props.keySet()) {
            builder.addProperty(prop, props.get(prop));
        }
        return builder.buildRequest();
    } else {
        throw new OperationFormatException("Resource type " + restype + " isn't supported.");
    }
}
Also used : OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) CommandFormatException(org.jboss.as.cli.CommandFormatException) DefaultOperationRequestBuilder(org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder)

Example 2 with CommandFormatException

use of org.jboss.as.cli.CommandFormatException in project wildfly by wildfly.

the class CreateJMSResourceHandler method buildRequestWithoutHeaders.

@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws OperationFormatException {
    try {
        if (!ctx.getParsedCommandLine().hasProperties()) {
            throw new OperationFormatException("Arguments are missing");
        }
    } catch (CommandFormatException e) {
        throw new OperationFormatException(e.getLocalizedMessage());
    }
    // String target = null;
    String restype = null;
    // String description = null;
    String propsStr = null;
    // boolean enabled = false;
    String jndiName = null;
    String[] args = ctx.getArgumentsString().split("\\s+");
    int i = 0;
    while (i < args.length) {
        String arg = args[i++];
        if (arg.equals("--restype")) {
            if (i < args.length) {
                restype = args[i++];
            }
        } else if (arg.equals("--target")) {
        // if(i < args.length) {
        // target = args[i++];
        // }
        } else if (arg.equals("--description")) {
        // if(i < args.length) {
        // restype = args[i++];
        // }
        } else if (arg.equals("--property")) {
            if (i < args.length) {
                propsStr = args[i++];
            }
        } else if (arg.equals("--enabled")) {
        // if (i < args.length) {
        // enabled = Boolean.parseBoolean(args[i++]);
        // }
        } else {
            jndiName = arg;
        }
    }
    if (restype == null) {
        throw new OperationFormatException("Required parameter --restype is missing.");
    }
    if (jndiName == null) {
        throw new OperationFormatException("JNDI name is missing.");
    }
    String name = null;
    // TODO read server name from props
    String serverName = "default";
    final Map<String, String> props;
    if (propsStr != null) {
        props = new HashMap<String, String>();
        String[] propsArr = propsStr.split(":");
        for (String prop : propsArr) {
            int equalsIndex = prop.indexOf('=');
            if (equalsIndex < 0 || equalsIndex == prop.length() - 1) {
                throw new OperationFormatException("Failed to parse property '" + prop + "'");
            }
            String propName = prop.substring(0, equalsIndex).trim();
            String propValue = prop.substring(equalsIndex + 1).trim();
            if (propName.isEmpty()) {
                throw new OperationFormatException("Failed to parse property '" + prop + "'");
            }
            if (propName.equals("imqDestinationName") || propName.equalsIgnoreCase("name")) {
                name = propValue;
            } else if ("ClientId".equals(propName)) {
                props.put("client-id", propValue);
            }
        }
    } else {
        props = Collections.emptyMap();
    }
    if (name == null) {
        name = jndiName.replace('/', '_');
    }
    if (restype.equals("javax.jms.Queue")) {
        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
        builder.addNode("subsystem", "messaging");
        builder.addNode("hornetq-server", serverName);
        builder.addNode("jms-queue", name);
        builder.setOperationName("add");
        builder.getModelNode().get("entries").add(jndiName);
        for (String prop : props.keySet()) {
            builder.addProperty(prop, props.get(prop));
        }
        return builder.buildRequest();
    } else if (restype.equals("javax.jms.Topic")) {
        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
        builder.addNode("subsystem", "messaging");
        builder.addNode("hornetq-server", serverName);
        builder.addNode("jms-topic", name);
        builder.setOperationName("add");
        builder.getModelNode().get("entries").add(jndiName);
        for (String prop : props.keySet()) {
            builder.addProperty(prop, props.get(prop));
        }
        return builder.buildRequest();
    } else if (restype.equals("javax.jms.ConnectionFactory") || restype.equals("javax.jms.TopicConnectionFactory") || restype.equals("javax.jms.QueueConnectionFactory")) {
        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
        builder.addNode("subsystem", "messaging");
        builder.addNode("hornetq-server", serverName);
        builder.addNode("connection-factory", name);
        builder.setOperationName("add");
        builder.getModelNode().get("entries").add(jndiName);
        for (String prop : props.keySet()) {
            builder.addProperty(prop, props.get(prop));
        }
        return builder.buildRequest();
    } else {
        throw new OperationFormatException("Resource type " + restype + " isn't supported.");
    }
}
Also used : OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) CommandFormatException(org.jboss.as.cli.CommandFormatException) DefaultOperationRequestBuilder(org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder)

Example 3 with CommandFormatException

use of org.jboss.as.cli.CommandFormatException in project wildfly by wildfly.

the class DeleteJMSResourceHandler method buildRequestWithoutHeaders.

@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws OperationFormatException {
    try {
        if (!ctx.getParsedCommandLine().hasProperties()) {
            throw new OperationFormatException("Arguments are missing");
        }
    } catch (CommandFormatException e) {
        throw new OperationFormatException(e.getLocalizedMessage());
    }
    // String target = null;
    String jndiName = null;
    // TODO read server name from props
    String serverName = "default";
    String[] args = ctx.getArgumentsString().split("\\s+");
    int i = 0;
    while (i < args.length) {
        String arg = args[i++];
        if (arg.equals("--target")) {
        // if(i < args.length) {
        // target = args[i++];
        // }
        } else {
            jndiName = arg;
        }
    }
    if (jndiName == null) {
        throw new OperationFormatException("name is missing.");
    }
    ModelControllerClient client = ctx.getModelControllerClient();
    final String resource;
    if (Util.isTopic(client, jndiName)) {
        resource = "jms-topic";
    } else if (Util.isQueue(client, jndiName)) {
        resource = "jms-queue";
    } else if (Util.isConnectionFactory(client, jndiName)) {
        resource = "connection-factory";
    } else {
        throw new OperationFormatException("'" + jndiName + "' wasn't found among existing JMS resources.");
    }
    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
    builder.addNode("subsystem", "messaging");
    builder.addNode("hornetq-server", serverName);
    builder.addNode(resource, jndiName);
    builder.setOperationName("remove");
    return builder.buildRequest();
}
Also used : OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) CommandFormatException(org.jboss.as.cli.CommandFormatException) DefaultOperationRequestBuilder(org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder)

Example 4 with CommandFormatException

use of org.jboss.as.cli.CommandFormatException 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)

Example 5 with CommandFormatException

use of org.jboss.as.cli.CommandFormatException in project wildfly by wildfly.

the class DeleteJMSResourceHandler method buildRequestWithoutHeaders.

@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws OperationFormatException {
    try {
        if (!ctx.getParsedCommandLine().hasProperties()) {
            throw new OperationFormatException("Arguments are missing");
        }
    } catch (CommandFormatException e) {
        throw new OperationFormatException(e.getLocalizedMessage());
    }
    // String target = null;
    String jndiName = null;
    // TODO read server name from props
    String serverName = "default";
    String[] args = ctx.getArgumentsString().split("\\s+");
    int i = 0;
    while (i < args.length) {
        String arg = args[i++];
        if (arg.equals("--target")) {
        // if(i < args.length) {
        // target = args[i++];
        // }
        } else {
            jndiName = arg;
        }
    }
    if (jndiName == null) {
        throw new OperationFormatException("name is missing.");
    }
    ModelControllerClient client = ctx.getModelControllerClient();
    final String resource;
    if (Util.isTopic(client, jndiName)) {
        resource = "jms-topic";
    } else if (Util.isQueue(client, jndiName)) {
        resource = "jms-queue";
    } else if (Util.isConnectionFactory(client, jndiName)) {
        resource = "connection-factory";
    } else {
        throw new OperationFormatException("'" + jndiName + "' wasn't found among existing JMS resources.");
    }
    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
    builder.addNode("subsystem", "messaging");
    builder.addNode("server", serverName);
    builder.addNode(resource, jndiName);
    builder.setOperationName("remove");
    return builder.buildRequest();
}
Also used : OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) CommandFormatException(org.jboss.as.cli.CommandFormatException) DefaultOperationRequestBuilder(org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder)

Aggregations

CommandFormatException (org.jboss.as.cli.CommandFormatException)5 OperationFormatException (org.jboss.as.cli.operation.OperationFormatException)4 DefaultOperationRequestBuilder (org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder)4 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)2 OperationRequestAddress (org.jboss.as.cli.operation.OperationRequestAddress)1 DefaultCallbackHandler (org.jboss.as.cli.operation.impl.DefaultCallbackHandler)1 DefaultOperationRequestAddress (org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress)1 Test (org.junit.Test)1