?? licenseserver.java
字號:
/*
* 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]
*/
/*
* $(@)LicenseServer.java $Revision: 1.3 $ $Date: 2006/09/20 01:37:39 $
*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
*/
package com.sun.licenseserver;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;
import java.io.*;
import java.net.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.omc.dream.mmi.common.*;
// import com.sun.sjc.idtv.vod.shared.data.*;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.sun.dream.*;
import java.util.*;
import sun.misc.*;
import com.sun.sjc.idtv.vod.shared.data.RightsInfo;
import com.sun.sjc.idtv.vod.shared.data.VerbElement;
/**
* The LicenseServer is a servlet that can be used to
* get the license for a given media type. The license server
* stores the licenses in a database. The database details have
* to by the user in the configuration file WEB-INF/conf/LicenseServer.xml.
*
*/
public class LicenseServer extends HttpServlet {
/**
* Initialize the servlet. The method reads
* the configuration values stored in the file
* WEB-INF/conf/License-Server.xml.
*
*/
public void init()
throws ServletException {
m_log.finest("Entering Function...");
Document doc = loadConfFile();
if (doc == null) {
m_log.severe("Error in initializing the servlet because of problems in parsing conf file");
throw new LicenseServerException(LicenseServerException.EC_NO_ERROR_CODE,
"error in parsing the conf file");
}
m_databaseHelper = DatabaseHelper.init(doc);
m_operaProxyURL = m_databaseHelper.getConfParameterValue(doc, "operaProxyURL");
if (m_operaProxyURL == null || "".equals(m_operaProxyURL.trim())) {
m_log.severe("Error in initializing the servlet because opera proxy URL is null. " +
"Change WEB-INF/conf/license-server.xml");
throw new LicenseServerException(LicenseServerException.EC_NO_ERROR_CODE,
"error in parsing the conf file because opera proxy is null");
}
String authenticate = m_databaseHelper.getConfParameterValue(doc, "authenticate");
if (authenticate != null && authenticate.equalsIgnoreCase("false")) {
m_authenticate = false;
}
HashMap map = new HashMap();
ServletContext servletContext = getServletContext();
servletContext.setAttribute("SessionHashMap", map);
m_log.finer("Leaving Function...");
}
/**
* Loads the xml configuration file,
* parses it and returns the Document object.
*
* @return
*/
private Document loadConfFile() {
m_log.finer("Entering Function...");
String confFile = "/WEB-INF/conf/license-server.xml";
URL confFileURL = null;
try {
confFileURL = getServletContext().getResource(confFile);
} catch (MalformedURLException e1) {
m_log.severe("License Server configuration file does not exists..");
e1.printStackTrace();
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
Document doc = null;
try {
db = dbf.newDocumentBuilder();
doc = db.parse(confFileURL.openStream());
} catch (SAXException e2) {
m_log.severe("Error in Parsing License Server Configuration File..");
e2.printStackTrace();
} catch (IOException e2) {
m_log.severe("Error in Parsing License Server Configuration File..");
m_log.severe("Probably the file /WEB-INF/conf/license-server.xml does not exists");
e2.printStackTrace();
} catch (ParserConfigurationException e) {
m_log.severe("Error in Parsing License Server Configuration File..");
e.printStackTrace();
}
m_log.finer("Leaving function...");
return doc;
}
/*
* This method is used to handle HTTP POST requests.
*
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
m_log.finest("Entering Function...");
processRequest(request, response);
m_log.finer("Leaving Function...");
}
/**
* This method is used to handle HTTP GET requests.
*
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
m_log.finer("Entering Function...");
processRequest(request, response);
m_log.finer("Leaving Function...");
}
/**
* This method processes all the requests that
* are send to the LicenseServer.
*
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
m_log.finer("Entering Function...");
m_log.fine("LICENSE SERVER REQUEST.GETQUERYSTRING() "+request.getQueryString());
String action = request.getParameter(Const.ACTION);
String userID = null;
String contentID = null;
String shopID = null;
String mmiVersion;
HttpSession httpSession = null;
MMIMessage mmiMessage = null;
if (action == null) {
m_log.fine("ACTION = null");
mmiVersion = request.getParameter("MMIVersion");
if(mmiVersion != null) { //MMI route
m_log.fine("There is a MMIMessage in this request");
// This maybe an MMIMessage
// check MMIMessage
// get userID, contentID
String strQuery = request.getQueryString();
MMIParserFactory mmiParserFactory = MMIParserFactory.PLAINTEXT;
MMIPlainTextParser mmiPlainTextParser = (MMIPlainTextParser)mmiParserFactory.createParser();
try {
m_log.fine("QUERY:"+strQuery);
mmiMessage = mmiPlainTextParser.parseMessage(strQuery);
} catch (Exception e) {
e.printStackTrace();
}
httpSession = request.getSession();
httpSession.setAttribute("MMIMessage", mmiMessage);
ServletContext servletContext = getServletContext();
HashMap hashMap = (HashMap)servletContext.getAttribute("SessionHashMap");
hashMap.put(httpSession.getId(), mmiMessage);
servletContext.setAttribute("SessionHashMap", hashMap);
MMIRequest mmiRequest = (MMIRequest)mmiMessage.getMMIDataObject();
userID = mmiRequest.getIdentitySegment().getAuthServiceId().getAuthServiceId();
MMIRightsRequestElement[] mmiRightsRequestElement = mmiRequest.getRightsSegment().getMMIRightsRequestElement();
StringBuffer sb = new StringBuffer();
for(int i=0;i<mmiRightsRequestElement.length; i++) {
ContentId[] contentId = mmiRightsRequestElement[i].getContentId();
for(int j=0; j<contentId.length; j++) {
if(i==0 && j==0) {
sb.append(contentId[j].getContentId());
} else {
sb.append(","+contentId[j].getContentId());
}
}
}
contentID=sb.toString();
shopID="operaShop0";
strQuery = request.getQueryString();
// check to see if vouchers exist
// strQuery[1] are the vouchers
m_log.finer("Calling handleLicenseRequest");
handleLicenseRequest(userID, contentID, shopID, null, request, response); // redirect to Opera Proxy
m_log.finer("Exit handleLicenseRequest");
} else if ("".equals(action.trim())) {
throw new LicenseServerException(LicenseServerException.EC_INVALID_ARGUMENT,
"Action parameter can not be null.");
}
} else {
m_log.finer("There is no MMIMessage in this request");
userID = request.getParameter(Const.USERID);
contentID = request.getParameter(Const.CONTENT_ID);
shopID = request.getParameter(Const.SHOPID);
String casFlag = request.getParameter(Const.CAS_FLAG);
// See if we have a stored session
// We need to extract defaults from there
// if userid, contentId and shopid are null
//
HttpSession session = request.getSession(true);
SessionInfo si = (SessionInfo) session.getAttribute("session");
if (si != null) {
if (userID == null || "".equals(userID.trim())) {
userID = si.getUserId();
}
if (contentID == null || "".equals(contentID.trim())) {
contentID = si.getContentId();
}
if (shopID == null || "".equals(shopID.trim())) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -