Java Code Examples for org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setInvoker()

The following examples show how to use org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setInvoker() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAXRSPerRequestValidationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();

    sf.setResourceClasses(BookStoreWithValidationPerRequest.class);
    sf.setProvider(new ValidationExceptionMapper());

    sf.setAddress("http://localhost:" + PORT + "/");
    sf.setInvoker(new JAXRSBeanValidationInvoker());

    sf.create();
}
 
Example 2
Source File: RxJava3ObservableServer.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    Bus bus = BusFactory.getDefaultBus();
    // Make sure default JSONProvider is not loaded
    bus.setProperty("skip.default.json.provider.registration", true);
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setInvoker(new ReactiveIOInvoker());
    sf.setProvider(new JacksonJsonProvider());
    sf.getOutInterceptors().add(new LoggingOutInterceptor());
    sf.setResourceClasses(RxJava3ObservableService.class);
    sf.setResourceProvider(RxJava3ObservableService.class,
                           new SingletonResourceProvider(new RxJava3ObservableService(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    server = sf.create();
}
 
Example 3
Source File: RxJava2ObservableServer.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    Bus bus = BusFactory.getDefaultBus();
    // Make sure default JSONProvider is not loaded
    bus.setProperty("skip.default.json.provider.registration", true);
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setInvoker(new ReactiveIOInvoker());
    sf.setProvider(new JacksonJsonProvider());
    sf.getOutInterceptors().add(new LoggingOutInterceptor());
    sf.setResourceClasses(RxJava2ObservableService.class);
    sf.setResourceProvider(RxJava2ObservableService.class,
                           new SingletonResourceProvider(new RxJava2ObservableService(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    server = sf.create();
}
 
Example 4
Source File: AbstractStreamingResponseExtension.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public final void customize(JAXRSServerFactoryBean bean) {
    bean.setInvoker(createInvoker(bean));
    StreamingResponseProvider<Object> streamProvider = new StreamingResponseProvider<>();
    streamProvider.setProduceMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
    bean.setProvider(streamProvider);
}
 
Example 5
Source File: JAXRSClientServerUserResourceDefaultTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void run() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setInvoker(new CustomModelInvoker());
    sf.setProvider(new PreMatchContainerRequestFilter());
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.getServiceFactory().setDefaultModelClass(DefaultResource.class);

    UserResource ur = new UserResource();
    ur.setPath("/default");
    UserOperation op = new UserOperation();
    op.setPath("/books/{id}");
    op.setName("getBook");
    op.setVerb("GET");
    Parameter param = new Parameter(ParameterType.PATH, "id");
    param.setJavaType(Long.class);
    op.setParameters(Collections.singletonList(param));

    UserOperation op2 = new UserOperation();
    op2.setPath("echobook");
    op2.setName("echo");
    op2.setVerb("POST");
    op2.setParameters(Collections.singletonList(new Parameter(ParameterType.REQUEST_BODY, null)));

    UserOperation op3 = new UserOperation();
    op3.setPath("echobookdefault");
    op3.setName("echoDefault");
    op3.setVerb("POST");
    Parameter echoDefaultParam = new Parameter(ParameterType.REQUEST_BODY, null);
    echoDefaultParam.setJavaType(SAXSource.class);
    op3.setParameters(Collections.singletonList(echoDefaultParam));

    List<UserOperation> ops = new ArrayList<>();
    ops.add(op);
    ops.add(op2);
    ops.add(op3);

    ur.setOperations(ops);

    sf.setModelBeans(ur);

    server = sf.create();
}
 
Example 6
Source File: CxfRsHttpListener.java    From tomee with Apache License 2.0 4 votes vote down vote up
private void deploy(final String contextRoot, final Class<?> clazz, final String address, final ResourceProvider rp, final Object serviceBean,
                    final Application app, final Invoker invoker, final Collection<Object> additionalProviders, final ServiceConfiguration configuration,
                    final WebBeansContext webBeansContext) {
    final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader());
    try {
        final JAXRSServerFactoryBean factory = newFactory(address, createServiceJmxName(clazz.getClassLoader()), createEndpointName(app));
        configureFactory(additionalProviders, configuration, factory, webBeansContext);
        factory.setResourceClasses(clazz);
        context = contextRoot;
        if (context == null) {
            context = "";
        }
        if (!context.startsWith("/")) {
            context = "/" + context;
        }

        if (rp != null) {
            factory.setResourceProvider(rp);
        }
        if (app != null) {
            factory.setApplication(app);
        }
        if (invoker != null) {
            factory.setInvoker(invoker);
        }
        if (serviceBean != null) {
            factory.setServiceBean(serviceBean);
        } else {
            factory.setServiceClass(clazz);
        }

        server = factory.create();
        destination = (HttpDestination) server.getDestination();

        fireServerCreated(oldLoader);
    } finally {
        if (oldLoader != null) {
            CxfUtil.clearBusLoader(oldLoader);
        }
    }
}