Search in sources :

Example 6 with Context

use of org.restlet.Context in project OpenAM by OpenRock.

the class TokenEndpointResourceTest method shouldThrowServerErrorForExceptionsThatAreNotOAuth2RestletExceptions.

@Test
public void shouldThrowServerErrorForExceptionsThatAreNotOAuth2RestletExceptions() {
    //Given
    Context context = new Context();
    Request request = new Request();
    Response response = new Response(request);
    tokenEndpointResource.init(context, request, response);
    //When
    tokenEndpointResource.doCatch(new NullPointerException());
    //Then
    assertEquals(response.getStatus(), Status.CLIENT_ERROR_BAD_REQUEST);
    assertEquals(response.getEntityAsText(), "{\"error\":\"server_error\"}");
}
Also used : Context(org.restlet.Context) Response(org.restlet.Response) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Test(org.testng.annotations.Test)

Example 7 with Context

use of org.restlet.Context in project xwiki-platform by xwiki.

the class XWikiRestletServlet method createApplication.

@Override
protected Application createApplication(Context context) {
    Context applicationContext = context.createChildContext();
    /* Retrieve the component manager and make it available in the restlet application context. */
    ComponentManager componentManager = getComponentManager();
    applicationContext.getAttributes().put(Constants.XWIKI_COMPONENT_MANAGER, componentManager);
    JaxRsApplication application;
    try {
        application = componentManager.getInstance(JaxRsApplication.class);
    } catch (ComponentLookupException e) {
        log("Failed to lookup default JAX-RS Application", e);
        return null;
    }
    application.setContext(applicationContext);
    // Make the servlet available
    try {
        JaxRsServletProvider applicationProvider = componentManager.getInstance(JaxRsServletProvider.class);
        applicationProvider.setApplication(this);
    } catch (ComponentLookupException e) {
        log("Failed to lookup JaxRsApplicationProvider. Dyncamically added/removed resources won'tbe supported", e);
    }
    return application;
}
Also used : Context(org.restlet.Context) ComponentManager(org.xwiki.component.manager.ComponentManager) JaxRsApplication(org.restlet.ext.jaxrs.JaxRsApplication) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 8 with Context

use of org.restlet.Context in project helix by apache.

the class HelixAdminWebApp method start.

public synchronized void start() throws Exception {
    LOG.info("helixAdminWebApp starting");
    if (_component == null) {
        _zkClient = new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
        _rawZkClient = new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
        _component = new Component();
        _component.getServers().add(Protocol.HTTP, _helixAdminPort);
        Context applicationContext = _component.getContext().createChildContext();
        applicationContext.getAttributes().put(RestAdminApplication.ZKSERVERADDRESS, _zkServerAddress);
        applicationContext.getAttributes().put(RestAdminApplication.PORT, "" + _helixAdminPort);
        applicationContext.getAttributes().put(RestAdminApplication.ZKCLIENT, _zkClient);
        applicationContext.getAttributes().put(ResourceUtil.ContextKey.RAW_ZKCLIENT.toString(), _rawZkClient);
        _adminApp = new RestAdminApplication(applicationContext);
        // Attach the application to the component and start it
        _component.getDefaultHost().attach(_adminApp);
        _component.start();
    }
    LOG.info("helixAdminWebApp started on port: " + _helixAdminPort);
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) Context(org.restlet.Context) Component(org.restlet.Component) ByteArraySerializer(org.apache.helix.manager.zk.ByteArraySerializer) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer)

Aggregations

Context (org.restlet.Context)8 Request (org.restlet.Request)3 Response (org.restlet.Response)3 IOException (java.io.IOException)2 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)2 Test (org.testng.annotations.Test)2 ControllerMetrics (com.linkedin.pinot.common.metrics.ControllerMetrics)1 ValidationMetrics (com.linkedin.pinot.common.metrics.ValidationMetrics)1 ServiceStatus (com.linkedin.pinot.common.utils.ServiceStatus)1 PinotHelixResourceManager (com.linkedin.pinot.controller.helix.core.PinotHelixResourceManager)1 ValidationManager (com.linkedin.pinot.controller.validation.ValidationManager)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 Executor (java.util.concurrent.Executor)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpConnectionManager (org.apache.commons.httpclient.HttpConnectionManager)1 MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)1 PreConnectCallback (org.apache.helix.PreConnectCallback)1