Search in sources :

Example 21 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project jbossws-cxf by jbossws.

the class JaspiServerAuthenticator method validateRequest.

public void validateRequest(SoapMessage message) {
    SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
    MessageInfo messageInfo = new GenericMessageInfo(soapMessage, null);
    AuthStatus authStatus;
    try {
        authStatus = sctx.validateRequest(messageInfo, null, null);
    } catch (AuthException e) {
        if (isSOAP12(message)) {
            SoapFault soap12Fault = new SoapFault(e.getMessage(), Soap12.getInstance().getReceiver());
            throw soap12Fault;
        } else {
            throw new SoapFault(e.getMessage(), new QName("", "jaspi AuthException"));
        }
    }
    Message response = null;
    if (messageInfo.getResponseMessage() != null && !message.getExchange().isOneWay()) {
        Endpoint e = message.getExchange().getEndpoint();
        response = new MessageImpl();
        response.setExchange(message.getExchange());
        response = e.getBinding().createMessage(response);
        message.getExchange().setOutMessage(response);
        response.setContent(SOAPMessage.class, messageInfo.getResponseMessage());
        if (AuthStatus.SEND_CONTINUE == authStatus) {
            response.put(Message.RESPONSE_CODE, Integer.valueOf(303));
        }
        if (AuthStatus.SEND_FAILURE == authStatus) {
            response.put(Message.RESPONSE_CODE, Integer.valueOf(500));
        }
        message.getInterceptorChain().abort();
        InterceptorChain chain = OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange());
        response.setInterceptorChain(chain);
        chain.doInterceptStartingAfter(response, SoapPreProtocolOutInterceptor.class.getName());
    }
}
Also used : InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) SoapFault(org.apache.cxf.binding.soap.SoapFault) SoapPreProtocolOutInterceptor(org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) Endpoint(org.apache.cxf.endpoint.Endpoint) AuthStatus(javax.security.auth.message.AuthStatus) QName(javax.xml.namespace.QName) GenericMessageInfo(org.jboss.security.auth.message.GenericMessageInfo) AuthException(javax.security.auth.message.AuthException) SOAPMessage(javax.xml.soap.SOAPMessage) MessageImpl(org.apache.cxf.message.MessageImpl) MessageInfo(javax.security.auth.message.MessageInfo) GenericMessageInfo(org.jboss.security.auth.message.GenericMessageInfo)

Example 22 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project jbossws-cxf by jbossws.

the class JBossWSInvokerTest method getTestExchange.

// build up a fake exchange instance, the minimum required to let the flow proceed till the JBossWSInvoker
private Exchange getTestExchange() {
    Exchange exchange = new ExchangeImpl();
    Message message = new MessageImpl();
    message.setExchange(exchange);
    exchange.setInMessage(message);
    exchange.put(BindingOperationInfo.class, new BindingOperationInfo());
    Service service = new ServiceImpl();
    MethodDispatcher md = new MethodDispatcher() {

        @Override
        public Method getMethod(BindingOperationInfo op) {
            return this.getClass().getMethods()[0];
        }

        @Override
        public BindingOperationInfo getBindingOperation(Method m, Endpoint endpoint) {
            return null;
        }

        @Override
        public void bind(OperationInfo o, Method... methods) {
        }
    };
    service.put(MethodDispatcher.class.getName(), md);
    exchange.put(Service.class, service);
    return exchange;
}
Also used : Exchange(org.apache.cxf.message.Exchange) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) Endpoint(org.apache.cxf.endpoint.Endpoint) ServiceImpl(org.apache.cxf.service.ServiceImpl) Service(org.apache.cxf.service.Service) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher) Method(java.lang.reflect.Method) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 23 with MessageImpl

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

the class ResourceUtils method createConstructorArguments.

public static Object[] createConstructorArguments(Constructor<?> c, Message m, boolean perRequest, Map<Class<?>, Object> contextValues, Class<?>[] params, Annotation[][] anns, Type[] genericTypes) {
    if (m == null) {
        m = new MessageImpl();
    }
    @SuppressWarnings("unchecked") MultivaluedMap<String, String> templateValues = (MultivaluedMap<String, String>) m.get(URITemplate.TEMPLATE_PARAMETERS);
    Object[] values = new Object[params.length];
    for (int i = 0; i < params.length; i++) {
        if (AnnotationUtils.getAnnotation(anns[i], Context.class) != null) {
            Object contextValue = contextValues != null ? contextValues.get(params[i]) : null;
            if (contextValue == null) {
                if (perRequest || InjectionUtils.VALUE_CONTEXTS.contains(params[i].getName())) {
                    values[i] = JAXRSUtils.createContextValue(m, genericTypes[i], params[i]);
                } else {
                    values[i] = InjectionUtils.createThreadLocalProxy(params[i]);
                }
            } else {
                values[i] = contextValue;
            }
        } else {
            // this branch won't execute for singletons given that the found constructor
            // is guaranteed to have only Context parameters, if any, for singletons
            Parameter p = ResourceUtils.getParameter(i, anns[i], params[i]);
            values[i] = JAXRSUtils.createHttpParameterValue(p, params[i], genericTypes[i], anns[i], m, templateValues, null);
        }
    }
    return values;
}
Also used : Context(javax.ws.rs.core.Context) Parameter(org.apache.cxf.jaxrs.model.Parameter) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 24 with MessageImpl

use of org.apache.cxf.message.MessageImpl 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 25 with MessageImpl

use of org.apache.cxf.message.MessageImpl 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)

Aggregations

MessageImpl (org.apache.cxf.message.MessageImpl)610 Message (org.apache.cxf.message.Message)291 Test (org.junit.Test)290 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)193 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)152 Exchange (org.apache.cxf.message.Exchange)148 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)137 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)115 Crypto (org.apache.wss4j.common.crypto.Crypto)113 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)107 JAXBElement (javax.xml.bind.JAXBElement)100 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)93 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)86 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)83 Element (org.w3c.dom.Element)74 ArrayList (java.util.ArrayList)62 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 Principal (java.security.Principal)59 Endpoint (org.apache.cxf.endpoint.Endpoint)58