Java Code Examples for org.apache.cxf.service.model.BindingOperationInfo#getWrappedOperation()

The following examples show how to use org.apache.cxf.service.model.BindingOperationInfo#getWrappedOperation() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cxf   File: ColocMessageObserver.java    License: Apache License 2.0 6 votes vote down vote up
protected void setExchangeProperties(Exchange exchange, Message m) {
    exchange.put(Bus.class, bus);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Service.class, endpoint.getService());
    exchange.put(Binding.class, endpoint.getBinding());

    //Setup the BindingOperationInfo
    QName opName = (QName) m.get(Message.WSDL_OPERATION);
    BindingInfo bi = endpoint.getEndpointInfo().getBinding();
    BindingOperationInfo boi = bi.getOperation(opName);
    if (boi != null && boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
    }

    exchange.put(BindingOperationInfo.class, boi);
}
 
Example 2
Source Project: cxf   File: SwAOutInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();
    if (bop == null) {
        return;
    }

    if (bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }

    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? bop.getInput() : bop.getOutput();

    if (bmi == null) {
        return;
    }

    SoapBodyInfo sbi = bmi.getExtensor(SoapBodyInfo.class);

    if (sbi == null || sbi.getAttachments() == null || sbi.getAttachments().isEmpty()) {
        Service s = ex.getService();
        DataBinding db = s.getDataBinding();
        if (db instanceof JAXBDataBinding
            && hasSwaRef((JAXBDataBinding) db)) {
            setupAttachmentOutput(message);
        }
        return;
    }
    processAttachments(message, sbi);
}
 
Example 3
Source Project: cxf   File: PolicyEngineImpl.java    License: Apache License 2.0 5 votes vote down vote up
private BindingFaultInfo mapToWrappedBindingFaultInfo(BindingFaultInfo bfi) {
    BindingOperationInfo boi = bfi.getBindingOperation();
    if (boi != null && boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
        for (BindingFaultInfo bf2 : boi.getFaults()) {
            if (bf2.getFaultInfo().getName().equals(bfi.getFaultInfo().getName())) {
                return bf2;
            }
        }
    }
    return bfi;
}
 
Example 4
Source Project: cxf   File: AbstractMetricsInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
protected void addOperationMetrics(ExchangeMetrics ctx, Message m, BindingOperationInfo boi) {
    Object metrics = null;
    if (boi == null) {
        //likely a REST service, let's see if we have a resource name
        Object nameProperty = m.getExchange().get("org.apache.cxf.resource.operation.name");
        if (nameProperty != null) {
            Map<String, Object> restMap = getRestMetricsMap(m.getExchange().getEndpoint());
            metrics = restMap.get(nameProperty.toString());
            if (metrics == null) {
                metrics = createMetricsContextForRestResource(m, nameProperty.toString());
            }
        }
    } else {
        if (boi.isUnwrapped()) {
            boi = boi.getWrappedOperation();
        }
        metrics = boi.getProperty(MetricsContext.class.getName());
        if (metrics == null) {
            synchronized (boi) {
                metrics = createMetricsContextForOperation(m, boi);
            }
        }
    }
    if (metrics instanceof List) {
        List<MetricsContext> list = CastUtils.cast((List<?>)metrics);
        for (MetricsContext c : list) {
            ctx.addContext(c);
        }
    } else if (metrics instanceof MetricsContext) {
        ctx.addContext((MetricsContext)metrics);
    }
}
 
Example 5
private void setSoapAction(SoapMessage message) {
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();

    // The soap action is set on the wrapped operation.
    if (boi != null && boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
    }

    String action = getSoapAction(message, boi);

    if (message.getVersion() instanceof Soap11) {
        Map<String, List<String>> tempReqHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        Map<String, List<String>> reqHeaders
                = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
        if (reqHeaders != null) {
            tempReqHeaders.putAll(reqHeaders);
        }
        if (!tempReqHeaders.containsKey(SoapBindingConstants.SOAP_ACTION)) {
            tempReqHeaders.put(SoapBindingConstants.SOAP_ACTION, Collections.singletonList(action));
        }
        message.put(Message.PROTOCOL_HEADERS, tempReqHeaders);
    } else if (message.getVersion() instanceof Soap12 && !"\"\"".equals(action)) {
        String ct = (String) message.get(Message.CONTENT_TYPE);

        if (ct.indexOf("action=\"") == -1) {
            ct = new StringBuilder().append(ct)
                .append("; action=").append(action).toString();
            message.put(Message.CONTENT_TYPE, ct);
        }
    }
}
 
Example 6
Source Project: cxf   File: DocLiteralInInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
private BindingOperationInfo getBindingOperationInfo(DepthXMLStreamReader xmlReader, Exchange exchange,
                                                     BindingOperationInfo bop, boolean client) {
    //bop might be a unwrapped, wrap it back so that we can get correct info
    if (bop != null && bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }

    if (bop == null) {
        QName startQName = xmlReader == null
            ? new QName("http://cxf.apache.org/jaxws/provider", "invoke")
            : xmlReader.getName();
        bop = getBindingOperationInfo(exchange, startQName, client);
    }
    return bop;
}
 
