JBoss Trading – Java EE 5 to Java EE 6 Migration Part IV (Deployment & Testing)

This post is the fourth in a series that covers the Java EE 5 to Java EE 6 migration of the JBoss Trading application (link).

This post covers source code / configuration modifications required for deployment and the EJB /REST / WS clients and integration tests.


Deployment

The Cargo Maven plugin is replaced with the new JBoss AS (7) Maven plugin.

JBoss Trading Client Test Perf

  1. Remove the Cargo Maven plugin. (localhost-remote)
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
  2. Add the JBoss AS (7) Maven plugin. (localhost-remote)
    <plugin>
        <groupId>org.jboss.as.plugins</groupId>
        <artifactId>jboss-as-maven-plugin</artifactId>
        <version>7.1.1.Final</version>
        <configuration>
            <username>admin</username>
            <password>password</password>
            <targetDir>${project.build.directory}/dependency/</targetDir>
            <filename>trading-app.ear</filename>
        </configuration>
        <executions>
            <execution>
                <id>pre-integration-test</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>deploy</goal>
                </goals>
            </execution>
            <execution>
                <id>post-integration-test</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>undeploy</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

JBoss Trading EJB Client

  1. Remove the JBoss Trading App dependency. (localhost-remote)
    <dependency>
        <groupId>com.jboss.trading</groupId>
        <artifactId>trading-app</artifactId>
        <version>${project.version}</version>
        <scope>provided</scope>
        <type>ear</type>
    </dependency>
  2. Remove the Cargo Maven plugin. (localhost-remote)
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
  3. Add the JBoss AS 7 Maven plugin. (localhost-remote)
    <plugin>
        <groupId>org.jboss.as.plugins</groupId>
        <artifactId>jboss-as-maven-plugin</artifactId>
        <version>7.1.1.Final</version>
        <configuration>
            <username>admin</username>
            <password>password</password>
            <targetDir>${project.build.directory}/dependency/</targetDir>
            <filename>trading-app.ear</filename>
        </configuration>
        <executions>
            <execution>
                <id>pre-integration-test</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>deploy</goal>
                </goals>
            </execution>
            <execution>
                <id>post-integration-test</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>undeploy</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

JBoss Trading REST

  1. Remove the Cargo Maven plugin. (localhost-remote)
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
  2. Add the JBoss AS 7 Maven plugin. (localhost-remote)
    <plugin>
        <groupId>org.jboss.as.plugins</groupId>
        <artifactId>jboss-as-maven-plugin</artifactId>
        <version>7.1.1.Final</version>
        <configuration>
            <username>admin</username>
            <password>password</password>
            <targetDir>${project.build.directory}/dependency/</targetDir>
            <filename>trading-app.ear</filename>
        </configuration>
        <executions>
            <execution>
                <id>pre-integration-test</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>deploy</goal>
                </goals>
            </execution>
            <execution>
                <id>post-integration-test</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>undeploy</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

JBoss Trading WS Client

  1. Remove the JBoss Trading App dependency. (localhost-remote)
    <dependency>
        <groupId>com.jboss.trading</groupId>
        <artifactId>trading-app</artifactId>
        <version>${project.version}</version>
        <scope>provided</scope>
        <type>ear</type>
    </dependency>
  2. Remove the Cargo Maven plugin. (localhost-remote)
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
  3. Add the JBoss AS 7 Maven plugin. (localhost-remote)
    <plugin>
        <groupId>org.jboss.as.plugins</groupId>
        <artifactId>jboss-as-maven-plugin</artifactId>
        <version>7.1.1.Final</version>
        <configuration>
            <username>admin</username>
            <password>password</password>
            <targetDir>${project.build.directory}/dependency/</targetDir>
            <filename>trading-app.ear</filename>
        </configuration>
        <executions>
            <execution>
                <id>pre-integration-test</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>deploy</goal>
                </goals>
            </execution>
            <execution>
                lt;id>post-integration-test</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>undeploy</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

