Package org.osgi.service.http

Examples of org.osgi.service.http.HttpService


public class TestRequestPath extends AbstractHttpliteTestCase
{

    public void testSimpleRequestPath() 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/a/b/c", "GET" );

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


    }


    public void testMultipleSeperatorsRequestPath() 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/a/b//c", "GET" );

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

    super(context, HttpService.class.getName(), null);
  }
 
  @Override
  public Object addingService(ServiceReference reference) {
    HttpService httpService = (HttpService) context.getService(reference);
    try {
      httpService.registerResources("/VAADIN", "/VAADIN", new TargetBundleHttpContext(context, "com.vaadin"));
    } catch (NamespaceException e) {
      e.printStackTrace();
    }
    ApplicationFactoryTracker bridge = new ApplicationFactoryTracker(httpService, context);
    bridge.open();
View Full Code Here

            LOG.warning("Remote address is unavailable");
            return null;
        }

        CXFNonSpringServlet cxf = new CXFNonSpringServlet();
        HttpService httpService = getHttpService();
        try {
            httpService.registerServlet(contextRoot, cxf, new Hashtable<String, String>(), null);
            LOG.info("Successfully registered CXF DOSGi servlet at " + contextRoot);
        } catch (Exception e) {
            throw new ServiceException("CXF DOSGi: problem registering CXF HTTP Servlet", e);
        }       
        Bus bus = cxf.getBus();
View Full Code Here

public class HttpServiceConfigurationTypeHandlerTest extends TestCase {
    public void testServer() throws Exception {
        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.port")).
            andReturn("1327").anyTimes();
        HttpService httpService = EasyMock.createNiceMock(HttpService.class);
        // expect that the cxf servlet is registered
        EasyMock.replay(httpService);
       
        ServiceReference httpSvcSR = EasyMock.createNiceMock(ServiceReference.class);
        EasyMock.replay(httpSvcSR);
View Full Code Here

        assertEquals(expected, dp.getExposedProperties(sr));
    }
   
    public void testServerUsingDefaultAddress() throws Exception {
        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
        HttpService httpService = EasyMock.createNiceMock(HttpService.class);
        // expect that the cxf servlet is registered
        EasyMock.replay(httpService);
       
        ServiceReference httpSvcSR = EasyMock.createNiceMock(ServiceReference.class);
        EasyMock.replay(httpSvcSR);
View Full Code Here

        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.secure.enabled")).
            andReturn("true").anyTimes();
        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.port.secure")).
            andReturn("8432").anyTimes();
       
        HttpService httpService = EasyMock.createNiceMock(HttpService.class);
        // expect that the cxf servlet is registered
        EasyMock.replay(httpService);
       
        ServiceReference httpSvcSR = EasyMock.createNiceMock(ServiceReference.class);
        EasyMock.replay(httpSvcSR);
View Full Code Here

    public void testServletThroughSystemContext() throws Exception {

        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(getClass().getClassLoader());

        HttpService httpService = ServiceLocator.getRequiredService(HttpService.class);
        String reqspec = "/gravia/servlet?test=module";

        // Verify that the alias is not yet available
        assertNotAvailable(reqspec);

        // Register the test servlet and make a call
        String servletAlias = getRuntimeAwareAlias("/servlet");
        httpService.registerServlet(servletAlias, new HttpServiceServlet(module), null, null);
        Assert.assertEquals("http-service:1.0.0", performCall(reqspec));

        // Unregister the servlet alias
        httpService.unregister(servletAlias);
        assertNotAvailable(reqspec);

        // Verify that the alias is not available any more
        assertNotAvailable(reqspec);
    }
View Full Code Here

        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(getClass().getClassLoader());

        ModuleContext context = module.getModuleContext();
        ServiceReference<HttpService> sref = context.getServiceReference(HttpService.class);
        HttpService httpService = context.getService(sref);

        String reqspec = "/gravia/servlet?test=module";
        try {
            // Verify that the alias is not yet available
            assertNotAvailable(reqspec);

            // Register the test servlet and make a call
            String servletAlias = getRuntimeAwareAlias("/servlet");
            httpService.registerServlet(servletAlias, new HttpServiceServlet(module), null, null);
            Assert.assertEquals("http-service:1.0.0", performCall(reqspec));

            // Unregister the servlet alias
            httpService.unregister(servletAlias);
            assertNotAvailable(reqspec);

            // Verify that the alias is not available any more
            assertNotAvailable(reqspec);
        } finally {
View Full Code Here

    protected void registerServlet(BundleContext bundleContext) throws Exception {
        httpServiceRef = bundleContext.getServiceReference(HttpService.class.getName());
       
        if (httpServiceRef != null && !registerService) {
            LOG.info("Register the servlet service");
            final HttpService httpService = (HttpService)bundleContext.getService(httpServiceRef);
            if (httpService != null) {
                // create a default context to share between registrations
                final HttpContext httpContext = httpService.createDefaultHttpContext();
                // register the hello world servlet
                final Dictionary<String, String> initParams = new Hashtable<String, String>();
                initParams.put("matchOnUriPrefix", "false");
                initParams.put("servlet-name", "CamelServlet");
                httpService.registerServlet("/camel/services", // alias
                    new CamelHttpTransportServlet(), // register servlet
                    initParams, // init params
                    httpContext // http context
                );
                registerService = true;
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.