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

The following examples show how to use org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setAddress() . 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: AbstractCXFTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Starts a local cxf server that listens for defined SOAP operation.
 * This means that each operation should have its own test.
 * @param type the implementing type of AbstractWebService, i.e. SakaiLogin.class
 */
private <T extends AbstractWebService> void startServer(Class<T> type) {
	JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
	sf.setResourceClasses(type);

	List<Object> providers = new ArrayList<Object>();
	// add custom providers if any
	// CXF supports String, byte[], InputStream, Reader, File, JAXP Source, JAX-RS StreamingOutput, 
	// JAXB-annotated types with application/xml, text/xml and application/json formats as well as JAXBElement
	sf.setProviders(providers);

	AbstractWebService service = MockingAbstractWebService.getMockedAbstractWebService(type);
	addServiceMocks(service);

	sf.setResourceProvider(type, new SingletonResourceProvider(service, true));
	sf.setAddress(getFullEndpointAddress());

	server = sf.create();
}
 
Example 2
Source File: JAXRSClientServerTikaTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void run() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();

    final Map< String, Object > properties = new HashMap<>();
    properties.put("search.query.parameter.name", "$filter");
    properties.put("search.parser", new FiqlParser< SearchBean >(SearchBean.class));
    properties.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy/MM/dd");

    sf.setResourceClasses(BookCatalog.class);
    sf.setResourceProvider(BookCatalog.class, new SingletonResourceProvider(new BookCatalog()));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.setProperties(properties);
    sf.setProvider(new MultipartProvider());
    sf.setProvider(new SearchContextProvider());
    sf.setProvider(new JacksonJsonProvider());

    sf.create();
}
 
Example 3
Source File: JAXRSClientServerUserResourceTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setAddress("http://localhost:" + PORT + "/");

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

    UserOperation op2 = new UserOperation();
    op2.setPath("/books/{id}/chapter");
    op2.setName("getBookChapter");
    op2.setParameters(Collections.singletonList(new Parameter(ParameterType.PATH, "id")));

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

    ur.setOperations(ops);

    UserResource ur2 = new UserResource();
    ur2.setName(ChapterNoAnnotations.class.getName());
    UserOperation op3 = new UserOperation();
    op3.setPath("/");
    op3.setName("getItself");
    op3.setVerb("GET");
    ur2.setOperations(Collections.singletonList(op3));

    sf.setModelBeans(ur, ur2);

    String modelRef = "classpath:/org/apache/cxf/systest/jaxrs/resources/resources2.xml";
    sf.setModelRefWithServiceClass(modelRef, BookStoreNoAnnotationsInterface.class);
    sf.setServiceBean(new BookStoreNoAnnotationsImpl());
    server = sf.create();
}
 
Example 4
Source File: CoffeeConfig.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Bean
public org.apache.cxf.endpoint.Server jaxRsServer() {
    JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance()
            .createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class);
    factory.setServiceBeans(Arrays.<Object>asList(starbucksOutletService()));
    factory.setAddress("/" + factory.getAddress());
    List<Object> providers = new ArrayList<Object>();
    providers.add(jsonProvider());
    providers.add(new OrderReader());
    factory.setProviders(providers);
    //factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
    return factory.create();
}
 
Example 5
Source File: FormBehaviorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(FormResource.class);
    sf.setProvider(new FormReaderInterceptor());
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.create();
}
 
Example 6
Source File: JsrJsonpProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookJsonStore.class);
    sf.setResourceProvider(BookJsonStore.class,
        new SingletonResourceProvider(new BookJsonStore()));
    sf.setProvider(new JsrJsonpProvider());
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.create();
}
 
Example 7
Source File: LoggingServer.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();

    sf.setResourceClasses(BookStore.class);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), false));
    sf.setAddress("http://localhost:" + PORT + "/");

    sf.getFeatures().add(new LoggingFeature());

    sf.create();
}
 
