All Examples This Package JMS Examples
Class examples.jms.webshare.WebshareServlet
examples.jms.webshare.WebshareServlet
- public class WebshareServlet
This example is a servlet that allows users to rate web pages and
receive other users' web page ratings. It demonstrates these
features of JMS:
- Publish/subscribe (Topic) messaging model.
- Using a MapMessage.
- Setting and checking the JMSType header field.
- Setting message properties.
- Using durable subscriptions.
- Using message selectors to filter messages.
Any user can publish a web page rating. The servlet requires
users to log in with a ClientID. This ClientID is used to
reconnect a TopicSubscriber so that the user can
receive all of the messages posted. The ClientID is also
used in messages to identify the user who published the
web page rating.
Configure the server:
-
Set weblogic.httpd.session.enable=true in the
weblogic.properties file.
-
You must have a connection
pool configured and assigned to JMS in the
weblogic.properties file. See JMS Examples
for instruction on how to set up a connection pool for JMS.
-
Set up a JMS Topic and a Durable ClientID by adding these properties to
your weblogic.properties file:
weblogic.jms.topic.webshareTopic=jms.topic.webshareTopic
weblogic.jms.connectionFactoryName.webshare=jms.connection.webshareFactory
weblogic.jms.connectionFactoryArgs.webshare=ClientID=webshareUser
-
Register the servlet in your weblogic.properties file
by adding this property:
weblogic.httpd.register.webshare=examples.jms.webshare.WebshareServlet
-
Set the servlet classpath and reload properties in your weblogic.properties file
by adding the following properties:
weblogic.httpd.servlet.classpath=weblogic/myserver/servletclasses
weblogic.httpd.servlet.reloadCheckSecs=1
where weblogic is the directory where WebLogic is installed.
Build the example:
-
Set up your development shell, as described in
Setting up
your environment.
-
Compile the files in this directory as shown in this examples for Windows NT:
$ javac -d %SERVLET_CLASSES% WebshareServlet.java
Run the example:
-
Start the WebLogic Server in a new command shell.
-
Load the servlet in a browser with a URL like this:
http://hostname:port/webshare
where:
- hostname
- Host name of the WebLogic Server
- port
- Port where the WebLogic Server is listening for connections
(weblogic.system.ListenPort).
-
Log in to establish a session with the servlet. Then you
can choose to rate web pages, view the posted web page listings, or
change your subscription information.
- Author:
- Copyright (c) 1999 by BEA Systems. All Rights Reserved.
-
JMS_FACTORY
-
-
MESSAGE_TYPE
-
-
TOPIC
-
-
WebshareServlet()
-
-
editSubscription(PrintWriter, String)
- Create a DurableSubscription and MessageSelector for the
current logged in user.
-
getLogin(PrintWriter)
- Draws the login HTML page.
-
getOptions(PrintWriter)
-
Sticks standard buttons on the bottom of pages.
-
getRatings(PrintWriter, String)
- Reads website recommendations from the webshareTopic JMS Topic.
-
installSelector(PrintWriter, String, String, int, String)
-
Create a selector string and update the user's DurableSubscription
-
printForm(PrintWriter, String)
- Displays the website review form.
-
service(HttpServletRequest, HttpServletResponse)
-
-
shareUrl(String, String, int, String, String, String)
- Publishes a website review to the webshareTopic Topic.
JMS_FACTORY
public static final String JMS_FACTORY
TOPIC
public static final String TOPIC
MESSAGE_TYPE
public static final String MESSAGE_TYPE
WebshareServlet
public WebshareServlet()
service
public void service(HttpServletRequest req,
HttpServletResponse res) throws IOException, ServletException
getLogin
public void getLogin(PrintWriter pw) throws Exception
- Draws the login HTML page.
getOptions
public void getOptions(PrintWriter pw) throws Exception
- Sticks standard buttons on the bottom of pages. Pressing one
of these buttons determines which post method the service() method
is going to process.
printForm
public void printForm(PrintWriter pw,
String login) throws Exception
- Displays the website review form.
shareUrl
public void shareUrl(String user,
String category,
int rating,
String summary,
String pagetitle,
String url) throws NamingException, JMSException
- Publishes a website review to the webshareTopic Topic.
editSubscription
public void editSubscription(PrintWriter pw,
String user) throws NamingException, JMSException, Exception
- Create a DurableSubscription and MessageSelector for the
current logged in user.
installSelector
public void installSelector(PrintWriter pw,
String userName,
String posters,
int minRating,
String categoryList) throws NamingException, JMSException, Exception
- Create a selector string and update the user's DurableSubscription
getRatings
public void getRatings(PrintWriter pw,
String user) throws NamingException, JMSException, Exception
- Reads website recommendations from the webshareTopic JMS Topic.
Creates a DurableSubscriber for whomever is logged in.
All Examples This Package JMS Examples