Java Code Examples for org.apache.cxf.Bus#setProperty()

The following examples show how to use org.apache.cxf.Bus#setProperty() . 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: AtmosphereWebSocketServletDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", new CustomInterceptor1());
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example 2
Source File: AtmosphereWebSocketJettyDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptors() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(), new CustomInterceptor2()));
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
        } else if (CustomInterceptor2.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(2, added);
}
 
Example 3
Source File: AtmosphereWebSocketJettyDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", new CustomInterceptor1());
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example 4
Source File: AtmosphereWebSocketServletDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptors() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(), new CustomInterceptor2()));
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
        } else if (CustomInterceptor2.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(2, added);
}
 
Example 5
Source File: SseProvidersExtension.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void busCreated(Bus bus) {
    Object providers = bus.getProperty(BUS_PROVIDERS);
    
    final List<?> sseProviders = 
        Arrays.asList(
            new SseContextProvider(), 
            new SseEventSinkContextProvider()
        );
    
    if (providers instanceof List) {
        final List<?> existing = new ArrayList<>((List<?>)providers);
        existing.addAll(CastUtils.cast(sseProviders));
        bus.setProperty(BUS_PROVIDERS, existing);
    } else {
        bus.setProperty(BUS_PROVIDERS, sseProviders);
    }
    
    bus.getInInterceptors().add(new SseInterceptor());
}
 
Example 6
Source File: SwaggerUiSupport.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Detects the presence of Swagger UI in classpath with respect to properties and
 * configuration provided. 
 * @param bus bus instance 
 * @param swaggerProps Swagger properties (usually externalized) 
 * @param runAsFilter "true" if Swagger integration is run as a filter, "false" otherwise. 
 * @return the Swagger UI registration
 */
default Registration getSwaggerUi(Bus bus, Properties swaggerProps, boolean runAsFilter) {
    final Registration registration = new Registration();
    
    if (checkSupportSwaggerUiProp(swaggerProps)) {
        String swaggerUiRoot = findSwaggerUiRoot();
        
        if (swaggerUiRoot != null) {
            final SwaggerUiResourceLocator locator = new SwaggerUiResourceLocator(swaggerUiRoot);
            SwaggerUiService swaggerUiService = new SwaggerUiService(locator, getSwaggerUiMediaTypes());
            swaggerUiService.setConfig(getSwaggerUiConfig());
            
            if (!runAsFilter) {
                registration.resources.add(swaggerUiService);
            } else {
                registration.providers.add(new SwaggerUiServiceFilter(swaggerUiService));
            }

            registration.providers.add(new SwaggerUiResourceFilter(locator));
            bus.setProperty("swagger.service.ui.available", "true");
        }
    }
    
    return registration;
}
 
Example 7
Source File: ProviderFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomProviderSortingWithBus2() {
    WildcardReader wc1 = new WildcardReader();
    WildcardReader2 wc2 = new WildcardReader2();
    Bus bus = BusFactory.newInstance().createBus();
    bus.setProperty(MessageBodyReader.class.getName(), wc2);
    ProviderFactory pf = ServerProviderFactory.createInstance(bus);
    pf.registerUserProvider(wc1);
    List<ProviderInfo<MessageBodyReader<?>>> readers = pf.getMessageReaders();
    assertEquals(11, readers.size());
    assertSame(wc1, readers.get(7).getProvider());
    assertSame(wc2, readers.get(8).getProvider());
}
 
Example 8
Source File: AbstractSwaggerFeature.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Server server, Bus bus) {
    if (!activateOnlyIfJaxrsSupported || SWAGGER_JAXRS_AVAILABLE) {
        calculateDefaultResourcePackage(server);
        calculateDefaultBasePath(server);
        addSwaggerResource(server, bus);

        doInitializeProvider(server.getEndpoint(), bus);
        bus.setProperty("swagger.service.description.available", "true");
    }
}
 
Example 9
Source File: JAXRSClientFactoryBeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvokePathEmptyAllowed() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    bus.setProperty("allow.empty.path.template.value", true);
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setBus(bus);
    bean.setAddress("http://bar");
    bean.setResourceClass(BookInterface.class);
    BookInterface store = bean.create(BookInterface.class);
    assertNotNull(store.getBook(""));
}
 
Example 10
Source File: CertConstraintsFeature.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bus bus) {
    if (contraints == null) {
        return;
    }
    doInitializeProvider(bus, bus);
    CertConstraints c = CertConstraintsJaxBUtils.createCertConstraints(contraints);
    bus.setProperty(CertConstraints.class.getName(), c);
}
 
