Package org.osgi.service.http

Examples of org.osgi.service.http.HttpService


            }
        }
        initInternalPlugins();

        // might update HTTP service registration
        HttpService httpService = this.httpService;
        if (httpService != null)
        {
            // unbind old location first
            unbindHttpService(httpService);
View Full Code Here


     *
     * @throws NamespaceException
     */
    public void testCanRegisterResources() throws NamespaceException
    {
        HttpService httpService = getHTTPService( registry.getBundleContext() );

        httpService.registerResources( "/restest", "/webroot/", null );
    }
View Full Code Here

     * @throws NamespaceException
     * @throws IOException
     */
    public void testExecuteGET() throws ServletException, NamespaceException, IOException
    {
        HttpService httpService = getHTTPService( registry.getBundleContext() );

        BasicTestingServlet testServlet = new BasicTestingServlet();
        httpService.registerServlet( "/test", testServlet, null, null );

        HttpURLConnection client = getConnection( DEFAULT_BASE_URL + "/test", "GET" );

        client.connect();

View Full Code Here

     * @throws NamespaceException
     * @throws IOException
     */
    public void testExecutePOST() throws ServletException, NamespaceException, IOException
    {
        HttpService httpService = getHTTPService( registry.getBundleContext() );

        BasicTestingServlet testServlet = new BasicTestingServlet();
        httpService.registerServlet( "/test", testServlet, null, null );

        HttpURLConnection client = getConnection( DEFAULT_BASE_URL + "/test", "POST" );
        client.connect();

        assertTrue( client.getResponseCode() == 200 );
View Full Code Here

     * @throws NamespaceException
     * @throws IOException
     */
    public void testExecutePUT() throws ServletException, NamespaceException, IOException
    {
        HttpService httpService = getHTTPService( registry.getBundleContext() );

        BasicTestingServlet testServlet = new BasicTestingServlet();
        httpService.registerServlet( "/test", testServlet, null, null );

        HttpURLConnection client = getConnection( DEFAULT_BASE_URL + "/test", "PUT" );

        client.connect();

View Full Code Here

     * @throws NamespaceException
     * @throws IOException
     */
    public void testExecuteDELETE() throws ServletException, NamespaceException, IOException
    {
        HttpService httpService = getHTTPService( registry.getBundleContext() );

        BasicTestingServlet testServlet = new BasicTestingServlet();
        httpService.registerServlet( "/test", testServlet, null, null );

        HttpURLConnection client = getConnection( DEFAULT_BASE_URL + "/test", "DELETE" );

        client.connect();

View Full Code Here

     * @throws NamespaceException
     * @throws IOException
     */
    public void testGETResponseStringContent() throws ServletException, NamespaceException, IOException
    {
        HttpService httpService = getHTTPService( registry.getBundleContext() );

        String content = "test content";

        BasicTestingServlet testServlet = new BasicTestingServlet( content, false );
        httpService.registerServlet( "/test", testServlet, null, null );

        HttpURLConnection client = getConnection( DEFAULT_BASE_URL + "/test", "GET" );

        client.connect();

        assertTrue( client.getResponseCode() == 200 );

        String response = readInputAsString( client.getInputStream() );

        printBytes( content.getBytes() );
        printBytes( response.getBytes() );
        assertTrue( content.equals( response ) );

        httpService.unregister( "/test" );

        content = "test content";
        testServlet = new BasicTestingServlet( content, true );
        httpService.registerServlet( "/test", testServlet, null, null );

        client = getConnection( DEFAULT_BASE_URL + "/test", "GET" );

        client.connect();

View Full Code Here

     * @throws NamespaceException
     * @throws IOException
     */
    public void testGETResponseBinaryContent() throws ServletException, NamespaceException, IOException
    {
        HttpService httpService = getHTTPService( registry.getBundleContext() );

        byte[] content = generateRandomBinaryContent();

        BasicTestingServlet testServlet = new BasicTestingServlet( content, false );
        httpService.registerServlet( "/test", testServlet, null, null );

        HttpURLConnection client = getConnection( DEFAULT_BASE_URL + "/test", "GET" );

        client.connect();

        assertTrue( client.getResponseCode() == 200 );

        byte[] response = readInputAsByteArray( client.getInputStream() );

        printBytes( content );
        printBytes( response );
        assertTrue( content.length ==  response.length );
        for (int i = 0; i < content.length; ++i)
        {
            assertTrue( content[i] == response[i] );
        }

        httpService.unregister( "/test" );      
    }
View Full Code Here

     * @throws NamespaceException
     * @throws IOException
     */
    public void testCanGetResource() throws NamespaceException, IOException
    {
        HttpService httpService = getHTTPService( registry.getBundleContext() );

        httpService.registerResources( "/", "/webroot/", null );

        HttpURLConnection client = getConnection( DEFAULT_BASE_URL + "/index.html", "GET" );
        client.connect();

        assertTrue( client.getResponseCode() == 200 );
View Full Code Here

     * @throws IOException
     * @throws NamespaceException
     */
    public void testCannotGetInvalidResource() throws IOException, NamespaceException
    {
        HttpService httpService = getHTTPService( registry.getBundleContext() );

        httpService.registerResources( "/", "/webroot/", null );

        HttpURLConnection client = getConnection( DEFAULT_BASE_URL + "/index2.html", "GET" );
        client.connect();

        assertTrue( client.getResponseCode() == 404 );
View Full Code Here

TOP

Related Classes of org.osgi.service.http.HttpService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.