use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.
the class WSDLServiceBuilderTest method testBindingMessageInfo.
@Test
public void testBindingMessageInfo() throws Exception {
setUpBasic();
BindingInfo bindingInfo = serviceInfo.getBindings().iterator().next();
QName name = new QName(serviceInfo.getName().getNamespaceURI(), "sayHi");
BindingOperationInfo sayHi = bindingInfo.getOperation(name);
BindingMessageInfo input = sayHi.getInput();
assertNotNull(input);
assertEquals(input.getMessageInfo().getName().getLocalPart(), "sayHiRequest");
assertEquals(input.getMessageInfo().getName().getNamespaceURI(), "http://apache.org/hello_world_soap_http");
assertEquals(input.getMessageInfo().getMessageParts().size(), 1);
assertEquals(input.getMessageInfo().getMessageParts().get(0).getName().getLocalPart(), "in");
assertEquals(input.getMessageInfo().getMessageParts().get(0).getName().getNamespaceURI(), "http://apache.org/hello_world_soap_http");
assertTrue(input.getMessageInfo().getMessageParts().get(0).isElement());
QName elementName = input.getMessageInfo().getMessageParts().get(0).getElementQName();
assertEquals(elementName.getLocalPart(), "sayHi");
assertEquals(elementName.getNamespaceURI(), "http://apache.org/hello_world_soap_http/types");
BindingMessageInfo output = sayHi.getOutput();
assertNotNull(output);
assertEquals(output.getMessageInfo().getName().getLocalPart(), "sayHiResponse");
assertEquals(output.getMessageInfo().getName().getNamespaceURI(), "http://apache.org/hello_world_soap_http");
assertEquals(output.getMessageInfo().getMessageParts().size(), 1);
assertEquals(output.getMessageInfo().getMessageParts().get(0).getName().getLocalPart(), "out");
assertEquals(output.getMessageInfo().getMessageParts().get(0).getName().getNamespaceURI(), "http://apache.org/hello_world_soap_http");
assertTrue(output.getMessageInfo().getMessageParts().get(0).isElement());
elementName = output.getMessageInfo().getMessageParts().get(0).getElementQName();
assertEquals(elementName.getLocalPart(), "sayHiResponse");
assertEquals(elementName.getNamespaceURI(), "http://apache.org/hello_world_soap_http/types");
assertTrue(sayHi.getFaults().isEmpty());
name = new QName(serviceInfo.getName().getNamespaceURI(), "pingMe");
BindingOperationInfo pingMe = bindingInfo.getOperation(name);
assertNotNull(pingMe);
assertEquals(1, pingMe.getFaults().size());
BindingFaultInfo fault = pingMe.getFaults().iterator().next();
assertNotNull(fault);
assertEquals(fault.getFaultInfo().getName().getLocalPart(), "pingMeFault");
assertEquals(fault.getFaultInfo().getName().getNamespaceURI(), "http://apache.org/hello_world_soap_http");
assertEquals(fault.getFaultInfo().getMessageParts().size(), 1);
assertEquals(fault.getFaultInfo().getMessageParts().get(0).getName().getLocalPart(), "faultDetail");
assertEquals(fault.getFaultInfo().getMessageParts().get(0).getName().getNamespaceURI(), "http://apache.org/hello_world_soap_http");
assertTrue(fault.getFaultInfo().getMessageParts().get(0).isElement());
elementName = fault.getFaultInfo().getMessageParts().get(0).getElementQName();
assertEquals(elementName.getLocalPart(), "faultDetail");
assertEquals(elementName.getNamespaceURI(), "http://apache.org/hello_world_soap_http/types");
control.verify();
}
use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.
the class Wsdl11AttachmentPolicyProvider method getEffectivePolicy.
public Policy getEffectivePolicy(BindingFaultInfo bfi, Message m) {
ServiceInfo si = bfi.getBindingOperation().getBinding().getService();
DescriptionInfo di = si.getDescription();
Policy p = getElementPolicy(bfi, false, di);
FaultInfo fi = bfi.getFaultInfo();
p = mergePolicies(p, getElementPolicy(fi, true, di));
Extensible ex = getMessageTypeInfo(fi.getName(), di);
p = mergePolicies(p, getElementPolicy(ex, false, di));
return p;
}
use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.
the class ServerPolicyOutFaultInterceptor method handle.
protected void handle(Message msg) {
if (MessageUtils.isRequestor(msg)) {
LOG.fine("Is a requestor.");
return;
}
Exchange exchange = msg.getExchange();
assert null != exchange;
BindingOperationInfo boi = exchange.getBindingOperationInfo();
if (null == boi) {
LOG.fine("No binding operation info.");
return;
}
Endpoint e = exchange.getEndpoint();
if (null == e) {
LOG.fine("No endpoint.");
return;
}
EndpointInfo ei = e.getEndpointInfo();
Bus bus = exchange.getBus();
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
if (null == pe) {
return;
}
Destination destination = exchange.getDestination();
Exception ex = exchange.get(Exception.class);
List<Interceptor<? extends Message>> faultInterceptors = new ArrayList<>();
Collection<Assertion> assertions = new ArrayList<>();
// 1. Check overridden policy
Policy p = (Policy) msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
if (p != null) {
EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
effectivePolicy.initialise(endpi, pe, false, true, msg);
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
faultInterceptors.addAll(effectivePolicy.getInterceptors());
assertions.addAll(effectivePolicy.getChosenAlternative());
} else {
// 2. Process effective server policy
BindingFaultInfo bfi = getBindingFaultInfo(msg, ex, boi);
if (bfi == null && msg.get(FaultMode.class) != FaultMode.UNCHECKED_APPLICATION_FAULT && msg.get(FaultMode.class) != FaultMode.CHECKED_APPLICATION_FAULT) {
return;
}
EffectivePolicy effectivePolicy = pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination, msg);
if (effectivePolicy != null) {
faultInterceptors.addAll(effectivePolicy.getInterceptors());
assertions.addAll(effectivePolicy.getChosenAlternative());
}
}
// add interceptors into message chain
for (Interceptor<? extends Message> oi : faultInterceptors) {
msg.getInterceptorChain().add(oi);
LOG.log(Level.FINE, "Added interceptor of type {0}", oi.getClass().getSimpleName());
}
// insert assertions of the chosen alternative into the message
if (!assertions.isEmpty()) {
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
}
}
use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.
the class EffectivePolicyImplTest method testInitialiseFault.
@Test
public void testInitialiseFault() throws NoSuchMethodException {
Method m1 = EffectivePolicyImpl.class.getDeclaredMethod("initialisePolicy", new Class[] { EndpointInfo.class, BindingOperationInfo.class, BindingFaultInfo.class, PolicyEngine.class, Message.class });
Method m2 = EffectivePolicyImpl.class.getDeclaredMethod("chooseAlternative", new Class[] { PolicyEngine.class, Assertor.class, Message.class });
Method m3 = EffectivePolicyImpl.class.getDeclaredMethod("initialiseInterceptors", new Class[] { PolicyEngine.class, Message.class });
EffectivePolicyImpl effectivePolicy = EasyMock.createMockBuilder(EffectivePolicyImpl.class).addMockedMethods(m1, m2, m3).createMock(control);
EndpointInfo ei = control.createMock(EndpointInfo.class);
BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
PolicyEngineImpl pe = new PolicyEngineImpl();
Assertor a = control.createMock(Assertor.class);
effectivePolicy.initialisePolicy(ei, null, bfi, pe, null);
EasyMock.expectLastCall();
effectivePolicy.chooseAlternative(pe, a, null);
EasyMock.expectLastCall();
effectivePolicy.initialiseInterceptors(pe, false, msg);
EasyMock.expectLastCall();
control.replay();
effectivePolicy.initialise(ei, null, bfi, pe, a, null);
control.verify();
}
use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.
the class PolicyInterceptorsTest method testServerPolicyOutFaultInterceptor.
@Test
public void testServerPolicyOutFaultInterceptor() throws NoSuchMethodException {
Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getBindingFaultInfo", new Class[] { Message.class, Exception.class, BindingOperationInfo.class });
ServerPolicyOutFaultInterceptor interceptor = EasyMock.createMockBuilder(ServerPolicyOutFaultInterceptor.class).addMockedMethod(m).createMock(control);
doTestBasics(interceptor, false, true);
control.reset();
setupMessage(false, false, true, true, true, true);
Exception ex = control.createMock(Exception.class);
EasyMock.expect(exchange.get(Exception.class)).andReturn(ex);
EasyMock.expect(interceptor.getBindingFaultInfo(message, ex, boi)).andReturn(null);
control.replay();
interceptor.handleMessage(message);
control.verify();
control.reset();
setupMessage(false, false, true, true, true, true);
// Exception ex = control.createMock(Exception.class);
EasyMock.expect(exchange.get(Exception.class)).andReturn(ex);
BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
EasyMock.expect(interceptor.getBindingFaultInfo(message, ex, boi)).andReturn(bfi);
EffectivePolicy effectivePolicy = control.createMock(EffectivePolicyImpl.class);
EasyMock.expect(pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination, message)).andReturn(effectivePolicy);
List<Interceptor<? extends Message>> li = createMockInterceptorList();
EasyMock.expect(effectivePolicy.getInterceptors()).andReturn(li);
InterceptorChain ic = control.createMock(InterceptorChain.class);
EasyMock.expect(message.getInterceptorChain()).andReturn(ic);
ic.add(li.get(0));
EasyMock.expectLastCall();
Collection<Assertion> assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class);
EasyMock.expect(effectivePolicy.getChosenAlternative()).andReturn(assertions);
control.replay();
interceptor.handleMessage(message);
control.verify();
}
Aggregations