?? commcontrollerdebugservlet.java
字號(hào):
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* http://www.opensource.org/licenses/cddl1.php
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* http://www.opensource.org/licenses/cddl1.php. If
* applicable, add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced
* with your own identifying information:
* Portions Copyright [yyyy]
* [name of copyright owner]
*/
/*
* $(@)CommControllerDebugServlet.java $Revision: 1.1.1.1 $ $Date: 2006/03/15 13:12:10 $
*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
*/
package com.sun.sjc.idtv.vod.server.comm;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.naming.*;
import javax.servlet.http.*;
import javax.rmi.PortableRemoteObject;
import javax.ejb.*;
import com.sun.sjc.idtv.vod.server.subscriber.*;
import com.sun.sjc.idtv.vod.server.mediacatalog.*;
import com.sun.sjc.idtv.vod.server.billing.*;
import com.sun.sjc.idtv.vod.server.auditing.*;
import com.sun.sjc.idtv.vod.shared.data.*;
/**
* This servlet is responsible for throwing the html pages for the HelloWorld application.
*/
public class CommControllerDebugServlet extends HttpServlet {
/**
* The doGet method of the servlet. Handles all http GET request.
* Required by the servlet specification.
* @exception throws ServletException and IOException.
*/
public void doGet (HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
SubscriberManagementSystem sms;
SubscriberManagementSystemHome smsHome;
MediaCatalog mediacat;
MediaCatalogHome mediacatHome;
BillingEngine billing;
BillingEngineHome billingHome;
AuditLog auditer;
AuditLogHome auditerHome;
InitialContext initContext = null;
Hashtable env = new java.util.Hashtable(1);
response.setContentType("text/html");
ServletOutputStream out = response.getOutputStream();
out.println("<html><head></head><body><b>CommControllerServlet</b><br><br><pre>");
//System.out.println("\n>>> CommControllerDebugServlet is executing at http://voyager/VOD/CommControllerServlet...");
try {
initContext = new javax.naming.InitialContext();
String JNDIName = "java:comp/env/ejb/SubscriberManagementSystem";
System.out.println("Looking up: " + JNDIName);
Object objref = initContext.lookup(JNDIName);
smsHome = (SubscriberManagementSystemHome)PortableRemoteObject.narrow(objref, SubscriberManagementSystemHome.class);
System.out.println("Creating the subscriber bean");
sms = smsHome.create();
out.println("getSubscriberList for IP 127.0.0.1:");
Subscriber[] subs = sms.getSubscriberList("127.0.0.1");
for (int i=0; i<subs.length; i++) {
System.out.println("Got this from bean: " + subs[i].login + " " + subs[i].firstname + " " + subs[i].lastname);
out.println("\t" + subs[i].login + " " + subs[i].firstname + " " + subs[i].lastname);
}
Subscriber me = subs[0];
me.pin = "1234";
System.out.println("Authenticating...");
me = sms.authenticate(me);
System.out.println("Authenticated");
String msg;
if (me == null) throw new Exception("Authentication failed: invalid ip or pin");
msg = me.pin;
out.println("\nauthenticate: " + msg);
out.println("allowed categories: ");
for (int i=0; i<me.categories.length; i++) {
out.println("\t" + me.categories[i].genrename);
}
out.println("\nrentals: ");
for (int i=0; i<me.rentals.length; i++) {
out.print("\t" + me.rentals[i].shorttitle);
}
out.println();
JNDIName = "java:comp/env/ejb/MediaCatalog";
System.out.println("Looking up: " + JNDIName);
objref = initContext.lookup(JNDIName);
mediacatHome = (MediaCatalogHome)PortableRemoteObject.narrow(objref, MediaCatalogHome.class);
System.out.println("Creating the catalog bean");
mediacat = mediacatHome.create();
for (int i=0; i<me.categories.length; i++) {
out.println("\ngetMovieList for category " + me.categories[i].genrename + ":");
Movie[] movies = mediacat.getMovieList(me.categories[i].genreid);
for (int j=0; j<movies.length; j++) {
System.out.println("Got this from bean: " + movies[j].shorttitle + " " + movies[j].longdescr);
Movie movie = mediacat.getMovieMetadata(movies[j].id);
String rtspurl = "rtsp://172.68.40.114:554//172.68.40.114/" + movie.movieurl + ";servertype=MediaBase;";
String rtsplink = "<A HREF=\"" + rtspurl + "\">" + movie.movieurl + "</A>";
out.println(rtsplink + "\t" + movies[j].shorttitle + ": " + movies[j].longdescr);
}
}
out.println();
out.println("\nselecting movie 1");
Movie movie = mediacat.getMovieMetadata(1);
out.println(movie.toString());
out.println("</pre>");
for (int i=0; i<movie.imageurls.length; i++) {
out.println("<img src=\""+ movie.imageurls[i] + "\"> ");
}
out.println("<pre>");
out.println("\nContent: <A HREF=\"" + movie.movieurl + "\">" + movie.movieurl + "</A>");
String plugin = "\n<OBJECT CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" WIDTH=\"480\" HEIGHT=\"280\" CODEBASE=\"http://www.apple.com/qtactivex/qtplugin.cab\">" +
"<PARAM NAME=\"controller\" VALUE=\"TRUE\">" +
"<PARAM NAME=\"autoplay\" VALUE=\"false\">" +
"<PARAM NAME=\"target\" VALUE=\"myself\">" +
"<PARAM NAME=\"pluginspage\" VALUE=\"http://www.apple.com/quicktime/download/indext.html\">" +
"<PARAM NAME=\"SRC\" VALUE=\"/movies/" + movie.movieurl + "\">" +
"<EMBED WIDTH=\"480\" HEIGHT=\"280\" CONTROLLER=\"TRUE\" TARGET=\"myself\" SRC=\"/movies/" + movie.movieurl + "\" BGCOLOR=\"#000000\" BORDER=\"0\" PLUGINSPAGE=\"http://www.apple.com/quicktime/download/indext.html\"></EMBED></OBJECT>";
//out.println(plugin);
out.println();
JNDIName = "java:comp/env/ejb/BillingEngine";
System.out.println("Looking up: " + JNDIName);
objref = initContext.lookup(JNDIName);
billingHome = (BillingEngineHome)PortableRemoteObject.narrow(objref, BillingEngineHome.class);
System.out.println("Creating the billing bean");
billing = billingHome.create();
out.println("\ngetAccountBalance: " + billing.getAccountBalance(me));
out.println("rentMovie: " + billing.rentMovie(me, movie));
out.println("getAccountBalance: " + billing.getAccountBalance(me));
out.println("getHistory: ");
String[] history = billing.getHistory(me, new java.util.Date(1970, 0, 1), new java.util.Date(2010, 0, 1));
for (int i=0; i<history.length; i++) {
out.println("\t" + history[i]);
}
JNDIName = "java:comp/env/ejb/AuditLog";
System.out.println("Looking up: " + JNDIName);
objref = initContext.lookup(JNDIName);
auditerHome = (AuditLogHome)PortableRemoteObject.narrow(objref, AuditLogHome.class);
System.out.println("Creating the audit bean");
auditer = auditerHome.create();
out.println("\nlog: ");
auditer.log(me, "RENTAL", "MOVIEID=" + movie.id, "OK");
out.println();
} catch (Exception e) {
System.out.println("Exception: " + e.toString());
e.printStackTrace();
e.printStackTrace(new PrintStream(out));
return;
}
out.println("</pre></body></html>");
return;
}
/**
* The doPost method of the servlet. Handles all http POST request.
* Required by the servlet specification.
* @exception throws ServletException and IOException.
*/
public void doPost (HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
/**
* Returns the servlet info as a String.
* @return returns the servlet info as a String.
*/
public String getServletInfo() {
return "Call a session bean from a servlet and deliver result via a JSP.";
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -