|
SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here. |
|
Thread Tools | Search this Thread | Display Modes |
#21
|
||||
|
||||
I found some simple jetty example code and can get it to cleanly build but how do I create a .war file using NetBeans? I've searched for hours and the best I can find is:
- NetBeans does it for you, look in the dist directory (I did, it created a .jar file) - Right click and choose export to .war (I right clicked everywhere I could think of, where do I right click?) I found some cryptic remarks about a "web project" but I can't find a way in NetBeans to select a "web project".
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#22
|
||||
|
||||
Quote:
When you create a project (File -> New) you create a Dynamic Web Application. Then you add your code, and then to create the .war file, you select the project folder and you select "File -> Export". Also, in eclipse (and netbeans too i suspect) you can fully test the servlet by right clicking on the project and selecting "Run As -> Web Application".. this will start a tomcat/jetty instance and allow you to test your servlet.
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#23
|
||||
|
||||
There's a bunch of web development stuff that's not part of the standard Java SE NetBeans install. Go into Tools > Plugins and you'll see a lot of downloadable add-ons for NetBeans. I'm not too familiar with this stuff but I'm guessing what you want is probably in the Java Web Applications plugin.
__________________
-- Greg |
#24
|
||||
|
||||
Quote:
Are you saying if they are all in the same JVM data that is the Global Context (added using AddGlobalContext()) are shared between the UI contexts? I thought AddGlobalContext() only worked within the same UI context? Tom
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#25
|
||||
|
||||
Greg, Sean,
Thanks for the help. I found what I needed by downloading the Web plugin from Tools->Plugins. Now to see if I can get the demo going...
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#26
|
||||
|
||||
Yikes! the plugin installed OK but when I went to create a new web project I had nothing but trouble.
First it wants to know what type of server I have and there is no choice for jetty. There's Tomcat, Glassfish and a whole bunch of other things, but no jetty. I chose Glassfish because it also gave me the option to download and install it. The download went OK but as soon as the new project wizard ends it complains that some library "javaee-endorsed-api-6.0" could not be found. I have no idea where to find that. I feel like a blind man fumbling around...
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#27
|
||||
|
||||
Quote:
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#28
|
|||
|
|||
Quote:
But if you had a public static array or hashmap in java and a call to add or read it in studio it would contain the same information for extenders,servers, placeshifters they would all have acces to the same object so for instance if you had a array and added element b from extender bedroom an element c from extender living room and then on the server called to get the values you would get element b and c returned. As long as you don't initiate a seperate instance in the ui this will hold true. Cheers |
#29
|
||||
|
||||
Quote:
My next step is to get some java code to talk to the servlet. Where can I find an example of how to use URLConnection? Thanks for all of your help on this gents.
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#30
|
||||
|
||||
Tom, here's a sample of how to use a url/urlconnection. (please note there is no error checking, etc, this is just the base code)
for the url, you simply, craft your url, with whatever args you need. Code:
import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; public class TestURLConnection { public static void main(String args[]) throws Exception { URL url = new URL("http://feeds.arstechnica.com/arstechnica/everything"); URLConnection conn = url.openConnection(); conn.connect(); if (conn instanceof HttpURLConnection) { System.out.println("Connected"); HttpURLConnection httpConn = (HttpURLConnection) conn; if (httpConn.getResponseCode()!=200) { System.out.println("Error: " + httpConn.getResponseCode() + "; " + httpConn.getResponseMessage()); return; } BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line = null; while ((line = reader.readLine())!=null) { System.out.println("RESPONSE: " + line); } reader.close(); } } }
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#31
|
||||
|
||||
Sean,
Don't you ever sleep? Thanks for the code snippit. How does this interact with the doGet and doPost? Does the reader.readLine statement get the results of doPost? I don't see the code sending any data to the servlet, is that correct? Would I use reader.writeLine to send something to the servlet? What I want to do is write a simple test to send some data (preferably non-String) to the servlet and have the servlet send back a response.
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#32
|
||||
|
||||
Tom, I find sleep gets in the way of me getting things done
Here's a snipped of a "TestServlet" that I just created... Code:
package test.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class TestServlet */ public class TestServlet extends HttpServlet { private static final long serialVersionUID = 1L; public TestServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); if (name==null||name.length()==0) { response.sendError(501, "Missing 'name' argument"); } response.setContentType("text/plain"); PrintWriter pw = response.getWriter(); pw.printf("Hello: %s\n", name); pw.flush(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } Code:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>ScratchWeb</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>TestServlet</display-name> <servlet-name>TestServlet</servlet-name> <servlet-class>test.servlet.TestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/TestServlet</url-pattern> </servlet-mapping> </web-app> Code:
http://localhost:8080/ScratchWeb/TestServlet?name=Sean Code:
Hello: Sean I hope this gives you a better indication of how the client and server interact.
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#33
|
||||
|
||||
Sean,
OK, that's clearer but... I thought doGet would get a request and doPost would post a response. I guess that's wrong. What's the difference between doGet and doPost? In all of the examples I've seen it's been Strings that are being passed as parameters. Can this also be used to pass more complex data like Maps and Arrays? Does the method that makes a request to the servlet expect a response right away or can it simply make the request and then continue processing? I am thinking the overall structure of my project should look like this. Comments welcome. There are three parts; 1. A jetty servlet whose job it is to wait for requests to download podcasts. It also needs to handle "status" requests such as: Is something being downloaded? What's being downloaded? How many items are in the download queue? etc. 2. A runnable class that periodically wakes up, checks for favorite podcasts that have new episodes available, and then for each new episode make a request to the servlet to download it. This runnable class will also need to provide status information such as: How many episodes are availabe for a certain podcast? (I'm not clear on how to do this part. Do I need another servlet that accepts this status info and then suplpies it to methods that request it?) 3. Some methods that can be used by the UI to request a download, get download status, etc.
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#34
|
||||
|
||||
Quote:
Quote:
for example, if you call, http://server/servlet?rssfeed=url&re...H1&channel=CH2 in the doGet, the "getParameter()" behaves like a map in that you can get the named elements 'rssfeed', 'returnitems', by name. But, 'channe' will return an array, because you used the same name 'channel' more than once. OR, from the client, you can serialize your objects, and then turn them into strings and then deserialize the objects in the servlet (a lot more complex) Quote:
Quote:
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#35
|
||||
|
||||
OK, got it. I think I can do what I need to do without serializing.
Next question: When constructing the URL in the method that calls the servlet, how do you obtain the port for the jetty server? Is this just something I need to have the user input during setup? I think I can assume a hostname of "localhost" for extenders and placeshifters and I think there is a Sage API that gets the hostname for a client. Will this work for Mac and Linux as well?
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#36
|
||||
|
||||
Quote:
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#37
|
||||
|
||||
Sean,
No love. I tried to build and deploy your code (just changed the name) but I get an error 404. Here is the java and the .xml. The .war file build fine and is placed in the jetty/webapps directory as SagePodcastRecorder.war. The .xml is in the contexts directory as sagepodcastrecorder.xml. I'm putting the followign into the browser: Code:
http://harris:8080/SagePodcastRecorder?name=Sean Code:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package sagepodcastrecorder; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * * @author Tom Miranda */ public class SagePodcastRecorder extends HttpServlet { public SagePodcastRecorder() { super(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); if (name==null||name.length()==0) { response.sendError(501, "Missing 'name' argument"); } response.setContentType("text/plain"); PrintWriter pw = response.getWriter(); pw.printf("Hello: %s\n", name); pw.flush(); } } Code:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>SagePodcastRecorder</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>SagePodcastRecorder</display-name> <servlet-name>SagePodcastRecorder</servlet-name> <servlet-class>sagepodcastrecorder.SagePodcastRecorder</servlet-class> </servlet> <servlet-mapping> <servlet-name>SagePodcastRecorder</servlet-name> <url-pattern>/SagePodcastRecorder</url-pattern> </servlet-mapping> </web-app>
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#38
|
||||
|
||||
Quote:
1. Take a look at the bmt context xml for the sjq context xml to get an idea of how to create a context file. The xml that that you posted, while is needed, is automatically added to the war file. BUT for jetty to work under sage, it also needs a context file, which is different. 2. When you invoke the url, you have to pass the CONTEXT name in the url (as defined in the context xml file) ie, Code:
http://harris:8080/YOUR_CONTEXT_NAME/SagePodcastRecorder?name=Sean Code:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure class="org.mortbay.jetty.webapp.WebAppContext"> <Set name="contextPath">/bmt</Set> <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/bmt.war</Set> <Set name="extractWAR">true</Set> <Set name="copyWebDir">true</Set> <!-- http://docs.codehaus.org/display/JETTY/How+to+Configure+Security+with+Embedded+Jetty --> <!-- include security constraints here because the only other place they can be specified is in the web.xml file inside the war file --> <!-- can the constraints be included in another file we won't overwrite? --> <Get name="securityHandler"> <Set name="userRealm"> <New class="org.mortbay.jetty.security.HashUserRealm"> <Set name="name">Metadata Tools Web (BMT)</Set> <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set> </New> </Set> <Set name="checkWelcomeFiles">true</Set> <Set name="constraintMappings"> <Array type="org.mortbay.jetty.security.ConstraintMapping"> <Item> <New class="org.mortbay.jetty.security.ConstraintMapping"> <Set name="constraint"> <New class="org.mortbay.jetty.security.Constraint"> <Set name="name">BASIC</Set> <Set name="roles"> <Array type="java.lang.String"> <Item>user</Item> <Item>admin</Item> <Item>moderator</Item> </Array> </Set> <Set name="authenticate">true</Set> </New> </Set> <Set name="pathSpec">/*</Set> </New> </Item> </Array> </Set> </Get> </Configure>
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#39
|
||||
|
||||
first, verify that jetty itself is working properly. Try browsing to http://harris:8080. It should give you an 'error' page, but on that page, it will have individual links to all the contexts currently installed.
__________________
Buy Fuzzy a beer! (Fuzzy likes beer) unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers. Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA. Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S Other Clients: Mi Box in Master Bedroom, HD-200 in kids room |
#40
|
||||
|
||||
Fuzzy - Jetty is working, I can get bmt to work fine.
Sean - I was wondering why your .xml was so much different from the other example context xml's I've seen. I copied your bmt xml (below) and it still does not work. The only difference is now if I enter http://harris:8080/sagepodcastrecorder I get a "Hello World!" message in the browser. I thought there might be a difference between SagePodcastRecorder and sagepodcastrecorder so I tried every combination of sagepodcastrecorder/sagepodcastrecorder I could think of. Code:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure class="org.mortbay.jetty.webapp.WebAppContext"> <Set name="contextPath">/sagepodcastrecorder</Set> <Set name="war"> <SystemProperty name="jetty.home" default="."/>/webapps/SagePodcastRecorder.war </Set> <Set name="tempDirectory"> <SystemProperty name="jetty.home" default="."/>/webapps/SagePodcastRecorder </Set> <Set name="defaultsDescriptor"> <SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml </Set> <Set name="extractWAR">true</Set> <Set name="copyWebDir">true</Set> </Configure>
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Re: Replying to Announcement Threads | MeInMaui | SageTV Customizations | 1 | 07-09-2009 10:49 PM |
Number of threads? | Stuntman | SageTV Beta Test Software | 8 | 11-24-2008 01:00 PM |