Skip to content

Commit

Permalink
- made some minor modifications to show how to connect to a secured m…
Browse files Browse the repository at this point in the history
…gmt port

-  created an example for a xa-datasource and howto create xa-datasource-properties elements.
  • Loading branch information
juhoffma committed Feb 16, 2012
1 parent 179ab38 commit 03f083a
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 12 deletions.
12 changes: 6 additions & 6 deletions mgmt-create-ds/pom.xml
Expand Up @@ -46,10 +46,10 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
<version>7.1.0.Beta1b</version>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
<version>7.1.0.Beta1b</version>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
Expand All @@ -61,7 +61,7 @@
<build>
<!-- Set the name of the war, used as the context root when the app is
deployed -->
<finalName>mgmt-server-status</finalName>
<finalName>mgmt-server-create-ds/finalName>
<plugins>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation
processors -->
Expand Down Expand Up @@ -91,4 +91,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Expand Up @@ -18,8 +18,10 @@ public class Client
{
public static void main(String[] args) throws Exception
{
//ModelControllerClient client = ModelControllerClient.Factory.create(
// InetAddress.getByName("127.0.0.1"), 9999, DemoAuthentication.getCallbackHandler());
ModelControllerClient client = ModelControllerClient.Factory.create(
InetAddress.getByName("10.32.69.24"), 9999, DemoAuthentication.getCallbackHandler());
InetAddress.getByName("127.0.0.1"), 9999);
try
{
String dsname = "REPLACE_WITH_PROPERTY";
Expand All @@ -29,10 +31,10 @@ public static void main(String[] args) throws Exception
op.get("address").add("subsystem", "datasources").add("data-source", dsname);

op.get("jndi-name").set("java:jboss/datasources/" + dsname);
//op.get("driver-name").set("mysql");
op.get("driver-name").set("postgresql-8.4-703.jdbc4.jar");
op.get("driver-name").set("mysql");
//op.get("driver-name").set("postgresql-8.4-703.jdbc4.jar");
op.get("pool-name").set("TestDS");
op.get("connection-url").set("jdbc:postgresql://localhost/test");
op.get("connection-url").set("jdbc:mysql://localhost/demo");
op.get("max-pool-size").set(10);
op.get("min-pool-size").set(5);

Expand Down Expand Up @@ -68,6 +70,26 @@ public static void main(String[] args) throws Exception
op = new ModelNode();
op.get("operation").set("enable");
op.get("address").add("subsystem", "datasources").add("data-source", dsname);
result = client.execute(
new ModelNode()
.get("operation").set("enable")
.get("address")
.add("subsystem", "datasources")
.add("data-source", dsname)
);

op = new ModelNode();
op.get("operation").set("write-attribute");
op.get("address").add("subsystem", "datasources").add("data-source", dsname);
op.get("name").set("max-pool-size");
op.get("value").set("20");
result = client.execute(op);

op = new ModelNode();
op.get("operation").set("write-attribute");
op.get("address").add("subsystem", "datasources").add("data-source", dsname);
op.get("name").set("min-pool-size");
op.get("value").set("10");
result = client.execute(op);


Expand Down
Expand Up @@ -29,8 +29,8 @@ public class DemoAuthentication {
// for this reason we cache the entered values to allow for re-use without pestering the end
// user.
private boolean promptShown = false;
private String userName = null;
private char[] password = null;
private String userName = "user1";
private char[] password = "pwd1".toCharArray();

private DemoAuthentication() {
}
Expand Down
96 changes: 96 additions & 0 deletions mgmt-create-xa-ds/pom.xml
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.jboss.as.quickstarts</groupId>
<artifactId>mgmt-create-xa-ds</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>JBoss AS Quickstarts: Create a XA Datasource through the Mgmt API</name>

<url>http://jboss.org/jbossas</url>
<licenses>
<license>
<name>GNU Lesser General Public License</name>
<url>http://www.gnu.org/copyleft/lesser.html</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
<dependencies>
<!-- Define the version of JBoss' Java EE 6 APIs we want to use -->
<!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
of artifacts. We use this here so that we always get the correct versions
of artifacts. Here we use the jboss-javaee-6.0 stack (you can read this as
the JBoss stack of the Java EE 6 APIs). You can actually use this stack with
any version of JBoss AS that implements Java EE 6, not just JBoss AS 7! -->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.0.Beta1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
<version>7.1.0.Beta1b</version>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller</artifactId>
<version>7.1.0.Beta1b</version>
</dependency>
</dependencies>

<build>
<!-- Set the name of the war, used as the context root when the app is
deployed -->
<finalName>mgmt-create-xa-ds</finalName>
<plugins>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation
processors -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.jboss.as.quickstarts.mgmt.Client</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
@@ -0,0 +1,75 @@
package org.jboss.as.quickstarts.mgmt;

import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.dmr.ModelNode;

import java.net.InetAddress;

/**
* Red Hat GmbH - Global Professional Services (GPS)
* <p/>
* Author: <a href="mailto:jhoffmann@redhat.com">Juergen Hoffmann</a>
* Date: 13.02.12
* Time: 09:51
*/
public class Client
{
public static void main(String[] args) throws Exception
{
ModelControllerClient client = ModelControllerClient.Factory.create(
InetAddress.getByName("127.0.0.1"), 9999);

try{
String dsname = "REPLACE_WITH_PROPERTY";
ModelNode op = new ModelNode();
op.get("operation").set("add");

op.get("address").add("subsystem", "datasources").add("xa-data-source", dsname);

op.get("jndi-name").set("java:jboss/datasources/" + "XA" + dsname);
op.get("xa-datasource-class").set("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
op.get("driver-name").set("mysql");
op.get("use-java-context").set("true");
op.get("pool-name").set("TestXADS");
op.get("xa-resource-timeout").set(3600);
op.get("jta").set(true);

op.get("max-pool-size").set(10);
op.get("min-pool-size").set(5);

ModelNode result = client.execute(op);

System.out.println(result.toString());

op = new ModelNode();
op.get("operation").set("add");
op.get("address").add("subsystem","datasources").add("xa-data-source", dsname).add("xa-datasource-properties", "URL");
op.get("value").set("jdbc:mysql://localhost/demo");

result = client.execute(op);

System.out.println(result.toString());

op = new ModelNode();
op.get("operation").set("add");
op.get("address").add("subsystem","datasources").add("xa-data-source", dsname).add("xa-datasource-properties", "User");
op.get("value").set("demo");

result = client.execute(op);

System.out.println(result.toString());

op = new ModelNode();
op.get("operation").set("add");
op.get("address").add("subsystem","datasources").add("xa-data-source", dsname).add("xa-datasource-properties", "Password");
op.get("value").set("demo");

result = client.execute(op);

System.out.println(result.toString());
}
finally {
client.close();
}
}
}

0 comments on commit 03f083a

Please sign in to comment.