Arquillian

The Aquillian dependencies are replaced with the JBoss AS Arquillian dependency. The auth.conf and jndi.properties files are no longer necessary with JBoss EAP 6 + Arquillian. However, the arquillian.xml file is updated.

Notes:

If a named sequence generator is not configured for each entity, the same default sequence generator will be used for each one.

The Apache Commons Beanutils packages are no longer added to the archive as there is an Apache Commons Beanutils module. JBoss EAP 6 modules can be added to the application classpath using a jboss-deployment-structure.xml file.

If the Servlet 3.0 protocol is used, the trading-jms.xml is not scanned and the JMS queues are not deployed.

The JBoss EJB 3 Extensions API dependency is removed due to a conflict with Arquillian

JBoss Trading Parent

  1. pom.xml (update)
    <arquillian-core.version>1.0.0.Final</arquillian-core.version>

JBoss Trading Beans

  1. Remove the JBoss EJB 3 Extensions API dependency.
    <dependency>
        <groupId>org.jboss.ejb3</groupId>
        <artifactId>jboss-ejb3-ext-api</artifactId>
        <version>${jboss-ejb3-ext-api.version}</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <artifactId>ejb3-persistence</artifactId>
                <groupId>org.hibernate</groupId>
            </exclusion>
        </exclusions>
    </dependency>
  2. Remove the Arquillian dependencies. (localhost-remote)
    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-jbossas-remote-5.1</artifactId>
        <version>${arquillian-jbossas.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.jbossas</groupId>
        <artifactId>jboss-as-client</artifactId>
        <version>${jboss-as-client.version}</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.jboss.jbossas</groupId>
        <artifactId>jboss-as-profileservice-client</artifactId>
        <version>${jboss-as-profileservice-client.version}</version>
        <type>pom</type>
    </dependency>
  3. Add the JBoss AS Arquillian dependency. (localhost-remote)
    <dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-arquillian-container-remote</artifactId>
        <version>7.1.1.Final</version>
    </dependency>
  4. Add the SLF4J Simple dependency.
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>${slf4j.version}</version>
        <scope>test</scope>
    </dependency>
  5. auth.conf (delete)
  6. jndi.properties (delete)
  7. arquillian.xml (update)
    <?xml version="1.0" encoding="UTF-8"?>
    <arquillian xmlns="http://jboss.org/schema/arquillian" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xsi:schemaLocation="
                         http://jboss.org/schema/arquillian 
                         http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
    
        <container qualifier="jboss-eap6-remote" default="true"> 
            <configuration> 
                <property name="managementAddress">localhost</property> 
                <property name="managementPort">9999</property> 
            </configuration> 
        </container>
    </arquillian>
  8. META-INF/jboss-deployment-structure.xml (create)
    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
        <deployment>
            <dependencies>
                <module name="org.apache.commons.beanutils" />
            </dependencies>
        </deployment>
    </jboss-deployment-structure>
  9. LimitOrderProcessorBean.java (update)
    import org.jboss.ejb3.annotation.Depends; 
    
    @Depends("jboss.messaging.destination:service=Queue,name=jbossTradingLimitOrders")
  10. LimitOrderEntity.java (update)
    @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, 
            generator = "sequence_limit_orders") 
    @SequenceGenerator(name = "sequence_limit_orders", 
            sequenceName = "sequence_limit_orders") 
    private Integer id;
  11. MarketOrderEntity.java (update)
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, 
            generator = "sequence_market_orders") 
    @SequenceGenerator(name = "sequence_market_orders", 
            sequenceName = "sequence_market_orders") 
    private Integer id;
  12. TradeManagerLocalIT.java (update)
    import javax.ejb.EJB;
    import javax.inject.Inject;
    import javax.inject.Named;
    
    @Inject 
    @Named("TradeManagerBean") 
    @EJB 
    TradeManager tradeManager;
    
    @Deployment
    public static JavaArchive createTestArchive() {
    
       return ShrinkWrap.create(
             JavaArchive.class, "trading-services.jar")
             .addPackage("com.jboss.trading.api")
             .addPackage("com.jboss.trading.api.exception")
             .addPackage("com.jboss.trading.api.model")
             .addPackage("com.jboss.trading.services")
             .addPackage("com.jboss.trading.services.persistence")
             .addPackage("com.jboss.trading.services.persistence.factory")
             .addPackage("com.jboss.trading.services.util")
             .addPackage("com.jboss.trading.test")
             .addPackage("org.apache.commons.beanutils") 
             .addPackage("org.apache.commons.beanutils.converters") 
             .addPackage("org.apache.commons.beanutils.expression") 
             .addPackage("org.apache.commons.lang") 
             .addPackage("org.apache.commons.lang.builder") 
             .addAsResource("META-INF/beans.xml") 
             .addAsResource("META-INF/jboss-deployment-structure.xml") 
             .addAsResource("META-INF/persistence.xml") 
             .addAsResource("META-INF/trading-jms.xml") 
             .addAsResource("trading-queue-service.xml") 
             .addAsResource("import.sql")
             .addAsResource("test.properties");
    }