Example 7
Source Project: cxf   File: WrapperClassOutInterceptor.java    License: Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();

    MessageInfo messageInfo = message.get(MessageInfo.class);
    if (messageInfo == null || bop == null || !bop.isUnwrapped()) {
        return;
    }

    BindingOperationInfo newbop = bop.getWrappedOperation();
    MessageInfo wrappedMsgInfo;
    if (Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE))) {
        wrappedMsgInfo = newbop.getInput().getMessageInfo();
    } else {
        wrappedMsgInfo = newbop.getOutput().getMessageInfo();
    }

    Class<?> wrapped = null;
    if (wrappedMsgInfo.getMessagePartsNumber() > 0) {
        wrapped = wrappedMsgInfo.getFirstMessagePart().getTypeClass();
    }

    if (wrapped != null) {
        MessagePartInfo firstMessagePart = wrappedMsgInfo.getFirstMessagePart();
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        WrapperHelper helper = firstMessagePart.getProperty("WRAPPER_CLASS", WrapperHelper.class);
        if (helper == null) {
            helper = getWrapperHelper(message, messageInfo, wrappedMsgInfo, wrapped, firstMessagePart);
        }
        if (helper == null) {
            return;
        }

        try {
            MessageContentsList newObjs = new MessageContentsList();
            if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)
                && helper instanceof AbstractWrapperHelper) {
                ((AbstractWrapperHelper)helper).setValidate(true);
            }
            Object o2 = helper.createWrapperObject(objs);
            newObjs.put(firstMessagePart, o2);

            for (MessagePartInfo p : messageInfo.getMessageParts()) {
                if (Boolean.TRUE.equals(p.getProperty(ReflectionServiceFactoryBean.HEADER))) {
                    MessagePartInfo mpi = wrappedMsgInfo.getMessagePart(p.getName());
                    if (objs.hasValue(p)) {
                        newObjs.put(mpi, objs.get(p));
                    }
                }
            }

            message.setContent(List.class, newObjs);
        } catch (Fault f) {
            throw f;
        } catch (Exception e) {
            throw new Fault(e);
        }

        // we've now wrapped the object, so use the wrapped binding op
        ex.put(BindingOperationInfo.class, newbop);

        if (messageInfo == bop.getOperationInfo().getInput()) {
            message.put(MessageInfo.class, newbop.getOperationInfo().getInput());
            message.put(BindingMessageInfo.class, newbop.getInput());
        } else if (messageInfo == bop.getOperationInfo().getOutput()) {
            message.put(MessageInfo.class, newbop.getOperationInfo().getOutput());
            message.put(BindingMessageInfo.class, newbop.getOutput());
        }
    }
}
 
Example 8
Source Project: cxf   File: ClientImpl.java    License: Apache License 2.0 4 votes vote down vote up
protected Object[] processResult(Message message,
                               Exchange exchange,
                               BindingOperationInfo oi,
                               Map<String, Object> resContext) throws Exception {
    Exception ex = null;
    // Check to see if there is a Fault from the outgoing chain if it's an out Message
    if (!message.get(Message.INBOUND_MESSAGE).equals(Boolean.TRUE)) {
        ex = message.getContent(Exception.class);
    }
    boolean mepCompleteCalled = false;
    if (ex != null) {
        completeExchange(exchange);
        mepCompleteCalled = true;
        if (message.getContent(Exception.class) != null) {
            throw ex;
        }
    }
    ex = message.getExchange().get(Exception.class);
    if (ex != null) {
        if (!mepCompleteCalled) {
            completeExchange(exchange);
        }
        throw ex;
    }

    //REVISIT
    // - use a protocol neutral no-content marker instead of 202?
    // - move the decoupled destination property name into api
    Integer responseCode = (Integer)exchange.get(Message.RESPONSE_CODE);
    if (null != responseCode && 202 == responseCode) {
        Endpoint ep = exchange.getEndpoint();
        if (null != ep && null != ep.getEndpointInfo() && null == ep.getEndpointInfo().
            getProperty("org.apache.cxf.ws.addressing.MAPAggregator.decoupledDestination")) {
            return null;
        }
    }

    // Wait for a response if we need to
    if (oi != null && !oi.getOperationInfo().isOneWay()) {
        waitResponse(exchange);
    }

    // leave the input stream open for the caller
    Boolean keepConduitAlive = (Boolean)exchange.get(Client.KEEP_CONDUIT_ALIVE);
    if (keepConduitAlive == null || !keepConduitAlive) {
        completeExchange(exchange);
    }

    // Grab the response objects if there are any
    List<Object> resList = null;
    Message inMsg = exchange.getInMessage();
    if (inMsg != null) {
        if (null != resContext) {
            resContext.putAll(inMsg);
            // remove the recursive reference if present
            resContext.remove(Message.INVOCATION_CONTEXT);
            setResponseContext(resContext);
        }
        resList = CastUtils.cast(inMsg.getContent(List.class));
    }

    // check for an incoming fault
    ex = getException(exchange);

    if (ex != null) {
        throw ex;
    }

    if (resList == null   
        && oi != null && !oi.getOperationInfo().isOneWay()) {
        
        BindingOperationInfo boi = oi;
        if (boi.isUnwrapped()) {
            boi = boi.getWrappedOperation();
        }
        if (!boi.getOutput().getMessageParts().isEmpty()) {
            //we were supposed to get some output, but didn't.
            throw new IllegalEmptyResponseException("Response message did not contain proper response data."
                + " Expected: " + boi.getOutput().getMessageParts().get(0).getConcreteName());
        }
    }
    if (resList != null) {
        return resList.toArray();
    }

    return null;
}