Example 11
Source File: ServerBusListener.java    From peer-os with Apache License 2.0 5 votes vote down vote up
public void busRegistered( Bus bus )
{
    LOG.info( "Adding LoggingFeature interceptor on bus: " + bus.getId() );

    //********Set BUS Message Size to 500 KB ************************
    bus.setProperty( "bus.io.CachedOutputStream.Threshold", "500000" );
    System.setProperty( "org.apache.cxf.io.CachedOutputStream.Threshold", "500000" );
    LOG.info( "Setting CXF CachedOutputStream.Threshold size to: 500Kb " );
    //***************************************************************
    bus.setProperty( AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE );
    //***************************************************************

    // initialise the feature on the bus, which will add the interceptors

    //***** RECEIVE    **********************************
    bus.getInInterceptors().add( new AccessControlInterceptor( identityManager ) );

    //***** PRE_STREAM **********************************
    bus.getOutInterceptors().add( new ClientOutInterceptor( securityManager, peerManager ) );

    //***** POST_LOGICAL **********************************
    bus.getOutInterceptors().add( new ClientHeaderInterceptor( peerManager ) );

    //***** RECEIVE    **********************************
    bus.getInInterceptors().add( new ServerInInterceptor( securityManager, peerManager ) );

    //***** PRE_STREAM **********************************
    bus.getOutInterceptors().add( new ServerOutInterceptor( securityManager, peerManager ) );

    //***** RECEIVE    **********************************
    bus.getInInterceptors().add( new ClientInInterceptor( securityManager, peerManager ) );


    LOG.info( "Successfully added LoggingFeature interceptor on bus: " + bus.getId() );
}
 
Example 12
Source File: ProviderFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomProviderSortingWithBus() {
    WildcardReader wc1 = new WildcardReader();
    WildcardReader2 wc2 = new WildcardReader2();
    Bus bus = BusFactory.newInstance().createBus();
    bus.setProperty(MessageBodyReader.class.getName(), wc1);
    ProviderFactory pf = ServerProviderFactory.createInstance(bus);
    pf.registerUserProvider(wc2);
    List<ProviderInfo<MessageBodyReader<?>>> readers = pf.getMessageReaders();
    assertEquals(11, readers.size());
    assertSame(wc2, readers.get(7).getProvider());
    assertSame(wc1, readers.get(8).getProvider());
}
 
Example 13
Source File: SpringBeansTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testChildContext() throws Exception {
    //Test for CXF-2283 - if a Child context is closed,
    //we shouldn't be shutting down
    ClassPathXmlApplicationContext ctx =
        new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxws/spring/servers.xml"});

    final Bus b = (Bus)ctx.getBean("cxf");
    BusLifeCycleManager lifeCycleManager = b.getExtension(BusLifeCycleManager.class);
    BusLifeCycleListener listener = new BusLifeCycleListener() {
        public void initComplete() {
        }

        public void postShutdown() {
            b.setProperty("post.was.called", Boolean.TRUE);
        }

        public void preShutdown() {
            b.setProperty("pre.was.called", Boolean.TRUE);
        }
    };
    lifeCycleManager.registerLifeCycleListener(listener);
    ClassPathXmlApplicationContext ctx2 =
            new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxws/spring/child.xml"},
                                               ctx);

    ctx2.close();

    assertNull(b.getProperty("post.was.called"));
    assertNull(b.getProperty("pre.was.called"));
}
 
Example 14
Source File: ReactorServer.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
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.getProperties(true).put("useStreamingSubscriber", false);
    sf.setProvider(new JacksonJsonProvider());
    new ReactorCustomizer().customize(sf);
    sf.setResourceClasses(FluxService.class, MonoService.class);
    sf.setResourceProvider(FluxService.class,
            new SingletonResourceProvider(new FluxService(), true));
    sf.setResourceProvider(MonoService.class,
            new SingletonResourceProvider(new MonoService(), true));
    sf.setAddress("http://localhost:" + PORT + "/reactor");
    server1 = sf.create();
    
    JAXRSServerFactoryBean sf2 = new JAXRSServerFactoryBean();
    sf2.setProvider(new JacksonJsonProvider());
    sf2.setProvider(new IllegalArgumentExceptionMapper());
    new ReactorCustomizer().customize(sf2);
    sf2.setResourceClasses(FluxService.class);
    sf2.setResourceProvider(FluxService.class,
            new SingletonResourceProvider(new FluxService(), true));
    sf2.setAddress("http://localhost:" + PORT + "/reactor2");
    server2 = sf2.create();
}
 
Example 15
Source File: RxJava2FlowableServer.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);
    server = createFactoryBean(bus, false, "/rx2").create();
    server = createFactoryBean(bus, true, "/rx22").create();
}
 
Example 16
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 17
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 18
Source File: RxJava3FlowableServer.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);
    server = createFactoryBean(bus, false, "/rx3").create();
    server = createFactoryBean(bus, true, "/rx33").create();
}
 
Example 19
Source File: NettyHttpConduitTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Before
public void start() throws Exception {
    Bus b = createStaticBus();
    b.setProperty(NettyHttpConduit.USE_ASYNC, NettyHttpConduitFactory.UseAsyncPolicy.ALWAYS);

    BusFactory.setThreadDefaultBus(b);

    ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort",
                          new org.apache.hello_world_soap_http.GreeterImpl() {
            public String greetMeLater(long cnt) {
                //use the continuations so the async client can
                //have a ton of connections, use less threads
                //
                //mimic a slow server by delaying somewhere between
                //1 and 2 seconds, with a preference of delaying the earlier
                //requests longer to create a sort of backlog/contention
                //with the later requests
                ContinuationProvider p = (ContinuationProvider)
                    getContext().getMessageContext().get(ContinuationProvider.class.getName());
                Continuation c = p.getContinuation();
                if (c.isNew()) {
                    if (cnt < 0) {
                        c.suspend(-cnt);
                    } else {
                        c.suspend(2000 - (cnt % 1000));
                    }
                    return null;
                }
                return "Hello, finally! " + cnt;
            }
            public String greetMe(String me) {
                if (me.equals(FILL_BUFFER)) {
                    return String.join("", Collections.nCopies(16093, " "));
                } else {
                    return "Hello " + me;
                }
            }
        });

    StringBuilder builder = new StringBuilder("NaNaNa");
    for (int x = 0; x < 50; x++) {
        builder.append(" NaNaNa ");
    }
    request = builder.toString();

    URL wsdl = NettyHttpConduitTest.class.getResource("/wsdl/hello_world_services.wsdl");
    assertNotNull("WSDL is null", wsdl);

    SOAPService service = new SOAPService();
    assertNotNull("Service is null", service);

    g = service.getSoapPort();
    assertNotNull("Port is null", g);
}
 
Example 20
Source File: AsyncHTTPConduitTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void start() throws Exception {
    Bus b = createStaticBus();
    b.setProperty(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
    b.setProperty("org.apache.cxf.transport.http.async.MAX_CONNECTIONS", 501);

    BusFactory.setThreadDefaultBus(b);

    AsyncHTTPConduitFactory hcf = (AsyncHTTPConduitFactory)b.getExtension(HTTPConduitFactory.class);
    assertEquals(501, hcf.maxConnections);

    ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort",
                          new org.apache.hello_world_soap_http.GreeterImpl() {
            public String greetMeLater(long cnt) {
                //use the continuations so the async client can
                //have a ton of connections, use less threads
                //
                //mimic a slow server by delaying somewhere between
                //1 and 2 seconds, with a preference of delaying the earlier
                //requests longer to create a sort of backlog/contention
                //with the later requests
                ContinuationProvider p = (ContinuationProvider)
                    getContext().getMessageContext().get(ContinuationProvider.class.getName());
                Continuation c = p.getContinuation();
                if (c.isNew()) {
                    if (cnt < 0) {
                        c.suspend(-cnt);
                    } else {
                        c.suspend(2000 - (cnt % 1000));
                    }
                    return null;
                }
                return "Hello, finally! " + cnt;
            }
            public String greetMe(String me) {
                if (me.equals(FILL_BUFFER)) {
                    return String.join("", Collections.nCopies(16093, " "));
                } else {
                    return "Hello " + me;
                }
            }
        });

    StringBuilder builder = new StringBuilder("NaNaNa");
    for (int x = 0; x < 50; x++) {
        builder.append(" NaNaNa ");
    }
    request = builder.toString();

    URL wsdl = AsyncHTTPConduitTest.class.getResource("/wsdl/hello_world_services.wsdl");
    assertNotNull("WSDL is null", wsdl);

    SOAPService service = new SOAPService();
    assertNotNull("Service is null", service);

    g = service.getSoapPort();
    assertNotNull("Port is null", g);
}