⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insertmovieservlet.java

📁 Sun公司Dream项目
💻 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]
 */ 

/*
 * $(@)InsertMovieServlet.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.http;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
// import com.sun.sjc.idtv.vod.server.mediaprovisioning.*;
// import com.sun.sjc.idtv.vod.shared.data.*;
// import javax.naming.*;
// import javax.rmi.*;

// import org.xml.sax.*;
// import org.xml.sax.helpers.DefaultHandler;

import javax.xml.soap.*;

public class InsertMovieServlet extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
    try {
        super.init(config);
        
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    }

    public boolean submitMovie(HttpServletRequest request) {
        try {
            SOAPConnectionFactory soapConnFac = SOAPConnectionFactory.newInstance();
            SOAPConnection soapConn = soapConnFac.createConnection();
            MessageFactory mesgFac = MessageFactory.newInstance();
            SOAPMessage soapMesg = mesgFac.createMessage();
            SOAPPart soapPart = soapMesg.getSOAPPart();
            SOAPEnvelope soapEnv = soapPart.getEnvelope();
            soapEnv.getHeader().detachNode();
            SOAPBody soapBody = soapEnv.getBody();
            System.out.println("submitMovie(): populating SOAP message");
            SOAPBodyElement soapBodyElement = soapBody.addBodyElement(soapEnv.createName("Asset", "", ""));
            SOAPElement soapElement = null;
            soapElement = soapBodyElement.addChildElement("ExternalId");
            soapElement.addTextNode("1");
            soapElement = soapBodyElement.addChildElement("FullTitle");
            soapElement.addTextNode(request.getParameter("FullTitle"));
            soapElement = soapBodyElement.addChildElement("OriginalTitle");
            soapElement.addTextNode(request.getParameter("OriginalTitle"));
            soapElement = soapBodyElement.addChildElement("ShortTitle");
            soapElement.addTextNode(request.getParameter("ShortTitle"));
            soapElement = soapBodyElement.addChildElement("ShortDescription");
            soapElement.addTextNode(request.getParameter("ShortDescription"));
            soapElement = soapBodyElement.addChildElement("LongDescription");
            soapElement.addTextNode(request.getParameter("LongDescription"));
            soapElement = soapBodyElement.addChildElement("Version");
            soapElement.addTextNode(request.getParameter("Version"));
            soapElement = soapBodyElement.addChildElement("Genre");
            soapElement.addTextNode(request.getParameter("Genre"));
            soapElement = soapBodyElement.addChildElement("ProductionCompany");
            soapElement.addTextNode(request.getParameter("ProductionCompany"));
            soapElement = soapBodyElement.addChildElement("ProductionDate");
            soapElement.addTextNode(request.getParameter("ProductionDate"));
            soapElement = soapBodyElement.addChildElement("ReleaseDate");
            soapElement.addTextNode(request.getParameter("ReleaseDate"));
            soapElement = soapBodyElement.addChildElement("Country");
            soapElement.addTextNode(request.getParameter("Country"));
            soapElement = soapBodyElement.addChildElement("ScreenFormat");
            soapElement.addTextNode(request.getParameter("ScreenFormat"));
            soapElement = soapBodyElement.addChildElement("Showing");
            soapElement.addTextNode(request.getParameter("Showing"));
            soapElement = soapBodyElement.addChildElement("BoxOfficeRating");
            soapElement.addTextNode(request.getParameter("BoxOfficeRating"));
            soapElement = soapBodyElement.addChildElement("ParentalRating");
            soapElement.addTextNode(request.getParameter("ParentalRating"));
            soapElement = soapBodyElement.addChildElement("Duration");
            soapElement.addTextNode(request.getParameter("Duration"));
            soapElement = soapBodyElement.addChildElement("Color");
            soapElement.addTextNode(request.getParameter("Color"));
            soapElement = soapBodyElement.addChildElement("Stereo");
            soapElement.addTextNode(request.getParameter("Stereo"));
            soapElement = soapBodyElement.addChildElement("Surround");
            soapElement.addTextNode(request.getParameter("Surround"));
            soapElement = soapBodyElement.addChildElement("Dolby");
            soapElement.addTextNode(request.getParameter("Dolby"));
            soapElement = soapBodyElement.addChildElement("DVBContent");
            soapElement.addTextNode(request.getParameter("DVBContent"));
            soapElement = soapBodyElement.addChildElement("StartDate");
            soapElement.addTextNode(request.getParameter("StartDate"));
            soapElement = soapBodyElement.addChildElement("EndDate");
            soapElement.addTextNode(request.getParameter("EndDate"));
            soapElement = soapBodyElement.addChildElement("StandardPrice");
            soapElement.addTextNode(request.getParameter("StandardPrice"));
            soapElement = soapBodyElement.addChildElement("MinimumPrice");
            soapElement.addTextNode(request.getParameter("MinimumPrice"));
            soapElement = soapBodyElement.addChildElement("MovieURL");
            soapElement.addTextNode(request.getParameter("MovieURL"));
            soapElement = soapBodyElement.addChildElement("PosterURL");
            soapElement.addTextNode(request.getParameter("PosterURL"));
            // TODO: need to parse comma delimited field
            soapElement = soapBodyElement.addChildElement("Actors");
            soapElement.addTextNode(request.getParameter("Actors"));
            soapElement = soapBodyElement.addChildElement("Producers");
            soapElement.addTextNode(request.getParameter("Producers"));
            soapElement = soapBodyElement.addChildElement("Directors");
            soapElement.addTextNode(request.getParameter("Directors"));
            soapElement = soapBodyElement.addChildElement("Composers");
            soapElement.addTextNode(request.getParameter("Composers"));
            soapElement = soapBodyElement.addChildElement("Snapshots");
            soapElement.addTextNode(request.getParameter("Snapshots"));
            soapElement = soapBodyElement.addChildElement("Trailers");
            soapElement.addTextNode(request.getParameter("Trailers"));
            /////////////////////////////////////////////////////////////

            
            soapElement = soapBodyElement.addChildElement("EncodingType");
            soapElement.addTextNode(request.getParameter("EncodingType"));
            soapElement = soapBodyElement.addChildElement("SourceFile");
            soapElement.addTextNode(request.getParameter("SourceFile"));
            soapMesg.saveChanges();

            //System.out.println("submitMovie(): Writing to file");
            
            DataOutputStream dos = null; 
            try {
            dos = new DataOutputStream(new FileOutputStream("/tmp/movie.xml"));
                try {
                    dos.writeChars("countAttachments() = "+soapMesg.countAttachments());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                try {
                    dos.writeChars("getAttachments() = "+soapMesg.getAttachments());
                } catch (Exception e) {
                    e.printStackTrace();    
                }
                try {
                    dos.writeChars("getContentDescription() = "+soapMesg.getContentDescription());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                try {
                    dos.writeChars("getSOAPPart() = "+soapMesg.getSOAPPart());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                soapMesg.writeTo(dos);
                dos.flush();
                dos.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

            //System.out.println("submitMovie(): sending soapMesg");
            SOAPMessage soapMesgResponse = soapConn.call(soapMesg, "http://my-212/VOD/IngestServlet");
            
            //System.out.println("submitMovie(): parsing response");
            soapPart = soapMesgResponse.getSOAPPart();
            soapEnv = soapPart.getEnvelope();
            soapBody = soapEnv.getBody();
            Iterator soapBodyIterator = soapBody.getChildElements();
            soapBodyElement = (SOAPBodyElement)soapBodyIterator.next();
            Iterator soapBodyElementIterator = soapBodyElement.getChildElements();
            System.out.println("soapPart = "+soapPart+"\tsoapEnv = "+soapEnv+"\tsoapBody = "+soapBody+"\tsoapBodyElement = "+soapBodyElement);
            Name name = null;
            while(soapBodyElementIterator.hasNext()) {                
                soapElement = (SOAPElement)soapBodyElementIterator.next();
                name = soapElement.getElementName();
                if(name.getLocalName().equals("status")) {
                    if(soapElement.getValue().equalsIgnoreCase("ok")) {
                        return true;
                    }
                }
            }
            return false;
        }
        catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }            

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException {
        try {
            boolean isConfirmed = submitMovie(request);
            //System.out.println("doPost(): movie submitted");
            request.getSession().setAttribute("submitted",Boolean.valueOf(isConfirmed));
            //System.out.println("doPost(): setting attribute");
            getServletContext().getRequestDispatcher(response.encodeURL("/admin.jsp")).forward(request,response);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException {
        doPost(request, response);
    }
        
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -