Search in sources :

Example 6 with BindingFaultInfo

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();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) QName(javax.xml.namespace.QName) BindingInfo(org.apache.cxf.service.model.BindingInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) Test(org.junit.Test)

Example 7 with BindingFaultInfo

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;
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Policy(org.apache.neethi.Policy) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) Extensible(org.apache.cxf.service.model.Extensible) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo)

Example 8 with BindingFaultInfo

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));
    }
}
Also used : Policy(org.apache.neethi.Policy) Bus(org.apache.cxf.Bus) Destination(org.apache.cxf.transport.Destination) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) Assertion(org.apache.neethi.Assertion) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) FaultMode(org.apache.cxf.message.FaultMode) Endpoint(org.apache.cxf.endpoint.Endpoint) Interceptor(org.apache.cxf.interceptor.Interceptor) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 9 with BindingFaultInfo

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();
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Method(java.lang.reflect.Method) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) Test(org.junit.Test)

Example 10 with BindingFaultInfo

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();
}
Also used : InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) Method(java.lang.reflect.Method) Interceptor(org.apache.cxf.interceptor.Interceptor) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) Test(org.junit.Test)

Aggregations

BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)31 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)15 Test (org.junit.Test)13 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)9 QName (javax.xml.namespace.QName)6 BindingInfo (org.apache.cxf.service.model.BindingInfo)5 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)5 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)5 Method (java.lang.reflect.Method)4 Bus (org.apache.cxf.Bus)4 Message (org.apache.cxf.message.Message)4 FaultInfo (org.apache.cxf.service.model.FaultInfo)4 Policy (org.apache.neethi.Policy)4 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)3 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)3 ArrayList (java.util.ArrayList)2 BindingFault (javax.wsdl.BindingFault)2 UnknownExtensibilityElement (javax.wsdl.extensions.UnknownExtensibilityElement)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 Interceptor (org.apache.cxf.interceptor.Interceptor)2