Hi,


I'm trying to implement a Restlet resource that should display different
media type, for example: text and video, text and image, image and video.



In particular, the example that I consider aims to show a video and its
textual description, I prepared a Freemarker Template for Html
Representation,

the code is as follows:



TEMPLATE FTL





    

    

      
Video Preview.avi


      

      
 Texual Description of video Preview.avi 


     

      
   

        

        

     


    

    





When I call the Restlet resource from the browser a failure occurs; 

the resource displays only the box corresponding to the video, 

the text "connecting to server localhost: 8182" and after a few seconds, the
player stops without playing the video. 

The path of the video included in the code is correct, we also tried to
change the Representation type replacing "text_html" with "Multipart_all" or
"Video_avi" 

but no change occurs.

Previously I specified in the template also the path of the player to use
but I did't have a different result. 

The video plays correctly if, instead of accessing the Restlet resource, I
open the ftl template with a standard browser. 

Below is also the Restlet application code that uses the video. 



package test;



import org.restlet.resource.*; 

import freemarker.template.Configuration;

import org.restlet.data.MediaType;

import org.restlet.ext.freemarker.TemplateRepresentation;

import org.restlet.representation.Representation;



public class Test extends ServerResource{

    

        private static final String HTML_TEMPLATE_FILE = "test.ftl"; 

        private String htmlRepresentationTemplate;

        

    protected void doInit() throws ResourceException {  

                super.doInit();

                setHtmlRepresentationTemplate(HTML_TEMPLATE_FILE);

        }

    

    @Override

        public Representation get(){

        

                Configuration c = new Configuration();

                TemplateRepresentation t = new 
TemplateRepresentation(HTML_TEMPLATE_FILE,
c, MediaType.TEXT_HTML);

                

                return t;

        }

    

    protected void setHtmlRepresentationTemplate( String
htmlRepresentationTemplate) {

                this.htmlRepresentationTemplate = htmlRepresentationTemplate;

        }

        

        

        protected String getHtmlRepresentationTemplate() {

                return this.htmlRepresentationTemplate;

        }

}





TEST APPLICATION

package test;



import org.restlet.Application;  

import org.restlet.Restlet;  

import org.restlet.routing.Router;  



public class TestApplication extends Application{

        @Override  

        public synchronized Restlet createInboundRoot() {  

        Router router = new Router(getContext());  

        

        router.attach("/test", test.class);  

        router.attach("/test/Preview.avi", test.class);

        

        return router;  

    }  

}





MAIN CLASS

package test;



import org.restlet.Component;

import org.restlet.data.Protocol;



public class MainClass {

        public static void main(String[] args) throws Exception {  

                // Create a new Component.  

                Component component = new Component();  

                

                // Add a new HTTP server listening on port 8182.  

                component.getServers().add(Protocol.HTTP, 8182);  

                

                

                // Attach the sample application.  

                TestApplication t = new TestApplication();

                component.getDefaultHost().attach("/testApplication",  t);  

                

                // Start the component.  

                component.start();  

                }  



}



Could you suggest me a solution to this error? Should I use particular
libraries to play videos?

--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/Restlet-Resource-with-mixed-Media-Type-tp6195923p6195923.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2713135

Reply via email to