Search in sources :

Example 46 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class BareInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("BareInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    Exchange exchange = message.getExchange();
    DataReader<XMLStreamReader> dr = getDataReader(message);
    MessageContentsList parameters = new MessageContentsList();
    Endpoint ep = exchange.getEndpoint();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    ServiceInfo si = ep.getEndpointInfo().getService();
    BindingMessageInfo msgInfo = null;
    boolean client = isRequestor(message);
    Collection<OperationInfo> ops = null;
    if (bop == null) {
        ops = new ArrayList<>();
        ops.addAll(si.getInterface().getOperations());
        if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT && !client) {
            // TO DO : check duplicate operation with no input
            for (OperationInfo op : ops) {
                MessageInfo bmsg = op.getInput();
                if (bmsg.getMessagePartsNumber() == 0) {
                    BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
                    exchange.put(BindingOperationInfo.class, boi);
                    exchange.setOneWay(op.isOneWay());
                }
            }
        }
    } else {
        getMessageInfo(message, bop);
        if (client) {
            msgInfo = bop.getOutput();
        } else {
            msgInfo = bop.getInput();
        }
    }
    int paramNum = 0;
    while (StaxUtils.toNextElement(xmlReader)) {
        QName elName = xmlReader.getName();
        Object o = null;
        MessagePartInfo p;
        if (msgInfo != null && msgInfo.getMessageParts() != null) {
            assert msgInfo.getMessageParts().size() > paramNum;
            p = msgInfo.getMessageParts().get(paramNum);
        } else {
            p = findMessagePart(exchange, ops, elName, client, paramNum, message);
        }
        if (p == null) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", LOG, elName), Fault.FAULT_CODE_CLIENT);
        }
        try {
            o = dr.read(p, xmlReader);
        } catch (Fault fault) {
            if (!isRequestor(message)) {
                fault.setFaultCode(Fault.FAULT_CODE_CLIENT);
            }
            throw fault;
        }
        if (o != null) {
            parameters.put(p, o);
        }
        paramNum++;
    }
    if (!parameters.isEmpty()) {
        message.setContent(List.class, parameters);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 47 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class DocLiteralInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("DocLiteralInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    MessageContentsList parameters = new MessageContentsList();
    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    boolean client = isRequestor(message);
    // operation anymore, just return
    if (bop != null && !StaxUtils.toNextElement(xmlReader)) {
        // body may be empty for partial response to decoupled request
        return;
    }
    Service service = ServiceModelUtil.getService(message.getExchange());
    bop = getBindingOperationInfo(xmlReader, exchange, bop, client);
    boolean forceDocLitBare = false;
    if (bop != null && bop.getBinding() != null) {
        forceDocLitBare = Boolean.TRUE.equals(bop.getBinding().getService().getProperty("soap.force.doclit.bare"));
    }
    DataReader<XMLStreamReader> dr = getDataReader(message);
    try {
        if (!forceDocLitBare && bop != null && bop.isUnwrappedCapable()) {
            ServiceInfo si = bop.getBinding().getService();
            // Wrapped case
            MessageInfo msgInfo = setMessage(message, bop, client, si);
            setDataReaderValidation(service, message, dr);
            // Determine if we should keep the parameters wrapper
            if (shouldWrapParameters(msgInfo, message)) {
                QName startQName = xmlReader.getName();
                MessagePartInfo mpi = msgInfo.getFirstMessagePart();
                if (!mpi.getConcreteName().equals(startQName)) {
                    throw new Fault("UNEXPECTED_WRAPPER_ELEMENT", LOG, null, startQName, mpi.getConcreteName());
                }
                Object wrappedObject = dr.read(mpi, xmlReader);
                parameters.put(mpi, wrappedObject);
            } else {
                // Unwrap each part individually if we don't have a wrapper
                bop = bop.getUnwrappedOperation();
                msgInfo = setMessage(message, bop, client, si);
                List<MessagePartInfo> messageParts = msgInfo.getMessageParts();
                Iterator<MessagePartInfo> itr = messageParts.iterator();
                // stuck
                if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
                    StaxUtils.nextEvent(xmlReader);
                }
                // loop through each child element
                getPara(xmlReader, dr, parameters, itr, message);
            }
        } else {
            // Bare style
            BindingMessageInfo msgInfo = null;
            Endpoint ep = exchange.getEndpoint();
            ServiceInfo si = ep.getEndpointInfo().getService();
            if (bop != null) {
                // for xml binding or client side
                if (client) {
                    msgInfo = bop.getOutput();
                } else {
                    msgInfo = bop.getInput();
                    if (bop.getOutput() == null) {
                        exchange.setOneWay(true);
                    }
                }
                if (msgInfo == null) {
                    return;
                }
                setMessage(message, bop, client, si, msgInfo.getMessageInfo());
            }
            Collection<OperationInfo> operations = null;
            operations = new ArrayList<>();
            operations.addAll(si.getInterface().getOperations());
            if (xmlReader == null || !StaxUtils.toNextElement(xmlReader)) {
                // empty input
                getBindingOperationForEmptyBody(operations, ep, exchange);
                return;
            }
            setDataReaderValidation(service, message, dr);
            int paramNum = 0;
            do {
                QName elName = xmlReader.getName();
                Object o = null;
                MessagePartInfo p;
                if (!client && msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().isEmpty()) {
                    // no input messagePartInfo
                    return;
                }
                if (msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().size() > 0) {
                    if (msgInfo.getMessageParts().size() > paramNum) {
                        p = msgInfo.getMessageParts().get(paramNum);
                    } else {
                        p = null;
                    }
                } else {
                    p = findMessagePart(exchange, operations, elName, client, paramNum, message);
                }
                if (!forceDocLitBare) {
                    // Make sure the elName found on the wire is actually OK for
                    // the purpose we need it
                    validatePart(p, elName, message);
                }
                o = dr.read(p, xmlReader);
                if (forceDocLitBare && parameters.isEmpty()) {
                    // webservice provider does not need to ensure size
                    parameters.add(o);
                } else {
                    parameters.put(p, o);
                }
                paramNum++;
                if (message.getContent(XMLStreamReader.class) == null || o == xmlReader) {
                    xmlReader = null;
                }
            } while (xmlReader != null && StaxUtils.toNextElement(xmlReader));
        }
        message.setContent(List.class, parameters);
    } catch (Fault f) {
        if (!isRequestor(message)) {
            f.setFaultCode(Fault.FAULT_CODE_CLIENT);
        }
        throw f;
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 48 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class WrappedOutInterceptor method handleMessage.

public void handleMessage(Message message) {
    BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
    if (bop != null && bop.isUnwrapped()) {
        XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);
        MessageInfo messageInfo;
        if (isRequestor(message)) {
            messageInfo = bop.getWrappedOperation().getOperationInfo().getInput();
        } else {
            messageInfo = bop.getWrappedOperation().getOperationInfo().getOutput();
        }
        QName name = messageInfo.getFirstMessagePart().getConcreteName();
        try {
            String pfx = null;
            Service service = message.getExchange().getService();
            if (service.getDataBinding().getDeclaredNamespaceMappings() != null) {
                pfx = service.getDataBinding().getDeclaredNamespaceMappings().get(name.getNamespaceURI());
            }
            if (pfx == null) {
                pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI(), false);
            }
            xmlWriter.setPrefix(pfx, name.getNamespaceURI());
            xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI());
            if (StringUtils.isEmpty(pfx)) {
                xmlWriter.writeDefaultNamespace(name.getNamespaceURI());
            } else {
                xmlWriter.writeNamespace(pfx, name.getNamespaceURI());
            }
        } catch (XMLStreamException e) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
        }
        // Add a final interceptor to write end element
        message.getInterceptorChain().add(ending);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamException(javax.xml.stream.XMLStreamException) Message(org.apache.cxf.message.Message) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 49 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class ReflectionServiceFactoryBean method createEndpoints.

protected void createEndpoints() {
    Service service = getService();
    BindingFactoryManager bfm = getBus().getExtension(BindingFactoryManager.class);
    for (ServiceInfo inf : service.getServiceInfos()) {
        for (EndpointInfo ei : inf.getEndpoints()) {
            for (BindingOperationInfo boi : ei.getBinding().getOperations()) {
                updateBindingOperation(boi);
            }
            try {
                bfm.getBindingFactory(ei.getBinding().getBindingId());
            } catch (BusException e1) {
                continue;
            }
            try {
                Endpoint ep = createEndpoint(ei);
                service.getEndpoints().put(ei.getName(), ep);
            } catch (EndpointException e) {
                throw new ServiceConstructionException(e);
            }
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) EndpointException(org.apache.cxf.endpoint.EndpointException) Service(org.apache.cxf.service.Service) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) BusException(org.apache.cxf.BusException)

Example 50 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class SimpleBatchSTSClient method validateBatchSecurityTokens.

protected List<SecurityToken> validateBatchSecurityTokens(List<BatchRequest> batchRequestList, String action, String requestType) throws Exception {
    createClient();
    BindingOperationInfo boi = findOperation("/BatchValidate");
    client.getRequestContext().putAll(ctx);
    client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, action);
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    writer.writeStartElement("wst", "RequestSecurityTokenCollection", namespace);
    writer.writeNamespace("wst", namespace);
    for (BatchRequest batchRequest : batchRequestList) {
        writer.writeStartElement("wst", "RequestSecurityToken", namespace);
        writer.writeNamespace("wst", namespace);
        addRequestType(requestType, writer);
        addTokenType(writer, batchRequest.getTokenType());
        writer.writeStartElement("wst", "ValidateTarget", namespace);
        Element el = batchRequest.getValidateTarget();
        StaxUtils.copy(el, writer);
        writer.writeEndElement();
        writer.writeEndElement();
    }
    writer.writeEndElement();
    Object[] obj = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
    Element responseCollection = getDocumentElement((DOMSource) obj[0]);
    Node child = responseCollection.getFirstChild();
    List<SecurityToken> tokens = new ArrayList<>();
    while (child != null) {
        if (child instanceof Element && "RequestSecurityTokenResponse".equals(((Element) child).getLocalName())) {
            Element rstrChild = DOMUtils.getFirstElement(child);
            while (rstrChild != null) {
                if ("Status".equals(rstrChild.getLocalName())) {
                    Element e2 = DOMUtils.getFirstChildWithName(rstrChild, rstrChild.getNamespaceURI(), "Code");
                    String s = DOMUtils.getContent(e2);
                    if (!s.endsWith("/status/valid")) {
                        throw new TrustException(LOG, "VALIDATION_FAILED");
                    }
                } else if ("RequestedSecurityToken".equals(rstrChild.getLocalName())) {
                    Element requestedSecurityTokenElement = DOMUtils.getFirstElement(rstrChild);
                    String id = findID(null, null, requestedSecurityTokenElement);
                    if (StringUtils.isEmpty(id)) {
                        throw new TrustException("NO_ID", LOG);
                    }
                    SecurityToken requestedSecurityToken = new SecurityToken(id);
                    requestedSecurityToken.setToken(requestedSecurityTokenElement);
                    tokens.add(requestedSecurityToken);
                }
                rstrChild = DOMUtils.getNextElement(rstrChild);
            }
        }
        child = child.getNextSibling();
    }
    return tokens;
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) DOMSource(javax.xml.transform.dom.DOMSource) TrustException(org.apache.cxf.ws.security.trust.TrustException) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ModCountCopyOnWriteArrayList(org.apache.cxf.common.util.ModCountCopyOnWriteArrayList) ArrayList(java.util.ArrayList) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken)

Aggregations

BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)214 QName (javax.xml.namespace.QName)82 BindingInfo (org.apache.cxf.service.model.BindingInfo)57 Test (org.junit.Test)55 Exchange (org.apache.cxf.message.Exchange)50 OperationInfo (org.apache.cxf.service.model.OperationInfo)47 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)42 Endpoint (org.apache.cxf.endpoint.Endpoint)41 Message (org.apache.cxf.message.Message)36 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)36 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)32 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)31 Service (org.apache.cxf.service.Service)29 Fault (org.apache.cxf.interceptor.Fault)24 MessageInfo (org.apache.cxf.service.model.MessageInfo)24 MessageContentsList (org.apache.cxf.message.MessageContentsList)23 Method (java.lang.reflect.Method)22 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)22 ArrayList (java.util.ArrayList)21 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)16