Example 8
Source File: RxJavaObservableServer.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.setProvider(new JacksonJsonProvider());
    new ObservableCustomizer().customize(sf);
    sf.getOutInterceptors().add(new LoggingOutInterceptor());
    sf.setResourceClasses(RxJavaObservableService.class);
    sf.setResourceProvider(RxJavaObservableService.class,
                           new SingletonResourceProvider(new RxJavaObservableService(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    server = sf.create();
}
 
Example 9
Source File: SwaggerToOpenApiConversionTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStoreSwagger2.class);
    sf.setResourceProvider(BookStoreSwagger2.class,
        new SingletonResourceProvider(new BookStoreSwagger2()));
    sf.setProvider(new SwaggerToOpenApiConversionFilter());
    final Swagger2Feature feature = createSwagger2Feature();
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.create();
}
 
Example 10
Source File: CoffeeConfig.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Bean
 public org.apache.cxf.endpoint.Server jaxRsServer() {
     JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class );
     factory.setServiceBeans( Arrays.< Object >asList(starbucksOutletService()) );
     factory.setAddress( "/" + factory.getAddress() );
List<Object> providers = new ArrayList<Object>();
     providers.add(jsonProvider());
     providers.add(new OrderReader());
     factory.setProviders(providers);
     //factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
     return factory.create();
 }
 
Example 11
Source File: SwaggerUiConfigurationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStoreSwagger2.class);
    sf.setResourceProvider(BookStoreSwagger2.class,
        new SingletonResourceProvider(new BookStoreSwagger2()));
    sf.setProvider(new JacksonJsonProvider());
    final Swagger2Feature feature = new Swagger2Feature();
    feature.setRunAsFilter(false);
    feature.setSwaggerUiConfig(new SwaggerUiConfig().url("/swagger.json"));
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.create();
}
 
Example 12
Source File: JAXRSServerMetricsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookLibrary.class);
    sf.setResourceProvider(BookLibrary.class, new SingletonResourceProvider(new BookLibrary()));
    sf.setFeatures(Arrays.asList(new MetricsFeature(provider)));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.setProvider(new JacksonJsonProvider());
    sf.create();
}
 
Example 13
Source File: BookServerWebSocket.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    Bus bus = BusFactory.getDefaultBus();
    setBus(bus);
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setBus(bus);
    sf.setResourceClasses(BookStoreWebSocket.class, BookStorePerRequest.class);
    sf.setProvider(new StreamingResponseProvider<Book>());
    sf.setResourceProvider(BookStoreWebSocket.class,
                           new SingletonResourceProvider(new BookStoreWebSocket(), true));
    sf.setAddress("ws://localhost:" + port + "/websocket");
    server = sf.create();

    BusFactory.setDefaultBus(null);
    BusFactory.setThreadDefaultBus(null);
}
 
Example 14
Source File: BookServerSub.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setStaticSubresourceResolution(true);
    sf.setResourceClasses(BookStoreSubObject.class);
    sf.setResourceProvider(BookStoreSubObject.class,
                           new SingletonResourceProvider(new BookStoreSubObject(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    server = sf.create();
}
 
Example 15
Source File: SampleRestApplication.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Bean
public Server rsServer() {
    JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
    endpoint.setBus(bus);
    endpoint.setServiceBeans(Arrays.<Object>asList(new HelloServiceImpl1(), new HelloServiceImpl2()));
    endpoint.setAddress("/");
    endpoint.setFeatures(Arrays.asList(createOpenApiFeature(), new LoggingFeature()));
    return endpoint.create();
}
 
Example 16
Source File: BraveTracingTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    final Tracing brave = Tracing
            .newBuilder()
            .spanReporter(new TestSpanReporter())
            .sampler(Sampler.ALWAYS_SAMPLE)
            .build();

    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore<TraceScope>()));
    sf.setAddress("http://localhost:" + PORT);
    sf.setProvider(new JacksonJsonProvider());
    sf.setProvider(new BraveFeature(brave));
    sf.create();
}
 
Example 17
Source File: RxJava2FlowableServer.java    From cxf with Apache License 2.0 5 votes vote down vote up
private JAXRSServerFactoryBean createFactoryBean(Bus bus, boolean useStreamingSubscriber,
                                                 String relAddress) {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.getProperties(true).put("useStreamingSubscriber", useStreamingSubscriber);
    sf.setProvider(new JacksonJsonProvider());
    new ReactiveIOCustomizer().customize(sf);
    sf.getOutInterceptors().add(new LoggingOutInterceptor());
    sf.setResourceClasses(RxJava2FlowableService.class);
    sf.setResourceProvider(RxJava2FlowableService.class,
                           new SingletonResourceProvider(new RxJava2FlowableService(), true));
    sf.setAddress("http://localhost:" + PORT + relAddress);
    return sf;
}
 
Example 18
Source File: EtcdSimulator.java    From etcd-viewer with Apache License 2.0 4 votes vote down vote up
public void start() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(EtcdResource.class);

    ObjectMapper mapper = new ObjectMapper();

    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    sf.setProvider(new JacksonJsonProvider(mapper));

    etcdResource = new EtcdResourceImpl();

    sf.setResourceProvider(EtcdResource.class, new SingletonResourceProvider(etcdResource));

    sf.setAddress("http://localhost:2379/");

    endpointServer = sf.create();

    endpointServer.start();
}
 
Example 19
Source File: SseEventSourceImplTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static void startDynamicServer(Type type, Function<HttpHeaders, String> function) {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setAddress(LOCAL_ADDRESS + type.name());
    sf.setServiceBean(new DynamicServer(function, type == Type.EVENT_RETRY_LAST_EVENT_ID));
    SERVERS.put(type, sf.create());
}
 
Example 20
Source File: ResourceUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static JAXRSServerFactoryBean createApplication(Application app,
                                                       boolean ignoreAppPath,
                                                       boolean staticSubresourceResolution,
                                                       boolean useSingletonResourceProvider,
                                                       Bus bus) {

    Set<Object> singletons = app.getSingletons();
    verifySingletons(singletons);

    List<Class<?>> resourceClasses = new ArrayList<>();
    List<Object> providers = new ArrayList<>();
    List<Feature> features = new ArrayList<>();
    Map<Class<?>, ResourceProvider> map = new HashMap<>();

    // Note, app.getClasses() returns a list of per-request classes
    // or singleton provider classes
    for (Class<?> cls : app.getClasses()) {
        if (isValidApplicationClass(cls, singletons)) {
            if (isValidProvider(cls)) {
                providers.add(createProviderInstance(cls));
            } else if (Feature.class.isAssignableFrom(cls)) {
                features.add(createFeatureInstance((Class<? extends Feature>) cls));
            } else {
                resourceClasses.add(cls);
                if (useSingletonResourceProvider) {
                    map.put(cls, new SingletonResourceProvider(createProviderInstance(cls)));
                } else {
                    map.put(cls, new PerRequestResourceProvider(cls));
                }
            }
        }
    }

    // we can get either a provider or resource class here
    for (Object o : singletons) {
        if (isValidProvider(o.getClass())) {
            providers.add(o);
        } else if (o instanceof Feature) {
            features.add((Feature) o);
        } else {
            resourceClasses.add(o.getClass());
            map.put(o.getClass(), new SingletonResourceProvider(o));
        }
    }

    JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
    if (bus != null) {
        bean.setBus(bus);
    }

    String address = "/";
    if (!ignoreAppPath) {
        ApplicationPath appPath = locateApplicationPath(app.getClass());
        if (appPath != null) {
            address = appPath.value();
        }
    }
    if (!address.startsWith("/")) {
        address = "/" + address;
    }
    bean.setAddress(address);
    bean.setStaticSubresourceResolution(staticSubresourceResolution);
    bean.setResourceClasses(resourceClasses);
    bean.setProviders(providers);
    bean.getFeatures().addAll(features);
    for (Map.Entry<Class<?>, ResourceProvider> entry : map.entrySet()) {
        bean.setResourceProvider(entry.getKey(), entry.getValue());
    }
    Map<String, Object> appProps = app.getProperties();
    if (appProps != null) {
        bean.getProperties(true).putAll(appProps);
    }
    bean.setApplication(app);
    return bean;
}