use of org.apache.cxf.binding.BindingFactoryManager in project cxf by apache.
the class Wsdl11AttachmentPolicyProviderTest method oneTimeSetUp.
@BeforeClass
public static void oneTimeSetUp() throws Exception {
IMocksControl control = EasyMock.createNiceControl();
Bus bus = control.createMock(Bus.class);
WSDLManager manager = new WSDLManagerImpl();
WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(dfm).anyTimes();
EasyMock.expect(dfm.getDestinationFactory(EasyMock.isA(String.class))).andReturn(null).anyTimes();
BindingFactoryManager bfm = control.createMock(BindingFactoryManager.class);
EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm).anyTimes();
EasyMock.expect(bfm.getBindingFactory(EasyMock.isA(String.class))).andReturn(null).anyTimes();
control.replay();
int n = 19;
services = new ServiceInfo[n];
endpoints = new EndpointInfo[n];
for (int i = 0; i < n; i++) {
String resourceName = "/attachment/wsdl11/test" + i + ".wsdl";
URL url = Wsdl11AttachmentPolicyProviderTest.class.getResource(resourceName);
try {
services[i] = builder.buildServices(manager.getDefinition(url.toString())).get(0);
} catch (WSDLException ex) {
ex.printStackTrace();
fail("Failed to build service from resource " + resourceName);
}
assertNotNull(services[i]);
endpoints[i] = services[i].getEndpoints().iterator().next();
assertNotNull(endpoints[i]);
}
control.verify();
}
use of org.apache.cxf.binding.BindingFactoryManager in project tomee by apache.
the class CxfUtil method initDefaultBus.
private static Bus initDefaultBus() {
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(CxfUtil.class.getClassLoader());
try {
// create the bus reusing cxf logic but skipping factory lookup
final Bus bus = BusFactory.newInstance(CXFBusFactory.class.getName()).createBus();
bus.setId(SystemInstance.get().getProperty("openejb.cxf.bus.id", "openejb.cxf.bus"));
final BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
bindingFactoryMap = (Map<String, BindingFactory>) Reflections.get(bfm, "bindingFactories");
bus.setExtension(new OpenEJBHttpDestinationFactory(), HttpDestinationFactory.class);
// ensure client proxies can use app classes
CXFBusFactory.setDefaultBus(Bus.class.cast(Proxy.newProxyInstance(CxfUtil.class.getClassLoader(), new Class<?>[] { Bus.class }, new ClientAwareBusHandler())));
bus.setProperty(ClassUnwrapper.class.getName(), new ClassUnwrapper() {
@Override
public Class<?> getRealClass(final Object o) {
final Class<?> aClass = o.getClass();
Class<?> c = aClass;
while (c.getName().contains("$$")) {
c = c.getSuperclass();
}
return c == Object.class ? aClass : c;
}
@Override
public Class<?> getRealClassFromClass(Class<?> aClass) {
return aClass;
}
@Override
public Object getRealObject(Object o) {
// straight on the proxy
if (o instanceof OwbInterceptorProxy) {
return getProxiedInstance(o);
}
return o;
}
private Object getProxiedInstance(Object o) {
try {
final Field field = o.getClass().getDeclaredField(FIELD_INTERCEPTOR_HANDLER);
field.setAccessible(true);
final Object fieldValue = field.get(o);
if (fieldValue instanceof DefaultInterceptorHandler) {
final DefaultInterceptorHandler handler = (DefaultInterceptorHandler) fieldValue;
return handler.getTarget();
} else {
throw new IllegalStateException("Expected OwbInterceptorProxy handler to be an instance of Default Interceptor Handler.");
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
});
SystemInstance.get().addObserver(new LifecycleManager());
initAuthenticators();
// we keep as internal the real bus and just expose to cxf the client aware bus to be able to cast it easily
return bus;
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
use of org.apache.cxf.binding.BindingFactoryManager in project tomee by apache.
the class CxfRSService method init.
@Override
public void init(final Properties properties) throws Exception {
super.init(properties);
config = properties;
factoryByListener = "true".equalsIgnoreCase(properties.getProperty("openejb.cxf-rs.factoryByListener", "false"));
System.setProperty("org.apache.johnzon.max-string-length", SystemInstance.get().getProperty("org.apache.johnzon.max-string-length", properties.getProperty("org.apache.johnzon.max-string-length", "8192")));
SystemInstance.get().setComponent(RESTResourceFinder.class, new CxfRESTResourceFinder());
try {
CUTask.addContainerListener(new CUTask.ContainerListener() {
@Override
public Object onCreation() {
return Contexts.state();
}
@Override
public Object onStart(final Object state) {
return Contexts.restore(state);
}
@Override
public void onEnd(final Object oldState) {
Contexts.restore(oldState);
}
});
} catch (final Throwable th) {
// unlikely but means the container core has been customized so just ignore it
}
CxfUtil.configureBus();
final Bus bus = CxfUtil.getBus();
final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader());
try {
// force init of bindings
if (!CxfUtil.hasService(JAXRSBindingFactory.JAXRS_BINDING_ID)) {
// cxf does it but with the pattern "if not here install it". It is slow so installing it without testing for presence here.
final BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
try {
bfm.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, new JAXRSBindingFactory(bus));
} catch (Throwable b) {
// no-op
}
}
initCxfProviders(bus);
} finally {
if (oldLoader != null) {
CxfUtil.clearBusLoader(oldLoader);
}
}
}
use of org.apache.cxf.binding.BindingFactoryManager in project cxf by apache.
the class CXFBusImplTest method testConstructionWithExtensions.
@Test
public void testConstructionWithExtensions() throws BusException {
IMocksControl control;
BindingFactoryManager bindingFactoryManager;
InstrumentationManager instrumentationManager;
PhaseManager phaseManager;
control = EasyMock.createNiceControl();
Map<Class<?>, Object> extensions = new HashMap<>();
bindingFactoryManager = control.createMock(BindingFactoryManager.class);
instrumentationManager = control.createMock(InstrumentationManager.class);
phaseManager = control.createMock(PhaseManager.class);
extensions.put(BindingFactoryManager.class, bindingFactoryManager);
extensions.put(InstrumentationManager.class, instrumentationManager);
extensions.put(PhaseManager.class, phaseManager);
Bus bus = new ExtensionManagerBus(extensions);
assertSame(bindingFactoryManager, bus.getExtension(BindingFactoryManager.class));
assertSame(instrumentationManager, bus.getExtension(InstrumentationManager.class));
assertSame(phaseManager, bus.getExtension(PhaseManager.class));
}
use of org.apache.cxf.binding.BindingFactoryManager in project cxf by apache.
the class DocLiteralInInterceptorTest method setUp.
@Before
public void setUp() throws Exception {
bus = BusFactory.newInstance().createBus();
BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
IMocksControl control = createNiceControl();
BindingFactory bf = control.createMock(BindingFactory.class);
Binding binding = control.createMock(Binding.class);
expect(bf.createBinding(null)).andStubReturn(binding);
expect(binding.getInFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
expect(binding.getOutFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
bfm.registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bf);
}
Aggregations