use of org.apache.cxf.binding.BindingFactory in project cxf by apache.
the class WSDLServiceBuilder method buildBinding.
public BindingInfo buildBinding(ServiceInfo service, Binding binding) {
BindingInfo bi = null;
StringBuilder ns = new StringBuilder(100);
BindingFactory factory = WSDLServiceUtils.getBindingFactory(binding, bus, ns);
if (factory instanceof WSDLBindingFactory) {
WSDLBindingFactory wFactory = (WSDLBindingFactory) factory;
bi = wFactory.createBindingInfo(service, binding, ns.toString());
copyExtensors(bi, binding.getExtensibilityElements());
copyExtensionAttributes(bi, binding);
}
if (bi == null) {
boolean onlyExtensors = false;
if (factory instanceof AbstractBindingFactory) {
bi = ((AbstractBindingFactory) factory).createBindingInfo(service, ns.toString(), null);
onlyExtensors = true;
} else {
bi = new BindingInfo(service, ns.toString());
}
bi.setName(binding.getQName());
copyExtensors(bi, binding.getExtensibilityElements());
copyExtensionAttributes(bi, binding);
for (BindingOperation bop : cast(binding.getBindingOperations(), BindingOperation.class)) {
if (LOG.isLoggable(Level.FINER)) {
LOG.finer("binding operation name is " + bop.getName());
}
String inName = null;
String outName = null;
if (bop.getBindingInput() != null) {
inName = bop.getBindingInput().getName();
}
if (bop.getBindingOutput() != null) {
outName = bop.getBindingOutput().getName();
}
final BindingOperationInfo bop2;
if (onlyExtensors) {
bop2 = bi.getOperation(new QName(binding.getQName().getNamespaceURI(), bop.getName()));
} else {
bop2 = bi.buildOperation(new QName(binding.getQName().getNamespaceURI(), bop.getName()), inName, outName);
if (bop2 != null) {
bi.addOperation(bop2);
}
}
if (bop2 != null) {
copyExtensors(bop2, bop.getExtensibilityElements());
copyExtensionAttributes(bop2, bop);
if (bop.getBindingInput() != null) {
copyExtensors(bop2.getInput(), bop.getBindingInput().getExtensibilityElements());
copyExtensionAttributes(bop2.getInput(), bop.getBindingInput());
handleHeader(bop2.getInput());
}
if (bop.getBindingOutput() != null) {
copyExtensors(bop2.getOutput(), bop.getBindingOutput().getExtensibilityElements());
copyExtensionAttributes(bop2.getOutput(), bop.getBindingOutput());
handleHeader(bop2.getOutput());
}
for (BindingFault f : cast(bop.getBindingFaults().values(), BindingFault.class)) {
BindingFaultInfo bif = bop2.getFault(new QName(service.getTargetNamespace(), f.getName()));
copyExtensors(bif, bop.getBindingFault(f.getName()).getExtensibilityElements());
copyExtensionAttributes(bif, bop.getBindingFault(f.getName()));
}
}
}
}
service.addBinding(bi);
DescriptionInfo d = service.getDescription();
if (null != d) {
d.getDescribed().add(bi);
}
return bi;
}
use of org.apache.cxf.binding.BindingFactory in project tomee by apache.
the class EndpointImpl method createBinding.
final void createBinding(BindingInfo bi) throws EndpointException {
if (null != bi) {
String namespace = bi.getBindingId();
try {
final BindingFactory bf = bus.getExtension(BindingFactoryManager.class).getBindingFactory(namespace);
if (null == bf) {
Message msg = new Message("NO_BINDING_FACTORY", BUNDLE, namespace);
throw new EndpointException(msg);
}
binding = bf.createBinding(bi);
} catch (BusException ex) {
throw new EndpointException(ex);
}
}
}
use of org.apache.cxf.binding.BindingFactory 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.BindingFactory in project cxf by apache.
the class TestBase 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);
String ns = "http://apache.org/hello_world_soap_http";
WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/org/apache/cxf/jaxb/resources/wsdl/hello_world.wsdl").toString(), new QName(ns, "SOAPService"));
service = factory.create();
endpointInfo = service.getEndpointInfo(new QName(ns, "SoapPort"));
endpoint = new EndpointImpl(bus, service, endpointInfo);
JAXBDataBinding db = new JAXBDataBinding();
db.setContext(JAXBContext.newInstance(new Class[] { GreetMe.class, GreetMeResponse.class }));
service.setDataBinding(db);
operation = endpointInfo.getBinding().getOperation(new QName(ns, "greetMe"));
operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(GreetMe.class);
operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(GreetMeResponse.class);
message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
exchange.put(Service.class, service);
exchange.put(Endpoint.class, endpoint);
exchange.put(Binding.class, endpoint.getBinding());
}
use of org.apache.cxf.binding.BindingFactory 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