use of org.apache.cxf.feature.Feature in project cxf by apache.
the class BusDefinitionParserTest method testFeatures.
@Test
@SuppressWarnings("deprecation")
public void testFeatures() {
String cfgFile = "org/apache/cxf/bus/spring/bus.xml";
Bus bus = new SpringBusFactory().createBus(cfgFile, true);
List<Interceptor<? extends Message>> in = bus.getInInterceptors();
assertTrue("could not find logging interceptor.", in.stream().anyMatch(i -> i.getClass() == org.apache.cxf.interceptor.LoggingInInterceptor.class));
Collection<Feature> features = bus.getFeatures();
TestFeature tf = null;
for (Feature f : features) {
if (f instanceof TestFeature) {
tf = (TestFeature) f;
break;
}
}
assertNotNull(tf);
assertTrue("test feature has not been initialised", tf.initialised);
assertNotNull("test feature has not been injected", tf.testBean);
assertTrue("bean injected into test feature has not been initialised", tf.testBean.initialised);
}
use of org.apache.cxf.feature.Feature in project cxf by apache.
the class DispatchImpl method calculateOpName.
@SuppressWarnings("unchecked")
private QName calculateOpName(Holder<T> holder, QName opName, boolean hasOpName) throws XMLStreamException {
boolean findDispatchOp = Boolean.TRUE.equals(getRequestContext().get("find.dispatch.operation"));
// if the addressing feature is enabled, set findDispatchOp to true
if (!findDispatchOp) {
// the feature list to be searched is the endpoint and the bus's lists
List<Feature> endpointFeatures = ((JaxWsClientEndpointImpl) client.getEndpoint()).getFeatures();
List<Feature> allFeatures;
if (client.getBus().getFeatures() != null) {
allFeatures = new ArrayList<>(endpointFeatures.size() + client.getBus().getFeatures().size());
allFeatures.addAll(endpointFeatures);
allFeatures.addAll(client.getBus().getFeatures());
} else {
allFeatures = endpointFeatures;
}
for (Feature feature : allFeatures) {
if (feature instanceof WSAddressingFeature) {
findDispatchOp = true;
}
}
}
Source createdSource = null;
Map<String, QName> payloadOPMap = createPayloadEleOpNameMap(client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
if (findDispatchOp && !payloadOPMap.isEmpty()) {
QName payloadElementName = null;
if (holder.value instanceof javax.xml.transform.Source) {
XMLStreamReader reader = null;
try {
reader = StaxUtils.createXMLStreamReader((javax.xml.transform.Source) holder.value);
Document document = StaxUtils.read(reader);
createdSource = new StaxSource(StaxUtils.createXMLStreamReader(document));
payloadElementName = getPayloadElementName(document.getDocumentElement());
} catch (Exception e) {
// ignore, we are trying to get the operation name
} finally {
StaxUtils.close(reader);
}
}
if (holder.value instanceof SOAPMessage) {
payloadElementName = getPayloadElementName((SOAPMessage) holder.value);
}
if (this.context != null) {
payloadElementName = getPayloadElementName(holder.value);
}
if (payloadElementName != null) {
if (hasOpName) {
// Verify the payload element against the given operation name.
// This allows graceful handling of non-standard WSDL definitions
// where different operations have the same payload element.
QName expectedElementName = payloadOPMap.get(opName.toString());
if (expectedElementName == null || !expectedElementName.toString().equals(payloadElementName.toString())) {
// Verification of the provided operation name failed.
// Resolve the operation name from the payload element.
hasOpName = false;
payloadOPMap = createPayloadEleOpNameMap(client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
}
}
QName dispatchedOpName = null;
if (!hasOpName) {
dispatchedOpName = payloadOPMap.get(payloadElementName.toString());
}
if (null != dispatchedOpName) {
BindingOperationInfo dbop = client.getEndpoint().getBinding().getBindingInfo().getOperation(dispatchedOpName);
if (dbop != null) {
opName = dispatchedOpName;
}
}
}
}
if (createdSource != null) {
holder.value = (T) createdSource;
}
return opName;
}
use of org.apache.cxf.feature.Feature in project cxf by apache.
the class ServiceImpl method createDispatch.
public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, JAXBContext context, Mode mode, WebServiceFeature... features) {
// using this instead of JaxWsClientFactoryBean so that handlers are configured
JaxWsProxyFactoryBean clientFac = new JaxWsProxyFactoryBean();
// Initialize Features.
configureObject(portName.toString() + ".jaxws-client.proxyFactory", clientFac);
final AbstractServiceFactoryBean sf;
try {
DataBinding db;
if (context != null) {
db = new JAXBDataBinding(context);
} else {
db = new SourceDataBinding(type);
}
sf = createDispatchService(db);
} catch (ServiceConstructionException e) {
throw new WebServiceException(e);
}
JaxWsEndpointImpl endpoint = getJaxwsEndpoint(portName, sf, features);
// if the client factory has properties specified, then set those into the endpoint
if (clientFac.getProperties() != null) {
endpoint.putAll(clientFac.getProperties());
}
// add all the client factory features onto the endpoint feature list
endpoint.getFeatures().addAll(clientFac.getFeatures());
// if the client factory has a bus specified (other than the thread default),
// then use that for the client. Otherwise use the bus from this service.
Bus clientBus = getBus();
if (clientFac.getBus() != BusFactory.getThreadDefaultBus(false) && clientFac.getBus() != null) {
clientBus = clientFac.getBus();
}
@SuppressWarnings("rawtypes") List<Handler> hc = clientFac.getHandlers();
// CXF-3956
hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
endpoint.getJaxwsBinding().setHandlerChain(hc);
// create the client object, then initialize the endpoint features against it
Client client = new ClientImpl(clientBus, endpoint, clientFac.getConduitSelector());
for (Feature af : endpoint.getFeatures()) {
af.initialize(client, clientBus);
}
// CXF-2822
initIntercepors(client, clientFac);
if (executor != null) {
client.getEndpoint().setExecutor(executor);
}
// then try to get it from the wsdl
if (!StringUtils.isEmpty(clientFac.getAddress())) {
client.getEndpoint().getEndpointInfo().setAddress(clientFac.getAddress());
} else {
// Set the the EPR's address in EndpointInfo
PortInfoImpl portInfo = portInfos.get(portName);
if (portInfo != null && !StringUtils.isEmpty(portInfo.getAddress())) {
client.getEndpoint().getEndpointInfo().setAddress(portInfo.getAddress());
}
}
Dispatch<T> disp = new DispatchImpl<>(client, mode, context, type);
configureObject(disp);
return disp;
}
use of org.apache.cxf.feature.Feature in project tesb-rt-se by Talend.
the class StsConfigurator method removeMessageLogging.
private void removeMessageLogging(Bus bus) {
Collection<Feature> features = bus.getFeatures();
Feature logFeature = null;
Interceptor inLogInterceptor = null;
Interceptor outLogInterceptor = null;
for (Feature feature : features) {
if (feature instanceof LoggingFeature) {
logFeature = feature;
break;
}
}
if (logFeature != null) {
features.remove(logFeature);
}
for (Interceptor interceptor : bus.getInInterceptors()) {
if (interceptor instanceof LoggingInInterceptor) {
inLogInterceptor = interceptor;
break;
}
}
for (Interceptor interceptor : bus.getOutInterceptors()) {
if (interceptor instanceof LoggingOutInterceptor) {
outLogInterceptor = interceptor;
break;
}
}
if (inLogInterceptor != null) {
bus.getInInterceptors().remove(inLogInterceptor);
// System.out.println("\nRemove in Interceptor = " + inLogInterceptor.getClass().getName());
}
if (outLogInterceptor != null) {
bus.getOutInterceptors().remove(outLogInterceptor);
// System.out.println("\nRemove out Interceptor = " + inLogInterceptor.getClass().getName());
}
}
use of org.apache.cxf.feature.Feature in project tesb-rt-se by Talend.
the class StsConfiguratorTest method getBus.
private Bus getBus() {
Collection<Feature> features = new ArrayList<Feature>();
features.add(new LoggingFeature());
List<Interceptor<? extends Message>> inInterceptors = new ArrayList<Interceptor<? extends Message>>();
inInterceptors.add(new LoggingInInterceptor());
List<Interceptor<? extends Message>> inFaultInterceptors = new ArrayList<Interceptor<? extends Message>>();
inFaultInterceptors.add(new LoggingInInterceptor());
List<Interceptor<? extends Message>> outInterceptors = new ArrayList<Interceptor<? extends Message>>();
outInterceptors.add(new LoggingOutInterceptor());
List<Interceptor<? extends Message>> outFaultInterceptors = new ArrayList<Interceptor<? extends Message>>();
outFaultInterceptors.add(new LoggingOutInterceptor());
Bus bus = createMock(Bus.class);
expect(bus.getFeatures()).andReturn(features).anyTimes();
expect(bus.getInInterceptors()).andReturn(inInterceptors).anyTimes();
expect(bus.getOutInterceptors()).andReturn(outInterceptors).anyTimes();
expect(bus.getInFaultInterceptors()).andReturn(inFaultInterceptors).anyTimes();
expect(bus.getOutFaultInterceptors()).andReturn(outFaultInterceptors).anyTimes();
replay(bus);
return bus;
}
Aggregations