Wrox Programmer Forums
|
BOOK: Java Programming 24-Hour Trainer 2nd Edition
This is the forum to discuss the Wrox book Java Programming 24-Hour Trainer, 2nd Edition by Yakov Fain; ISBN: 978-1-118-95145-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Java Programming 24-Hour Trainer 2nd Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 10th, 2015, 01:17 PM
Registered User
 
Join Date: Dec 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson31 Tryit

The Tryit source code isn't in the download (this is true for many tryit. ex: lesson 30 as well). I manually created the source code but getting HTTP Status 404 - Not Found.


package lesson31.ejb;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.jms.ConnectionFactory;
import javax.annotation.Resource;

import javax.jms.Destination;
import javax.jms.JMSContext;
import javax.jms.JMSProducer;

/**
* Session Bean implementation class StockServerBean
*/
@Stateless
@LocalBean
public class StockServerBean {
@Resource(lookup = "java:comp/DefaultJMSConnectionFactory")
ConnectionFactory factory;


@Resource(lookup = "MyJMSTestQueue")
Destination testQueue;

private List<String> nasdaqSymbols = new ArrayList<>();
/**Ser
* Default constructor.
*/
public StockServerBean() {
// Define some hard-coded NASDAQ symbols
nasdaqSymbols.add("AAPL");
nasdaqSymbols.add("MSFT");
nasdaqSymbols.add("YHOO");
nasdaqSymbols.add("AMZN");

}
@Schedule(second="*",minute="*", hour="*")
public void getQuote(){

String symbol = "AAPL";
// Generate a random price for valid symbols
String price = (new Double(Math.random()*100)).toString();
String quote = "The price of " + symbol + " is " + price;

// send to JMS queue

{
try (JMSContext context = factory.createContext("admin","admin")) {

JMSProducer producer = context.createProducer();

// Send stock quote to the queue
producer.send(testQueue, quote);

System.out.println("Sent stock quote to the queue: " + quote);
}

}
}
}
 
Old December 10th, 2015, 04:21 PM
Authorized User
 
Join Date: Feb 2012
Posts: 30
Thanks: 5
Thanked 4 Times in 4 Posts
Default

Might it be that the StockServerBean is not created?
How about using the @Startup annotation, to request the creation of the bean on application startup?
 
Old December 10th, 2015, 04:51 PM
Registered User
 
Join Date: Dec 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@Startup doesn't help. Same error
 
Old December 10th, 2015, 05:06 PM
Authorized User
 
Join Date: Feb 2012
Posts: 30
Thanks: 5
Thanked 4 Times in 4 Posts
Default

Did you implement a consumer (message driven bean) as well?
I don't understand what does HTTP have to do with this ejb...
 
Old December 23rd, 2015, 02:45 PM
Authorized User
 
Join Date: Oct 2014
Posts: 13
Thanks: 1
Thanked 4 Times in 4 Posts
Default Lesson31 Tryit

Hi,

Let me know if you are still having problems with the Lesson 31 TryIt code. I can help out.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 9 Tryit cellison BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 1 July 14th, 2012 01:57 PM
Chapter 11 TryIt Luthios BOOK: Java Programming 24-Hour Trainer by Yakov Fain 8 March 3rd, 2012 01:57 PM
TryIt 32 zavodney BOOK: Stephens' Visual Basic Programming 24-Hour Trainer 5 October 13th, 2011 11:33 AM
Lesson 36 Tryit Mark P. BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 4 October 11th, 2011 02:49 PM
Chapter 10 Tryit Mark P. BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 3 June 20th, 2011 08:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.