Search in sources :

Example 56 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project cxf by apache.

the class JAXRSInvoker method handleFault.

private Object handleFault(Fault ex, Message inMessage, ClassResourceInfo cri, Method methodToInvoke) {
    String errorMessage = ex.getMessage();
    if (errorMessage != null && cri != null && errorMessage.contains(PROXY_INVOCATION_ERROR_FRAGMENT)) {
        org.apache.cxf.common.i18n.Message errorM = new org.apache.cxf.common.i18n.Message("PROXY_INVOCATION_FAILURE", BUNDLE, methodToInvoke, cri.getServiceClass().getName());
        LOG.severe(errorM.toString());
    }
    Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause() == null ? ex : ex.getCause(), inMessage);
    if (excResponse == null) {
        inMessage.getExchange().put(Message.PROPOGATE_EXCEPTION, ExceptionUtils.propogateException(inMessage));
        throw ex;
    }
    return new MessageContentsList(excResponse);
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) Message(org.apache.cxf.message.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList)

Example 57 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project cxf by apache.

the class ClientRequestContextImpl method doSetEntity.

private void doSetEntity(Object entity) {
    Object actualEntity = InjectionUtils.getEntity(entity);
    m.setContent(List.class, actualEntity == null ? new MessageContentsList() : new MessageContentsList(actualEntity));
    if (entity != null) {
        final Type type;
        if (GenericEntity.class.isAssignableFrom(entity.getClass())) {
            type = ((GenericEntity<?>) entity).getType();
        } else {
            type = entity.getClass();
        }
        m.put(Type.class, type);
        m.remove("org.apache.cxf.empty.request");
    }
}
Also used : MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type) MessageContentsList(org.apache.cxf.message.MessageContentsList)

Example 58 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project cxf by apache.

the class SoapOutInterceptor method handleHeaderPart.

private boolean handleHeaderPart(boolean preexistingHeaders, SoapMessage message, String soapPrefix) {
    // add MessagePart to soapHeader if necessary
    boolean endedHeader = false;
    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    if (bop == null) {
        return endedHeader;
    }
    XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
    boolean startedHeader = false;
    BindingOperationInfo unwrappedOp = bop;
    if (bop.isUnwrapped()) {
        unwrappedOp = bop.getWrappedOperation();
    }
    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? unwrappedOp.getInput() : unwrappedOp.getOutput();
    BindingMessageInfo wrappedBmi = client ? bop.getInput() : bop.getOutput();
    if (bmi == null) {
        return endedHeader;
    }
    if (wrappedBmi.getMessageInfo().getMessagePartsNumber() > 0) {
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        if (objs == null) {
            return endedHeader;
        }
        SoapVersion soapVersion = message.getVersion();
        List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
        if (headers == null) {
            return endedHeader;
        }
        for (SoapHeaderInfo header : headers) {
            MessagePartInfo part = header.getPart();
            if (wrappedBmi != bmi) {
                part = wrappedBmi.getMessageInfo().addMessagePart(part.getName());
            }
            if (part.getIndex() >= objs.size()) {
                // The optional out of band header is not a part of parameters of the method
                continue;
            }
            Object arg = objs.get(part);
            if (arg == null) {
                continue;
            }
            objs.remove(part);
            if (!(startedHeader || preexistingHeaders)) {
                try {
                    xtw.writeStartElement(soapPrefix, soapVersion.getHeader().getLocalPart(), soapVersion.getNamespace());
                } catch (XMLStreamException e) {
                    throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e, soapVersion.getSender());
                }
                startedHeader = true;
            }
            DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message);
            dataWriter.write(arg, header.getPart(), xtw);
        }
        if (startedHeader || preexistingHeaders) {
            try {
                xtw.writeEndElement();
                endedHeader = true;
            } catch (XMLStreamException e) {
                throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e, soapVersion.getSender());
            }
        }
    }
    return endedHeader;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapFault(org.apache.cxf.binding.soap.SoapFault) MessageContentsList(org.apache.cxf.message.MessageContentsList) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Exchange(org.apache.cxf.message.Exchange) SoapVersion(org.apache.cxf.binding.soap.SoapVersion) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) DelegatingXMLStreamWriter(org.apache.cxf.staxutils.DelegatingXMLStreamWriter)

Example 59 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project cxf by apache.

the class STSInvoker method invoke.

public Object invoke(Exchange exchange, Object o) {
    AddressingProperties inProps = (AddressingProperties) exchange.getInMessage().getContextualProperty(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND);
    if (inProps != null) {
        AddressingProperties props = inProps.createCompatibleResponseProperties();
        AttributedURIType action = new AttributedURIType();
        action.setValue(inProps.getAction().getValue().replace("/RST/", "/RSTR/"));
        props.setAction(action);
        exchange.getOutMessage().put(JAXWSAConstants.ADDRESSING_PROPERTIES_OUTBOUND, props);
    }
    MessageContentsList lst = (MessageContentsList) o;
    DOMSource src = (DOMSource) lst.get(0);
    Node nd = src.getNode();
    final Element requestEl;
    if (nd instanceof Document) {
        requestEl = ((Document) nd).getDocumentElement();
    } else {
        requestEl = (Element) nd;
    }
    String namespace = requestEl.getNamespaceURI();
    String prefix = requestEl.getPrefix();
    SecurityToken cancelOrRenewToken = null;
    if ("RequestSecurityToken".equals(requestEl.getLocalName())) {
        try {
            String requestType = null;
            Element binaryExchange = null;
            String tokenType = null;
            Element el = DOMUtils.getFirstElement(requestEl);
            while (el != null) {
                String localName = el.getLocalName();
                if (namespace.equals(el.getNamespaceURI())) {
                    if ("RequestType".equals(localName)) {
                        requestType = el.getTextContent();
                    } else if ("CancelTarget".equals(localName) || "RenewTarget".equals(localName)) {
                        cancelOrRenewToken = findCancelOrRenewToken(exchange, el);
                    } else if ("BinaryExchange".equals(localName)) {
                        binaryExchange = el;
                    } else if ("TokenType".equals(localName)) {
                        tokenType = DOMUtils.getContent(el);
                    }
                }
                el = DOMUtils.getNextElement(el);
            }
            if (requestType == null) {
                requestType = "/Issue";
            }
            if (requestType.endsWith("/Issue") && !STSUtils.getTokenTypeSCT(namespace).equals(tokenType)) {
                throw new Exception("Unknown token type: " + tokenType);
            }
            W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
            writer.setNsRepairing(true);
            if (requestType.endsWith("/Issue")) {
                doIssue(requestEl, exchange, binaryExchange, writer, prefix, namespace);
            } else if (requestType.endsWith("/Cancel")) {
                doCancel(exchange, cancelOrRenewToken, writer, prefix, namespace);
            } else if (requestType.endsWith("/Renew")) {
                doRenew(requestEl, exchange, cancelOrRenewToken, binaryExchange, writer, prefix, namespace);
            }
            return new MessageContentsList(new DOMSource(writer.getDocument()));
        } catch (RuntimeException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new Fault(ex);
        }
    }
    throw new Fault("Unknown SecureConversation element: " + requestEl.getLocalName(), LOG);
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) DOMSource(javax.xml.transform.dom.DOMSource) MessageContentsList(org.apache.cxf.message.MessageContentsList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) Fault(org.apache.cxf.interceptor.Fault) Document(org.w3c.dom.Document) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) XMLStreamException(javax.xml.stream.XMLStreamException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties)

Example 60 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project cxf by apache.

the class JAXRSBeanValidationInvoker method invoke.

@Override
public Object invoke(Exchange exchange, final Object serviceObject, Method m, List<Object> params) {
    Message message = JAXRSUtils.getCurrentMessage();
    BeanValidationProvider theProvider = getProvider(message);
    try {
        if (isValidateServiceObject()) {
            theProvider.validateBean(serviceObject);
        }
        theProvider.validateParameters(serviceObject, m, params.toArray());
        Object response = super.invoke(exchange, serviceObject, m, params);
        if (response instanceof MessageContentsList) {
            MessageContentsList list = (MessageContentsList) response;
            if (list.size() == 1) {
                Object entity = list.get(0);
                if (entity instanceof Response) {
                    theProvider.validateReturnValue(serviceObject, m, ((Response) entity).getEntity());
                } else {
                    theProvider.validateReturnValue(serviceObject, m, entity);
                }
            }
        }
        return response;
    } catch (Fault ex) {
        throw ex;
    } catch (Throwable ex) {
        throw new Fault(ex);
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(org.apache.cxf.message.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList) Fault(org.apache.cxf.interceptor.Fault) BeanValidationProvider(org.apache.cxf.validation.BeanValidationProvider)

Aggregations

MessageContentsList (org.apache.cxf.message.MessageContentsList)69 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)24 Exchange (org.apache.cxf.message.Exchange)23 Message (org.apache.cxf.message.Message)22 Fault (org.apache.cxf.interceptor.Fault)19 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)18 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Endpoint (org.apache.cxf.endpoint.Endpoint)11 MessageImpl (org.apache.cxf.message.MessageImpl)11 Response (javax.ws.rs.core.Response)10 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)10 Method (java.lang.reflect.Method)9 OperationInfo (org.apache.cxf.service.model.OperationInfo)9 XMLStreamException (javax.xml.stream.XMLStreamException)8 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)8 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)8 MessageInfo (org.apache.cxf.service.model.MessageInfo)8 Test (org.junit.Test)8 Service (org.apache.cxf.service.Service)7