use of org.apache.cxf.Bus in project cxf by apache.
the class PerRequestFactory method create.
public Object create(Exchange ex) throws Throwable {
try {
if (svcClass.isInterface()) {
throw new Fault(new Message("SVC_CLASS_IS_INTERFACE", BUNDLE, svcClass.getName()));
}
if (Modifier.isAbstract(svcClass.getModifiers())) {
throw new Fault(new Message("SVC_CLASS_IS_ABSTRACT", BUNDLE, svcClass.getName()));
}
Object o = svcClass.newInstance();
Bus b = ex.getBus();
ResourceManager resourceManager = b.getExtension(ResourceManager.class);
if (resourceManager != null) {
ResourceInjector injector = new ResourceInjector(resourceManager);
injector.inject(o);
injector.construct(o);
}
return o;
} catch (InstantiationException e) {
throw new Fault(new Message("COULD_NOT_INSTANTIATE", BUNDLE), e);
} catch (IllegalAccessException e) {
throw new Fault(new Message("ILLEGAL_ACCESS", BUNDLE), e);
}
}
use of org.apache.cxf.Bus in project cxf by apache.
the class SAAJInInterceptor method replaceHeaders.
public static void replaceHeaders(SOAPMessage soapMessage, SoapMessage message) throws SOAPException {
SOAPHeader header = SAAJUtils.getHeader(soapMessage);
if (header == null) {
return;
}
Element elem = DOMUtils.getFirstElement(header);
elem = (Element) DOMUtils.getDomElement(elem);
while (elem != null) {
Bus b = message.getExchange() == null ? null : message.getExchange().getBus();
HeaderProcessor p = null;
if (b != null && b.getExtension(HeaderManager.class) != null) {
p = b.getExtension(HeaderManager.class).getHeaderProcessor(elem.getNamespaceURI());
}
Object obj;
DataBinding dataBinding = null;
if (p == null || p.getDataBinding() == null) {
obj = elem;
} else {
dataBinding = p.getDataBinding();
obj = p.getDataBinding().createReader(Node.class).read(elem);
}
SoapHeader shead = new SoapHeader(new QName(elem.getNamespaceURI(), elem.getLocalName()), obj, dataBinding);
shead.setDirection(SoapHeader.Direction.DIRECTION_IN);
String mu = elem.getAttributeNS(message.getVersion().getNamespace(), message.getVersion().getAttrNameMustUnderstand());
String act = elem.getAttributeNS(message.getVersion().getNamespace(), message.getVersion().getAttrNameRole());
shead.setActor(act);
shead.setMustUnderstand(Boolean.valueOf(mu) || "1".equals(mu));
Header oldHdr = message.getHeader(new QName(elem.getNamespaceURI(), elem.getLocalName()));
if (oldHdr != null) {
message.getHeaders().remove(oldHdr);
}
message.getHeaders().add(shead);
elem = DOMUtils.getNextElement(elem);
}
}
use of org.apache.cxf.Bus in project cxf by apache.
the class MustUnderstandInterceptorTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
Bus bus = BusFactory.getDefaultBus();
rhi = new ReadHeadersInterceptor(bus, "phase1");
chain.add(rhi);
sbi = new StartBodyInterceptor("phase1.5");
chain.add(sbi);
mui = new MustUnderstandInterceptor("phase2");
chain.add(mui);
dsi = new DummySoapInterceptor("phase3");
chain.add(dsi);
}
use of org.apache.cxf.Bus in project cxf by apache.
the class ServiceModelUtilTest method setUp.
@Before
public void setUp() throws Exception {
String wsdlUrl = getClass().getResource(WSDL_PATH).toString();
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
wsdlReader.setFeature("javax.wsdl.verbose", false);
def = wsdlReader.readWSDL(wsdlUrl);
WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus);
for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
if (serv != null) {
service = serv;
break;
}
}
control = EasyMock.createNiceControl();
bus = control.createMock(Bus.class);
bindingFactoryManager = control.createMock(BindingFactoryManager.class);
wsdlServiceBuilder = new WSDLServiceBuilder(bus);
EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager);
DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
control.replay();
serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
}
use of org.apache.cxf.Bus in project cxf by apache.
the class SoapBindingFactoryTest method testFactory.
@Test
public void testFactory() throws Exception {
Definition d = createDefinition("/wsdl_soap/hello_world.wsdl");
Bus bus = getMockBus();
BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);
bus.getExtension(BindingFactoryManager.class);
expectLastCall().andReturn(bfm).anyTimes();
DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
control.replay();
WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
ServiceInfo serviceInfo = builder.buildServices(d, new QName("http://apache.org/hello_world_soap_http", "SOAPService")).get(0);
BindingInfo bi = serviceInfo.getBindings().iterator().next();
assertTrue(bi instanceof SoapBindingInfo);
SoapBindingInfo sbi = (SoapBindingInfo) bi;
assertEquals("document", sbi.getStyle());
assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
assertTrue(sbi.getSoapVersion() instanceof Soap11);
BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap_http", "sayHi"));
SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
assertNotNull(sboi);
assertEquals("document", sboi.getStyle());
assertEquals("", sboi.getAction());
BindingMessageInfo input = boi.getInput();
SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
assertEquals("literal", bodyInfo.getUse());
List<MessagePartInfo> parts = bodyInfo.getParts();
assertNotNull(parts);
assertEquals(1, parts.size());
}
Aggregations