Search in sources :

Example 1 with OperationInfo

use of org.apache.cxf.service.model.OperationInfo in project camel by apache.

the class DefaultCxfBinding method getPayloadBodyElements.

protected static List<Source> getPayloadBodyElements(Message message, Map<String, String> nsMap) {
    // take the namespace attribute from soap envelop
    Map<String, String> bodyNC = CastUtils.cast((Map<?, ?>) message.get("soap.body.ns.context"));
    if (bodyNC != null) {
        // if there is no Node and the addNamespaceContext option is enabled, this map is available
        nsMap.putAll(bodyNC);
    } else {
        Document soapEnv = (Document) message.getContent(Node.class);
        if (soapEnv != null) {
            NamedNodeMap attrs = soapEnv.getFirstChild().getAttributes();
            for (int i = 0; i < attrs.getLength(); i++) {
                Node node = attrs.item(i);
                if (!node.getNodeValue().equals(Soap11.SOAP_NAMESPACE) && !node.getNodeValue().equals(Soap12.SOAP_NAMESPACE)) {
                    nsMap.put(node.getLocalName(), node.getNodeValue());
                }
            }
        }
    }
    MessageContentsList inObjects = MessageContentsList.getContentsList(message);
    if (inObjects == null) {
        return new ArrayList<Source>(0);
    }
    org.apache.cxf.message.Exchange exchange = message.getExchange();
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    OperationInfo op = boi.getOperationInfo();
    if (boi.isUnwrapped()) {
        op = boi.getWrappedOperation().getOperationInfo();
    }
    List<MessagePartInfo> partInfos = null;
    boolean client = Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE));
    if (client) {
        // it is a response
        partInfos = op.getOutput().getMessageParts();
    } else {
        // it is a request
        partInfos = op.getInput().getMessageParts();
    }
    List<Source> answer = new ArrayList<Source>();
    for (MessagePartInfo partInfo : partInfos) {
        if (!inObjects.hasValue(partInfo)) {
            continue;
        }
        Object part = inObjects.get(partInfo);
        if (part instanceof Holder) {
            part = ((Holder<?>) part).value;
        }
        if (part instanceof Source) {
            Element element = null;
            if (part instanceof DOMSource) {
                element = getFirstElement(((DOMSource) part).getNode());
            }
            if (element != null) {
                addNamespace(element, nsMap);
                answer.add(new DOMSource(element));
            } else {
                answer.add((Source) part);
            }
            if (LOG.isTraceEnabled()) {
                LOG.trace("Extract body element {}", element == null ? "null" : getXMLString(element));
            }
        } else if (part instanceof Element) {
            addNamespace((Element) part, nsMap);
            answer.add(new DOMSource((Element) part));
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Unhandled part type '{}'", part.getClass());
            }
        }
    }
    return answer;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) DOMSource(javax.xml.transform.dom.DOMSource) NamedNodeMap(org.w3c.dom.NamedNodeMap) MessageContentsList(org.apache.cxf.message.MessageContentsList) Node(org.w3c.dom.Node) Holder(javax.xml.ws.Holder) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source)

Example 2 with OperationInfo

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

the class OperationInfoAuthorizingInterceptorTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    Exchange ex = setUpExchange();
    Service service = EasyMock.createMock(Service.class);
    ex.put(Service.class, service);
    MethodDispatcher md = EasyMock.createMock(MethodDispatcher.class);
    EasyMock.expect(service.get(MethodDispatcher.class.getName())).andReturn(md).anyTimes();
    BindingOperationInfo boi = EasyMock.createMock(BindingOperationInfo.class);
    ex.put(BindingOperationInfo.class, boi);
    EasyMock.expect(md.getMethod(boi)).andReturn(null);
    OperationInfo opinfo = EasyMock.createMock(OperationInfo.class);
    EasyMock.expect(opinfo.getName()).andReturn(new QName("urn:test", "echo")).anyTimes();
    EasyMock.expect(boi.getOperationInfo()).andReturn(opinfo).anyTimes();
    EasyMock.replay(service, md, boi, opinfo);
}
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) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher) Before(org.junit.Before)

Example 3 with OperationInfo

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

the class ServiceUtils method getSchemaValidationTypeFromModel.

private static SchemaValidationType getSchemaValidationTypeFromModel(Message message) {
    Exchange exchange = message.getExchange();
    if (exchange != null) {
        BindingOperationInfo boi = exchange.getBindingOperationInfo();
        Endpoint endpoint = exchange.getEndpoint();
        if (boi != null && endpoint != null) {
            SchemaValidationType validationType = null;
            OperationInfo opInfo = boi.getOperationInfo();
            EndpointInfo ep = endpoint.getEndpointInfo();
            if (opInfo != null) {
                validationType = getSchemaValidationTypeFromModel(opInfo);
                if (validationType == null && ep != null) {
                    validationType = getSchemaValidationTypeFromModel(ep);
                }
            }
            return validationType;
        }
    }
    // else
    return null;
}
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 4 with OperationInfo

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

the class AbstractInDatabindingInterceptor method findMessagePart.

/**
 * Find the next possible message part in the message. If an operation in
 * the list of operations is no longer a viable match, it will be removed
 * from the Collection.
 *
 * @param exchange
 * @param operations
 * @param name
 * @param client
 * @param index
 */
protected MessagePartInfo findMessagePart(Exchange exchange, Collection<OperationInfo> operations, QName name, boolean client, int index, Message message) {
    Endpoint ep = exchange.getEndpoint();
    MessagePartInfo lastChoice = null;
    BindingOperationInfo lastBoi = null;
    BindingMessageInfo lastMsgInfo = null;
    BindingMessageInfo msgInfo = null;
    BindingOperationInfo boi = null;
    for (Iterator<OperationInfo> itr = operations.iterator(); itr.hasNext(); ) {
        OperationInfo op = itr.next();
        boi = ep.getEndpointInfo().getBinding().getOperation(op);
        if (boi == null) {
            continue;
        }
        if (client) {
            msgInfo = boi.getOutput();
        } else {
            msgInfo = boi.getInput();
        }
        if (msgInfo == null) {
            itr.remove();
            continue;
        }
        Collection<MessagePartInfo> bodyParts = msgInfo.getMessageParts();
        if (bodyParts.isEmpty() || bodyParts.size() <= index) {
            itr.remove();
            continue;
        }
        MessagePartInfo p = msgInfo.getMessageParts().get(index);
        if (name.getNamespaceURI() == null || name.getNamespaceURI().length() == 0) {
            // message part has same namespace with the message
            name = new QName(p.getMessageInfo().getName().getNamespaceURI(), name.getLocalPart());
        }
        if (name.equals(p.getConcreteName())) {
            exchange.put(BindingOperationInfo.class, boi);
            exchange.setOneWay(op.isOneWay());
            return p;
        }
        if (Constants.XSD_ANYTYPE.equals(p.getTypeQName())) {
            lastChoice = p;
            lastBoi = boi;
            lastMsgInfo = msgInfo;
        } else {
            itr.remove();
        }
    }
    if (lastChoice != null) {
        setMessage(message, lastBoi, client, lastBoi.getBinding().getService(), lastMsgInfo.getMessageInfo());
    }
    return lastChoice;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 5 with OperationInfo

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

the class OperationInfoAuthorizingInterceptor method handleMessage.

@Override
public void handleMessage(Message message) throws Fault {
    OperationInfo opinfo = getTargetOperationInfo(message);
    SecurityContext sc = message.get(SecurityContext.class);
    if (sc != null && sc.getUserPrincipal() != null) {
        if (opinfo.getName() != null && authorize(sc, opinfo.getName().getLocalPart())) {
            return;
        }
    } else if (!isMethodProtected(opinfo.getName().getLocalPart()) && isAllowAnonymousUsers()) {
        return;
    }
    throw new AccessDeniedException("Unauthorized");
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SecurityContext(org.apache.cxf.security.SecurityContext)

Aggregations

OperationInfo (org.apache.cxf.service.model.OperationInfo)135 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)87 QName (javax.xml.namespace.QName)58 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)44 MessageInfo (org.apache.cxf.service.model.MessageInfo)40 Test (org.junit.Test)38 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)36 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)31 Method (java.lang.reflect.Method)25 Endpoint (org.apache.cxf.endpoint.Endpoint)24 Service (org.apache.cxf.service.Service)22 BindingInfo (org.apache.cxf.service.model.BindingInfo)21 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)19 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)17 Exchange (org.apache.cxf.message.Exchange)17 ArrayList (java.util.ArrayList)13 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)13 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)12 Fault (org.apache.cxf.interceptor.Fault)10 Message (org.apache.cxf.message.Message)10