Search in sources :

Example 36 with Exchange

use of org.apache.cxf.message.Exchange in project tomee by apache.

the class ServiceUtils method getSchemaValidationTypeFromModel.

private static SchemaValidationType getSchemaValidationTypeFromModel(Message message) {
    Exchange exchange = message.getExchange();
    SchemaValidationType validationType = null;
    if (exchange != null) {
        BindingOperationInfo boi = exchange.getBindingOperationInfo();
        if (boi != null) {
            OperationInfo opInfo = boi.getOperationInfo();
            if (opInfo != null) {
                validationType = getSchemaValidationTypeFromModel(opInfo);
            }
        }
        if (validationType == null) {
            Endpoint endpoint = exchange.getEndpoint();
            if (endpoint != null) {
                EndpointInfo ep = endpoint.getEndpointInfo();
                if (ep != null) {
                    validationType = getSchemaValidationTypeFromModel(ep);
                }
            }
        }
    }
    return validationType;
}
Also used : Exchange(org.apache.cxf.message.Exchange) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) SchemaValidationType(org.apache.cxf.annotations.SchemaValidation.SchemaValidationType)

Example 37 with Exchange

use of org.apache.cxf.message.Exchange in project tomee by apache.

the class ClientImpl method getConduit.

public Conduit getConduit() {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    message.putAll(getRequestContext());
    setExchangeProperties(exchange, getEndpoint(), null);
    return getConduitSelector().selectConduit(message);
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 38 with Exchange

use of org.apache.cxf.message.Exchange in project tomee by apache.

the class AbstractFaultChainInitiatorObserver method onMessage.

public void onMessage(Message message) {
    assert null != message;
    Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
    ClassLoaderHolder origLoader = null;
    try {
        if (loader != null) {
            origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
        }
        Exchange exchange = message.getExchange();
        Message faultMessage;
        if (isOutboundObserver()) {
            Exception ex = message.getContent(Exception.class);
            if (!(ex instanceof Fault)) {
                ex = new Fault(ex);
            }
            FaultMode mode = message.get(FaultMode.class);
            faultMessage = exchange.getOutMessage();
            if (null == faultMessage) {
                faultMessage = new MessageImpl();
                faultMessage.setExchange(exchange);
                faultMessage = exchange.getEndpoint().getBinding().createMessage(faultMessage);
            }
            faultMessage.setContent(Exception.class, ex);
            if (null != mode) {
                faultMessage.put(FaultMode.class, mode);
            }
            // CXF-3981
            if (message.get("javax.xml.ws.addressing.context.inbound") != null) {
                faultMessage.put("javax.xml.ws.addressing.context.inbound", message.get("javax.xml.ws.addressing.context.inbound"));
            }
            exchange.setOutMessage(null);
            exchange.setOutFaultMessage(faultMessage);
            if (message.get(BindingFaultInfo.class) != null) {
                faultMessage.put(BindingFaultInfo.class, message.get(BindingFaultInfo.class));
            }
        } else {
            faultMessage = message;
            exchange.setInMessage(null);
            exchange.setInFaultMessage(faultMessage);
        }
        // setup chain
        PhaseInterceptorChain chain = new PhaseInterceptorChain(getPhases());
        initializeInterceptors(faultMessage.getExchange(), chain);
        faultMessage.setInterceptorChain(chain);
        try {
            chain.doIntercept(faultMessage);
        } catch (RuntimeException exc) {
            LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
            throw exc;
        } catch (Exception exc) {
            LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
            throw new RuntimeException(exc);
        }
    } finally {
        if (origBus != bus) {
            BusFactory.setThreadDefaultBus(origBus);
        }
        if (origLoader != null) {
            origLoader.reset();
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) FaultMode(org.apache.cxf.message.FaultMode) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Message(org.apache.cxf.message.Message) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) MessageImpl(org.apache.cxf.message.MessageImpl) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 39 with Exchange

use of org.apache.cxf.message.Exchange in project ddf by codice.

the class PepInterceptorActionsTest method testMessageWithDefaultUriAction.

@Test
public void testMessageWithDefaultUriAction() throws SecurityServiceException {
    SecurityManager mockSecurityManager = mock(SecurityManager.class);
    interceptor.setSecurityManager(mockSecurityManager);
    Message messageWithAction = mock(Message.class);
    SecurityToken mockSecurityToken = mock(SecurityToken.class);
    Subject mockSubject = mock(Subject.class);
    assertNotNull(mockSecurityAssertion);
    // SecurityLogger is already stubbed out
    when(mockSecurityAssertion.getToken()).thenReturn(mockSecurityToken);
    when(mockSecurityToken.getToken()).thenReturn(null);
    when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
    QName op = new QName("urn:catalog:query", "search", "ns1");
    QName port = new QName("urn:catalog:query", "query-port", "ns1");
    when(messageWithAction.get(MessageContext.WSDL_OPERATION)).thenReturn(op);
    when(messageWithAction.get(MessageContext.WSDL_PORT)).thenReturn(port);
    Exchange mockExchange = mock(Exchange.class);
    BindingOperationInfo mockBOI = mock(BindingOperationInfo.class);
    when(messageWithAction.getExchange()).thenReturn(mockExchange);
    when(mockExchange.get(BindingOperationInfo.class)).thenReturn(mockBOI);
    when(mockBOI.getExtensor(SoapOperationInfo.class)).thenReturn(null);
    doAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            CollectionPermission perm = (CollectionPermission) invocation.getArguments()[0];
            assertEquals("urn:catalog:query:query-port:searchRequest", perm.getAction());
            return true;
        }
    }).when(mockSubject).isPermitted(isA(CollectionPermission.class));
    // This should work.
    interceptor.handleMessage(messageWithAction);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SecurityManager(ddf.security.service.SecurityManager) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) Subject(ddf.security.Subject) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Exchange(org.apache.cxf.message.Exchange) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CollectionPermission(ddf.security.permission.CollectionPermission) Test(org.junit.Test)

Example 40 with Exchange

use of org.apache.cxf.message.Exchange in project ddf by codice.

the class PepInterceptorActionsTest method testMessageWithNoAction.

@Test(expected = AccessDeniedException.class)
public void testMessageWithNoAction() throws SecurityServiceException {
    SecurityManager mockSecurityManager = mock(SecurityManager.class);
    interceptor.setSecurityManager(mockSecurityManager);
    Message messageWithoutAction = mock(Message.class);
    SecurityToken mockSecurityToken = mock(SecurityToken.class);
    Subject mockSubject = mock(Subject.class);
    assertNotNull(mockSecurityAssertion);
    // SecurityLogger is already stubbed out
    when(mockSecurityAssertion.getToken()).thenReturn(mockSecurityToken);
    when(mockSecurityToken.getToken()).thenReturn(null);
    when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
    Exchange mockExchange = mock(Exchange.class);
    BindingOperationInfo mockBOI = mock(BindingOperationInfo.class);
    when(messageWithoutAction.getExchange()).thenReturn(mockExchange);
    when(mockExchange.get(BindingOperationInfo.class)).thenReturn(mockBOI);
    when(mockBOI.getExtensor(SoapOperationInfo.class)).thenReturn(null);
    when(mockSubject.isPermitted(isA(CollectionPermission.class))).thenReturn(false);
    // This should throw an exception.
    interceptor.handleMessage(messageWithoutAction);
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Exchange(org.apache.cxf.message.Exchange) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SecurityManager(ddf.security.service.SecurityManager) Message(org.apache.cxf.message.Message) CollectionPermission(ddf.security.permission.CollectionPermission) Subject(ddf.security.Subject) Test(org.junit.Test)

Aggregations

Exchange (org.apache.cxf.message.Exchange)338 Message (org.apache.cxf.message.Message)196 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)159 MessageImpl (org.apache.cxf.message.MessageImpl)144 Test (org.junit.Test)119 Endpoint (org.apache.cxf.endpoint.Endpoint)75 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)62 QName (javax.xml.namespace.QName)51 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)43 Bus (org.apache.cxf.Bus)33 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)32 Conduit (org.apache.cxf.transport.Conduit)31 Fault (org.apache.cxf.interceptor.Fault)30 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)28 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)28 MessageContentsList (org.apache.cxf.message.MessageContentsList)23 Service (org.apache.cxf.service.Service)22 SOAPMessage (javax.xml.soap.SOAPMessage)21 List (java.util.List)19