EJB Client

The JBoss AS Client dependency is replaced with the new JBoss AS EJB Client dependency. The JBoss Java EE 6 and JBoss AS EJB Client (bom) dependencies are added to simplify the management of the required dependencies. The client and configuration files are updated as the host and port configuration is now read by the JBoss AS EJB client directly from the jboss-ejb-client.properties file. In addition, several initial context properties are no longer necessary with the new JBoss AS EJB client.

JBoss Trading EJB Client

  1. Remove the JBoss AS Client dependency.
    <dependency>
        <groupId>org.jboss.jbossas</groupId>
        <artifactId>jboss-as-client</artifactId>
        <version>${jboss-as-client.version}</version>
        <type>pom</type>
        <exclusions>
            <!-- using slf4j-simple outside of jboss -->
            <exclusion>
                <groupId>org.jboss.slf4j</groupId>
                <artifactId>slf4j-jboss-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
  2. Add the JBoss Java EE 6 (bom) and JBoss AS EJB Client (bom) dependencies.
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-6.0</artifactId>
                <version>3.0.0.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>org.jboss.as</groupId>
                <artifactId>jboss-as-ejb-client-bom</artifactId>
                <version>7.1.1.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>
  3. Add the JBoss AS EJB Client dependencies.
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-ejb-client</artifactId>
        <scope>runtime</scope>
    </dependency> 
    <dependency>
        <groupId>org.jboss.marshalling</groupId>
        <artifactId>jboss-marshalling-river</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.sasl</groupId>
        <artifactId>jboss-sasl</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.xnio</groupId>
        <artifactId>xnio-nio</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.1_spec</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.transaction</groupId>
        <artifactId>jboss-transaction-api_1.1_spec</artifactId>
        <scope>runtime</scope>
    </dependency>
  4. TradeManagerClient.java (update)
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    
    private static final String PROP_INITIAL = 
            "java.naming.factory.initial"; 
    
    private static final String PROP_PKGS = 
            "java.naming.factory.url.pkgs"; 
    
    private static final String PROP_URL = 
            "java.naming.provider.url"; 
    
    private static final String PROP_INITIAL_VALUE = 
            "org.jnp.interfaces.NamingContextFactory"; 
    
    private static final String PROP_PKGS_VALUE = 
            "org.jboss.ejb.client.naming"; 
    
    private static final String PROP_URL_VALUE_PREFIX = 
            "jnp://"; 
    
    public static TradeManager getInstance(String jndiName) 
            throws NamingException {
    
        Properties properties = new Properties();
    
        properties.put(PROP_INITIAL, PROP_INITIAL_VALUE); 
        properties.put(Context.URL_PKG_PREFIXES, PROP_PKGS_VALUE); 
        properties.put(PROP_URL, PROP_URL_VALUE_PREFIX + hostPort); 
    
        InitialContext ctx = new InitialContext(properties);
    
        TradeManager tradeManagerRemote = 
                (TradeManager) ctx.lookup(jndiName);
    
        TradeManager tradeManager = 
                new TradeManagerClient(tradeManagerRemote);
    
        return tradeManager;
    }
  5. ClientTestConfig.java (update)
    package com.jboss.trading.rmi.client.test;
    
    import java.io.IOException;
    import java.util.Properties;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    public class ClientTestConfig {
    
        private static final Logger LOGGER = 
                LoggerFactory.getLogger(ClientTestConfig.class);
    
        private static final String PROPS_FILE_NAME = 
                "ejb-client-test.properties";
    
        private static final String PROPS_HOST_PORT = 
                "host.port";
    
        private static final String PROPS_JNDI_NAME = 
                "jndi.name";
    
        private String hostPort;
    
        private String jndiName;
    
        private ClientTestConfig() {
    
            Properties props = new Properties();
    
            try {
    
                props.load(ClientTestConfig.class
                        .getClassLoader()
                        .getResourceAsStream(PROPS_FILE_NAME));
    
                hostPort = props.getProperty(PROPS_HOST_PORT);
                jndiName = props.getProperty(PROPS_JNDI_NAME);
            } 
            catch (IOException ex) {
    
                LOGGER.error(ex.getMessage(), ex);
            }
        }
    
        public static ClientTestConfig getInstance() {
    
            return ClientTestConfig.EJBClientTestConfigHolder.INSTANCE;
        }
    
        public String getHostPort() { 
    
            return hostPort; 
        } 
    
        public String getJndiName() {
    
            return jndiName;
        }
    
        private static class EJBClientTestConfigHolder {
    
            public static final ClientTestConfig INSTANCE = 
                    new ClientTestConfig();
        }
    }
  6. TradeManagerClientIT.java (update)
    public TradeManagerClientIT() {
    
       testConfig = TestConfig.getInstance();
    
       clientTestConfig = ClientTestConfig.getInstance();
    
       String hostPort = clientTestConfig.getHostPort();
       String jndiName = clientTestConfig.getJndiName();
    
       try {
    
          tradeManager = TradeManagerClient.getInstance(jndiName);
       } 
       catch (NamingException ex) {
    
          LOGGER.error(ex.getMessage(), ex);
       }
    }

JBoss Trading EJB Client Test Config

The TradeManagerBean JNDI name is updated. The host.port property is no longer necessary as the host and port configuration is now read by the JBoss AS EJB client directly from the jboss-ejb-client.properties file. The username and password are configured in the jboss-ejb-client.properties file

Format:

ejb:<appName>/<moduleName>/<distinctName>/<beanName>!<viewClassName>

  1. pom.xml (update)
    <properties>
        <host>localhost</host> 
        <port>4447</port> 
        <host.port>localhost:1099</host.port> 
        <jndi.name>ejb:trading-app/trading-beans//TradeManagerBean!com.jboss.trading.services.TradeManagerRemote</jndi.name> 
    </properties>
  2. ejb-client-test.properties (update)
    host.port=${host.port}
    jndi.name=${jndi.name}
  3. jboss-ejb-client.properties (create)
    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
    
    remote.connections=default
    
    remote.connection.default.host=${host}
    remote.connection.default.port=${port}

REST Client

JBoss Trading Parent

  1. pom.xml (update)
    <resteasy.version>2.3.3.Final</resteasy.version>

JBoss Trading REST

The trading services are separated into a JAX-RS annotated interface and an implementation as RESTEasy requires a JAX-RS annotated interface to generate a client proxy.

  1. TradingServices.java (update)
    package com.jboss.trading.rest;
    
    import com.jboss.trading.api.exception.LimitOrderNotFoundException;
    import com.jboss.trading.api.exception.MarketOrderNotFoundException;
    import com.jboss.trading.api.exception.PlaceOrderException;
    import com.jboss.trading.api.model.LimitOrder;
    import com.jboss.trading.api.model.MarketOrder;
    import com.jboss.trading.api.model.TransactionType;
    import java.util.List;
    import javax.ws.rs.DELETE;
    import javax.ws.rs.FormParam;
    import javax.ws.rs.GET;
    import javax.ws.rs.POST;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;
    
    @Path("/services")
    public interface TradingServices {
    
        @DELETE
        @Path("/orders/limit/{limitOrderId}")
        @Produces("application/json")
        public void cancelLimitOrder(
                @PathParam("limitOrderId") Integer limitOrderId)
                throws LimitOrderNotFoundException;
    
        @DELETE
        @Path("/orders/market/{marketOrderId}")
        @Produces("application/json")
        public void cancelMarketOrder(
                @PathParam("marketOrderId") Integer marketOrderId)
                throws MarketOrderNotFoundException;
    
        @POST
        @Produces("application/json")
        @Path("/orders/limit")
        public void placeLimitOrder(
                @FormParam("stockHolderId") Integer stockHolderId,
                @FormParam("transactionType") TransactionType transactionType,
                @FormParam("quantity") Integer quantity,
                @FormParam("stockSymbol") String stockSymbol,
                @FormParam("price") Float price) 
                throws PlaceOrderException;
    
        @POST
        @Produces("application/json")
        @Path("/orders/market")
        public void placeMarketOrder(
                @FormParam("stockHolderId") Integer stockHolderId,
                @FormParam("transactionType") TransactionType transactionType,
                @FormParam("quantity") Integer quantity,
                @FormParam("stockSymbol") String stockSymbol);
    
        @GET
        @Path("/orders/limit/{limitOrderId}")
        @Produces("application/json")
        public LimitOrder viewLimitOrder(
                @PathParam("limitOrderId") Integer limitOrderId)
                throws LimitOrderNotFoundException;
    
        @GET
        @Path("/orders/market/{marketOrderId}")
        @Produces("application/json")
        public MarketOrder viewMarketOrder(
                @PathParam("marketOrderId") Integer marketOrderId)
                throws MarketOrderNotFoundException;
    
        @GET
        @Path("/stockholders/{stockHolderId}/orders/limit/last/{numberLimitOrders}")
        @Produces("application/json")
        public List<LimitOrder> viewStockHolderLimitOrders(
                @PathParam("stockHolderId") Integer stockHolderId,
                @PathParam("numberLimitOrders") Integer numberLimitOrders);
    
        @GET
        @Path("/stockholders/{stockHolderId}/orders/market/last/{numberLimitOrders}")
        @Produces("application/json")
        public List<MarketOrder> viewStockHolderMarketOrders(
                @PathParam("stockHolderId") Integer stockHolderId,
                @PathParam("numberLimitOrders") Integer numberMarketOrders);
    }
  2. TradingServicesImpl.java (create)
    package com.jboss.trading.rest;
    
    import com.jboss.trading.api.TradeManager;
    import com.jboss.trading.api.exception.LimitOrderNotFoundException;
    import com.jboss.trading.api.exception.MarketOrderNotFoundException;
    import com.jboss.trading.api.exception.PlaceOrderException;
    import com.jboss.trading.api.model.LimitOrder;
    import com.jboss.trading.api.model.MarketOrder;
    import com.jboss.trading.api.model.TransactionType;
    import java.util.List;
    import javax.inject.Inject;
    import javax.inject.Named;
    
    public class TradingServicesImpl implements TradingServices {
    
        @Inject 
        @Named("TradeManagerBean")
        TradeManager tradeManager;
    
        public void cancelLimitOrder(Integer limitOrderId)
                throws LimitOrderNotFoundException {
    
            tradeManager.cancelLimitOrder(limitOrderId);
        }
    
        public void cancelMarketOrder(Integer marketOrderId)
                throws MarketOrderNotFoundException {
    
            tradeManager.cancelMarketOrder(marketOrderId);
        }
    
        public void placeLimitOrder(
                Integer stockHolderId, TransactionType transactionType,
                Integer quantity, String stockSymbol, Float price) 
                throws PlaceOrderException {
    
            tradeManager.placeLimitOrder(
                    stockHolderId, transactionType, quantity, 
                    stockSymbol, price);
        }
    
        public void placeMarketOrder(
                Integer stockHolderId, TransactionType transactionType,
                Integer quantity, String stockSymbol) {
    
            tradeManager.placeMarketOrder(
                    stockHolderId, transactionType, quantity,
                    stockSymbol);
        }
    
        public LimitOrder viewLimitOrder(Integer limitOrderId)
                throws LimitOrderNotFoundException {
    
            return tradeManager.viewLimitOrder(limitOrderId);
        }
    
        public MarketOrder viewMarketOrder(Integer marketOrderId)
                throws MarketOrderNotFoundException {
    
            return tradeManager.viewMarketOrder(marketOrderId);
        }
    
        public List<LimitOrder> viewStockHolderLimitOrders(
                Integer stockHolderId, Integer numberLimitOrders) {
    
            return tradeManager.viewStockHolderLimitOrders(
                    stockHolderId, numberLimitOrders);
        }
    
        public List<MarketOrder> viewStockHolderMarketOrders(
                Integer stockHolderId, Integer numberMarketOrders) {
    
            return tradeManager.viewStockHolderMarketOrders(
                    stockHolderId, numberMarketOrders);
        }
    }

Trading REST Client

RESTEasy will generate the client proxy using the JAX-RS annotated interface in the JBoss Trading REST module.

  1. Add the JBoss Trading REST dependency.
    <dependency>
        <groupId>com.jboss.trading</groupId>
        <artifactId>trading-rest</artifactId>
        <version>${project.version}</version>
    </dependency>
  2. Add the SLF4J Simple dependency.
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>${slf4j.version}</version>
        <scope>test</scope>
    </dependency>
  3. TradeManagerClient.java (update)
    package com.jboss.trading.rest.client;
    
    import com.jboss.trading.api.TradeManager;
    import com.jboss.trading.api.exception.LimitOrderNotFoundException;
    import com.jboss.trading.api.exception.MarketOrderNotFoundException;
    import com.jboss.trading.api.exception.PlaceOrderException;
    import com.jboss.trading.api.model.LimitOrder;
    import com.jboss.trading.api.model.MarketOrder;
    import com.jboss.trading.api.model.TransactionType;
    import com.jboss.trading.rest.TradingServices;
    import java.util.List;
    import org.jboss.resteasy.client.ClientResponseFailure;
    import org.jboss.resteasy.client.ProxyFactory;
    import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
    import org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider;
    import org.jboss.resteasy.spi.ResteasyProviderFactory;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    public class TradeManagerClient implements TradeManager {
    
        private static final Logger LOGGER = 
                LoggerFactory.getLogger(TradeManagerClient.class);
    
        private TradingServices tradingServices;
    
        static {
    
            ResteasyProviderFactory providerFactory = 
                    ResteasyProviderFactory.getInstance();
    
            providerFactory.addMessageBodyReader(
                    ResteasyJacksonProvider.class);
    
            RegisterBuiltin.register(providerFactory);
        }
    
        public TradeManagerClient(TradingServices tradingServices) { 
    
            this.tradingServices = tradingServices;
        }
    
        public static TradeManagerClient getInstance(String baseUri) {
    
            TradingServices tradingServices = 
                    ProxyFactory.create(TradingServices.class, baseUri);
    
            TradeManagerClient tradeManagerClient = 
                    new TradeManagerClient(tradingServices);
    
            return tradeManagerClient;
        }
    
        @Override
        public void cancelLimitOrder(Integer limitOrderId) 
                throws LimitOrderNotFoundException {
    
            try {
    
                tradingServices.cancelLimitOrder(limitOrderId);
            } 
            catch (ClientResponseFailure ex) {
    
                if (LOGGER.isDebugEnabled()) {
    
                    LOGGER.debug(ex.getMessage(), ex);
                }
    
                throw LimitOrderNotFoundException.getInstance(limitOrderId);
            }
        }
    
        @Override
        public void cancelMarketOrder(Integer marketOrderId) 
                throws MarketOrderNotFoundException {
    
            try {
    
                tradingServices.cancelMarketOrder(marketOrderId);
            } 
            catch (ClientResponseFailure ex) {
    
                if (LOGGER.isDebugEnabled()) {
    
                    LOGGER.debug(ex.getMessage(), ex);
                }
    
                throw MarketOrderNotFoundException.getInstance(marketOrderId);
            }
        }
    
        @Override
        public void placeLimitOrder(
                Integer stockHolderId, TransactionType transactionType,
                Integer quantity, String stockSymbol, Float price) 
                throws PlaceOrderException {
    
            tradingServices.placeLimitOrder(
                    stockHolderId, transactionType, quantity, 
                    stockSymbol, price); 
        }
    
        @Override
        public void placeMarketOrder(
                Integer stockHolderId, TransactionType transactionType,
                Integer quantity, String stockSymbol) {
    
            tradingServices.placeMarketOrder( 
                    stockHolderId, transactionType, 
                    quantity, stockSymbol);
        }
    
        @Override
        public LimitOrder viewLimitOrder(Integer limitOrderId) 
                throws LimitOrderNotFoundException {
    
            try {
    
                return tradingServices.viewLimitOrder(limitOrderId);
            } 
            catch (ClientResponseFailure ex) {
    
                if (LOGGER.isDebugEnabled()) {
    
                    LOGGER.debug(ex.getMessage(), ex);
                }
    
                throw LimitOrderNotFoundException.getInstance(limitOrderId);
            }
        }
    
        @Override
        public MarketOrder viewMarketOrder(Integer marketOrderId) 
                throws MarketOrderNotFoundException {
    
            try {
    
                return tradingServices.viewMarketOrder(marketOrderId);
            } 
            catch (ClientResponseFailure ex) {
    
                if (LOGGER.isDebugEnabled()) {
    
                    LOGGER.debug(ex.getMessage(), ex);
                }
    
                throw MarketOrderNotFoundException.getInstance(marketOrderId);
            }
        }
    
        @Override
        public List<LimitOrder> viewStockHolderLimitOrders(
                Integer stockHolderId, Integer numberLimitOrders) {
    
            return tradingServices.viewStockHolderLimitOrders( 
                    stockHolderId, numberLimitOrders);
        }
    
        @Override
        public List<MarketOrder> viewStockHolderMarketOrders(
                Integer stockHolderId, Integer numberMarketOrders) {
    
            return tradingServices.viewStockHolderMarketOrders( 
                    stockHolderId, numberMarketOrders);
        }
    }

JBoss Trading REST Client Config

The URL is updated as the JAX-RS services are exposed via the new JBoss Trading Web module.

  1. pom.xml (update)
    <base.url>http://localhost:8080/trading-web/trading</base.url>

WS Client

JBoss Trading WS Client Test Config

The URL is updated as the JAX-WS services are exposed via the new JBoss Trading Web module.

  1. pom.xml (update)
    <wsdl.url>http://localhost:8080/trading-web/TradingServices?WSDL</wsdl.url>

Build & Test

mvn clean install -Plocalhost-remote

JBoss Trading – Java EE 5 to Java EE 6 Migration

  • Part I – CDI 1.0 & JAX-RS 1.1 (link)
  • Part II – JPA 2.0 & JAX-WS 2.2 (link)
  • Part III – Structure & Packaging (link)
  • Part IV – Deployment & Testing
  • Part V – Clean Up (link)
, , ,

About Shane K Johnson

Technical Marketing Manager, Red Hat Inc.

View all posts by Shane K Johnson

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 115 other followers

%d bloggers like this: