org.apache.cxf.feature.AbstractFeature Java Examples

The following examples show how to use org.apache.cxf.feature.AbstractFeature. 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: JaxWsBeanPostProcessor.java    From bearchoke with Apache License 2.0 6 votes vote down vote up
@Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (isWebService(bean)) {
            Bus bus = beanFactory.getBean(Bus.DEFAULT_BUS_ID, Bus.class);
            EndpointDefinitionParser.SpringEndpointImpl endpoint = new EndpointDefinitionParser.SpringEndpointImpl(bus, bean);

            WebService ws = bean.getClass().getAnnotation(WebService.class);
            endpoint.setAddress("/" + ws.serviceName());

            // capitalization is just a nice feature - totally optional
//            endpoint.setAddress("/" + StringUtils.capitalize(beanName));

            // adds ALL features registered / discovered by Spring
            Map<String, AbstractFeature> featureMap = beanFactory.getBeansOfType(AbstractFeature.class);
            endpoint.getFeatures().addAll(featureMap.values());

            // publish bean
            endpoint.publish();
        }

        return bean;
    }
 
Example #2
Source File: JAXRSSoapBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddFeatureToClient() throws Exception {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(baseAddress);
    bean.setResourceClass(BookStoreJaxrsJaxws.class);
    TestFeature testFeature = new TestFeature();
    List<AbstractFeature> features = new ArrayList<>();
    features.add(testFeature);
    bean.setFeatures(features);
    BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws)bean.create();
    Book b = proxy.getBook(Long.valueOf("123"));
    assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled());
    assertTrue("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
    assertEquals(123, b.getId());
    assertEquals("CXF in Action", b.getName());
}
 
Example #3
Source File: JAXRSSoapBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testClientFaultOutInterceptor() throws Exception {
    //testing faults created by client out interceptor chain handled correctly
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(baseAddress);
    bean.setResourceClass(BookStoreJaxrsJaxws.class);
    final boolean addBadOutInterceptor = true;
    TestFeature testFeature = new TestFeature(addBadOutInterceptor);
    List<AbstractFeature> features = new ArrayList<>();
    features.add(testFeature);
    bean.setFeatures(features);
    BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws)bean.create();
    try {
        //321 is special case - causes error code of 525
        proxy.getBook(Long.valueOf("123"));
        fail("Method should have thrown an exception");
    } catch (Exception e) {
        assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled());
        assertFalse("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
        assertTrue("Wrong exception caught",
                   "fault from bad interceptor".equals(e.getCause().getMessage()));
        assertTrue("Client In Fault In Interceptor was invoked",
                testFeature.faultInInterceptorCalled());
    }
}
 
Example #4
Source File: AmbariClientBuilder.java    From components with Apache License 2.0 5 votes vote down vote up
/**
 * Build a client proxy, for a specific proxy type.
 * 
 * @param proxyType proxy type class
 * @return client proxy stub
 */
protected <T> T build(Class<T> proxyType) {
    String address = generateAddress();
    T rootResource;
    // Synchronized on the class to correlate with the scope of clientStaticResources
    // We want to ensure that the shared bean isn't set concurrently in multiple callers
    synchronized (AmbariClientBuilder.class) {
        JAXRSClientFactoryBean bean = cleanFactory(clientStaticResources.getUnchecked(proxyType));
        bean.setAddress(address);
        if (username != null) {
            bean.setUsername(username);
            bean.setPassword(password);
        }

        if (enableLogging) {
            bean.setFeatures(Arrays.<AbstractFeature> asList(new LoggingFeature()));
        }
        rootResource = bean.create(proxyType);
    }

    boolean isTlsEnabled = address.startsWith("https://");
    ClientConfiguration config = WebClient.getConfig(rootResource);
    HTTPConduit conduit = (HTTPConduit) config.getConduit();
    if (isTlsEnabled) {
        TLSClientParameters tlsParams = new TLSClientParameters();
        if (!validateCerts) {
            tlsParams.setTrustManagers(new TrustManager[] { new AcceptAllTrustManager() });
        } else if (trustManagers != null) {
            tlsParams.setTrustManagers(trustManagers);
        }
        tlsParams.setDisableCNCheck(!validateCn);
        conduit.setTlsClientParameters(tlsParams);
    }

    HTTPClientPolicy policy = conduit.getClient();
    policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout));
    policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout));
    return rootResource;
}
 
Example #5
Source File: LoadDistributorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected JAXRSClientFactoryBean createBean(String address,
                                            FailoverFeature feature) {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(address);
    List<AbstractFeature> features = new ArrayList<>();
    features.add(feature);
    bean.setFeatures(features);

    return bean;
}
 
Example #6
Source File: JAXRSSoapBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void serverFaultInInterceptorTest(String param) {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(baseAddress);
    bean.setResourceClass(BookStoreJaxrsJaxws.class);
    TestFeature testFeature = new TestFeature();
    List<AbstractFeature> features = new ArrayList<>();
    features.add(testFeature);
    bean.setFeatures(features);
    BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws)bean.create();
    WebClient.getConfig(proxy).getRequestContext().put("org.apache.cxf.transport.no_io_exceptions", false);
    try {
        //321 is special case - causes error code of 525
        proxy.getBook(Long.valueOf(param));
        fail("Method should have thrown an exception");
    } catch (Exception e) {
        assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled());
        if ("322".equals(param)) {
            //In interceptors not called when checked exception thrown from server
            assertTrue("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
        } else {
            assertFalse("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
        }
        assertTrue("Client In Fault In Interceptor not invoked",
                testFeature.faultInInterceptorCalled());
    }
}
 
Example #7
Source File: CxfUtil.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static List<Feature> createFeatures(final Collection<ServiceInfo> availableServices, final String featuresIds) {
    final List<?> features = ServiceInfos.resolve(availableServices, featuresIds.split(","));
    for (final Object instance : features) {
        if (!AbstractFeature.class.isInstance(instance)) {
            throw new OpenEJBRuntimeException("feature should inherit from " + AbstractFeature.class.getName());
        }
    }
    return (List<Feature>) features;
}
 
Example #8
Source File: ProtobufServerFactoryBean.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
protected void applyFeatures() {
    if (getFeatures() != null) {
        for (AbstractFeature feature : getFeatures()) {
            feature.initialize(server, getBus());
        }
    }
}
 
Example #9
Source File: AmbariClientBuilder.java    From components with Apache License 2.0 4 votes vote down vote up
private static JAXRSClientFactoryBean cleanFactory(JAXRSClientFactoryBean bean) {
    bean.setUsername(null);
    bean.setPassword(null);
    bean.setFeatures(Arrays.<AbstractFeature> asList());
    return bean;
}
 
Example #10
Source File: SimpleBatchSTSClient.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void setFeatures(List<AbstractFeature> f) {
    features = f;
}
 
Example #11
Source File: SimpleBatchSTSClient.java    From cxf with Apache License 2.0 4 votes vote down vote up
public List<AbstractFeature> getFeatures() {
    return features;
}