Java Code Examples for org.apache.cxf.message.Exchange#getBindingOperationInfo()

The following examples show how to use org.apache.cxf.message.Exchange#getBindingOperationInfo() . 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 File: AbstractJAXWSHandlerInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void setupBindingOperationInfo(Exchange exch, Object data) {
    if (exch.getBindingOperationInfo() == null) {
        //need to know the operation to determine if oneway
        QName opName = getOpQName(exch, data);
        if (opName == null) {
            return;
        }
        BindingOperationInfo bop = ServiceModelUtil
            .getOperationForWrapperElement(exch, opName, false);
        if (bop == null) {
            bop = ServiceModelUtil.getOperation(exch, opName);
        }
        if (bop != null) {
            exch.put(BindingOperationInfo.class, bop);
            if (bop.getOutput() == null) {
                exch.setOneWay(true);
            }
        }

    }
}
 
Example 2
Source File: PhaseInterceptorChain.java    From cxf with Apache License 2.0 6 votes vote down vote up
private String getServiceInfo(Message message) {
    StringBuilder description = new StringBuilder();
    if (message.getExchange() != null) {
        Exchange exchange = message.getExchange();
        Service service = exchange.getService();
        if (service != null) {
            description.append('\'');
            description.append(service.getName());
            BindingOperationInfo boi = exchange.getBindingOperationInfo();
            OperationInfo opInfo = boi != null ? boi.getOperationInfo() : null;
            if (opInfo != null) {
                description.append('#').append(opInfo.getName());
            }
            description.append("\' ");
        }
    }
    return description.toString();
}
 
Example 3
Source File: SwAOutInterceptor.java    From cxf with 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 4
Source File: StaxDataBindingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("StaxDataBindingInterceptor skipped in HTTP GET method");
        return;
    }

    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    DataReader<XMLStreamReader> dr = getDataReader(message);
    MessageContentsList parameters = new MessageContentsList();

    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();

    //if body is empty and we have BindingOperationInfo, we do not need to match
    //operation anymore, just return
    if (!StaxUtils.toNextElement(xmlReader) && bop != null) {
        // body may be empty for partial response to decoupled request
        return;
    }

    if (bop == null) {
        Endpoint ep = exchange.getEndpoint();
        bop = ep.getBinding().getBindingInfo().getOperations().iterator().next();
    }

    message.getExchange().put(BindingOperationInfo.class, bop);

    if (isRequestor(message)) {
        parameters.put(bop.getOutput().getMessageParts().get(0), dr.read(xmlReader));
    } else {
        parameters.put(bop.getInput().getMessageParts().get(0), dr.read(xmlReader));
    }


    if (!parameters.isEmpty()) {
        message.setContent(List.class, parameters);
    }
}
 
Example 5
Source File: FailoverTargetSelector.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Called prior to the interceptor chain being traversed.
 *
 * @param message the current Message
 */
public void prepare(Message message) {
    if (message.getContent(List.class) == null) {
        return;
    }
    Exchange exchange = message.getExchange();
    setupExchangeExceptionProperties(exchange);

    String key = String.valueOf(System.identityHashCode(exchange));
    if (getInvocationContext(key) == null) {

        if (getClientBootstrapAddress() != null
            && getClientBootstrapAddress().equals(message.get(Message.ENDPOINT_ADDRESS))) {
            List<String> addresses = failoverStrategy.getAlternateAddresses(exchange);
            if (addresses != null && !addresses.isEmpty()) {
                getEndpoint().getEndpointInfo().setAddress(addresses.get(0));
                message.put(Message.ENDPOINT_ADDRESS, addresses.get(0));
            }
        }

        Endpoint endpoint = exchange.getEndpoint();
        BindingOperationInfo bindingOperationInfo =
            exchange.getBindingOperationInfo();
        Object[] params = message.getContent(List.class).toArray();
        Map<String, Object> context =
            CastUtils.cast((Map<?, ?>)message.get(Message.INVOCATION_CONTEXT));
        InvocationContext invocation =
            new InvocationContext(endpoint,
                                  bindingOperationInfo,
                                  params,
                                  context);
        inProgress.putIfAbsent(key, invocation);
    }
}
 
Example 6
Source File: CorbaStreamOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message msg) {
    CorbaMessage message = (CorbaMessage) msg;
    orb = (org.omg.CORBA.ORB) message.get(CorbaConstants.ORB);
    Exchange exchange = message.getExchange();
    service = exchange.getEndpoint().getEndpointInfo().getService();
    typeMap = message.getCorbaTypeMap();
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    if (ContextUtils.isRequestor(message)) {
        handleOutBoundMessage(message, boi);
    } else {
        handleInBoundMessage(message, boi);
    }
    message.getInterceptorChain().add(new CorbaStreamOutEndingInterceptor());
}
 
Example 7
Source File: CorbaStreamOutEndingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message msg) {
    CorbaMessage message = (CorbaMessage) msg;
    orb = (org.omg.CORBA.ORB) message.get(CorbaConstants.ORB);
    Exchange exchange = message.getExchange();
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    service = exchange.getEndpoint().getEndpointInfo().getService();
    typeMap = message.getCorbaTypeMap();

    if (ContextUtils.isRequestor(message)) {
        handleOutBoundMessage(message, boi);
    } else {
        handleInBoundMessage(message, boi);
    }

}
 
Example 8
Source File: OutgoingChainInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    Exchange ex = message.getExchange();
    BindingOperationInfo binding = ex.getBindingOperationInfo();
    //if we get this far, we're going to be outputting some valid content, but we COULD
    //also be "echoing" some of the content from the input.   Thus, we need to
    //mark it as requiring the input to be cached.
    if (message.getExchange().get(CACHE_INPUT_PROPERTY) == null) {
        message.put(CACHE_INPUT_PROPERTY, Boolean.TRUE);
    }
    if (null != binding && null != binding.getOperationInfo() && binding.getOperationInfo().isOneWay()) {
        closeInput(message);
        return;
    }
    Message out = ex.getOutMessage();
    if (out != null) {
        try {
            getBackChannelConduit(message);
        } catch (IOException ioe) {
            throw new Fault(ioe);
        }
        if (binding != null) {
            out.put(MessageInfo.class, binding.getOperationInfo().getOutput());
            out.put(BindingMessageInfo.class, binding.getOutput());
        }

        InterceptorChain outChain = out.getInterceptorChain();
        if (outChain == null) {
            outChain = OutgoingChainInterceptor.getChain(ex, chainCache);
            out.setInterceptorChain(outChain);
        } else if (outChain.getState() == InterceptorChain.State.PAUSED) {
            outChain.resume();
            return;
        }
        outChain.doIntercept(out);

    }
}
 
Example 9
Source File: ServiceUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static SchemaValidationType getSchemaValidationTypeFromModel(Message message) {
    Exchange exchange = message.getExchange();
    SchemaValidationType validationType = null;

    if (exchange != null) {

        BindingOperationInfo boi = exchange.getBindingOperationInfo();
        if (boi != null) {
            OperationInfo opInfo = boi.getOperationInfo();
            if (opInfo != null) {
                validationType = getSchemaValidationTypeFromModel(opInfo);
            }
        }

        if (validationType == null) {
            Endpoint endpoint = exchange.getEndpoint();
            if (endpoint != null) {
                EndpointInfo ep = endpoint.getEndpointInfo();
                if (ep != null) {
                    validationType = getSchemaValidationTypeFromModel(ep);
                }
            }
        }
    }

    return validationType;
}
 
Example 10
Source File: BareOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    Exchange exchange = message.getExchange();
    BindingOperationInfo operation = exchange.getBindingOperationInfo();

    if (operation == null) {
        return;
    }

    MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return;
    }

    List<MessagePartInfo> parts = null;
    BindingMessageInfo bmsg = null;
    boolean client = isRequestor(message);

    if (!client) {
        if (operation.getOutput() != null) {
            bmsg = operation.getOutput();
            parts = bmsg.getMessageParts();
        } else {
            // partial response to oneway
            return;
        }
    } else {
        bmsg = operation.getInput();
        parts = bmsg.getMessageParts();
    }

    writeParts(message, exchange, operation, objs, parts);
}
 
Example 11
Source File: ColocInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message msg) throws Fault {
    Exchange ex = msg.getExchange();
    if (ex.isOneWay()) {
        return;
    }

    Bus bus = ex.getBus();
    SortedSet<Phase> phases = new TreeSet<>(bus.getExtension(PhaseManager.class).getOutPhases());

    //TODO Set Coloc FaultObserver chain
    ColocUtil.setPhases(phases, Phase.SETUP, Phase.USER_LOGICAL);
    InterceptorChain chain = ColocUtil.getOutInterceptorChain(ex, phases);

    if (LOG.isLoggable(Level.FINER)) {
        LOG.finer("Processing Message at collocated endpoint.  Response message: " + msg);
    }

    //Initiate OutBound Processing
    BindingOperationInfo boi = ex.getBindingOperationInfo();
    Message outBound = ex.getOutMessage();
    if (boi != null) {
        outBound.put(MessageInfo.class,
                     boi.getOperationInfo().getOutput());
    }

    outBound.put(Message.INBOUND_MESSAGE, Boolean.FALSE);
    outBound.setInterceptorChain(chain);
    chain.doIntercept(outBound);
}
 
Example 12
Source File: WrappedMessageContext.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static BindingOperationInfo getBindingOperationInfo(Exchange exchange) {
    if (exchange != null && exchange.getBindingOperationInfo() != null) {
        return exchange.getBindingOperationInfo();
    }
    return null;
}
 
Example 13
Source File: WrapperClassOutInterceptor.java    From cxf with 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 14
Source File: XMLMessageInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    if (isGET(message)) {
        LOG.fine("XMLMessageInInterceptor skipped in HTTP GET method");
        return;
    }
    Endpoint ep = message.getExchange().getEndpoint();

    XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
    if (xsr == null) {
        return;
    }
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xsr);
    if (!StaxUtils.toNextElement(reader)) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OPERATION_ELEMENT", LOG));
    }

    Exchange ex = message.getExchange();
    QName startQName = reader.getName();
    // handling xml fault message
    if (startQName.getLocalPart().equals(XMLFault.XML_FAULT_ROOT)) {
        message.getInterceptorChain().abort();

        if (ep.getInFaultObserver() != null) {
            ep.getInFaultObserver().onMessage(message);
            return;
        }
    }
    // handling xml normal inbound message
    BindingOperationInfo boi = ex.getBindingOperationInfo();
    boolean isRequestor = isRequestor(message);
    if (boi == null) {
        BindingInfo service = ep.getEndpointInfo().getBinding();
        boi = getBindingOperationInfo(isRequestor, startQName, service, xsr);
        if (boi != null) {
            ex.put(BindingOperationInfo.class, boi);
            ex.setOneWay(boi.getOperationInfo().isOneWay());
        }
    } else {
        BindingMessageInfo bmi = isRequestor ? boi.getOutput() : boi.getInput();

        if (hasRootNode(bmi, startQName)) {
            try {
                xsr.nextTag();
            } catch (XMLStreamException xse) {
                throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC", LOG));
            }
        }
    }
}
 
Example 15
Source File: ColocMessageObserver.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void onMessage(Message m) {
    Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
    ClassLoaderHolder origLoader = null;
    try {
        if (loader != null) {
            origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
        }
        if (LOG.isLoggable(Level.FINER)) {
            LOG.finer("Processing Message at collocated endpoint.  Request message: " + m);
        }
        Exchange ex = new ExchangeImpl();
        setExchangeProperties(ex, m);

        Message inMsg = endpoint.getBinding().createMessage();
        MessageImpl.copyContent(m, inMsg);

        //Copy Request Context to Server inBound Message
        //TODO a Context Filter Strategy required.
        inMsg.putAll(m);

        inMsg.put(COLOCATED, Boolean.TRUE);
        inMsg.put(Message.REQUESTOR_ROLE, Boolean.FALSE);
        inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
        BindingOperationInfo boi = ex.getBindingOperationInfo();
        OperationInfo oi = boi != null ? boi.getOperationInfo() : null;
        if (oi != null) {
            inMsg.put(MessageInfo.class, oi.getInput());
        }
        ex.setInMessage(inMsg);
        inMsg.setExchange(ex);

        if (LOG.isLoggable(Level.FINEST)) {
            LOG.finest("Build inbound interceptor chain.");
        }

        //Add all interceptors between USER_LOGICAL and INVOKE.
        SortedSet<Phase> phases = new TreeSet<>(bus.getExtension(PhaseManager.class).getInPhases());
        ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.INVOKE);
        InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases);
        chain.add(addColocInterceptors());
        inMsg.setInterceptorChain(chain);

        //Convert the coloc object type if necessary
        BindingOperationInfo bop = m.getExchange().getBindingOperationInfo();
        OperationInfo soi = bop != null ? bop.getOperationInfo() : null;
        if (soi != null && oi != null) {
            if (ColocUtil.isAssignableOperationInfo(soi, Source.class)
                && !ColocUtil.isAssignableOperationInfo(oi, Source.class)) {
                // converting source -> pojo
                ColocUtil.convertSourceToObject(inMsg);
            } else if (ColocUtil.isAssignableOperationInfo(oi, Source.class)
                && !ColocUtil.isAssignableOperationInfo(soi, Source.class)) {
                // converting pojo -> source
                ColocUtil.convertObjectToSource(inMsg);
            }
        }
        chain.doIntercept(inMsg);
        if (soi != null && oi != null) {
            if (ColocUtil.isAssignableOperationInfo(soi, Source.class)
                && !ColocUtil.isAssignableOperationInfo(oi, Source.class)
                && ex.getOutMessage() != null) {
                // converting pojo -> source
                ColocUtil.convertObjectToSource(ex.getOutMessage());
            } else if (ColocUtil.isAssignableOperationInfo(oi, Source.class)
                && !ColocUtil.isAssignableOperationInfo(soi, Source.class)
                && ex.getOutMessage() != null) {
                // converting pojo -> source
                ColocUtil.convertSourceToObject(ex.getOutMessage());
            }
        }
        //Set Server OutBound Message onto InBound Exchange.
        setOutBoundMessage(ex, m.getExchange());
    } finally {
        if (origBus != bus) {
            BusFactory.setThreadDefaultBus(origBus);
        }
        if (origLoader != null) {
            origLoader.reset();
        }
    }
}
 
Example 16
Source File: ColocOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    if (bus == null) {
        bus = message.getExchange().getBus();
        if (bus == null) {
            bus = BusFactory.getDefaultBus(false);
        }
        if (bus == null) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("BUS_NOT_FOUND", BUNDLE));
        }
    }

    ServerRegistry registry = bus.getExtension(ServerRegistry.class);

    if (registry == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("SERVER_REGISTRY_NOT_FOUND", BUNDLE));
    }

    Exchange exchange = message.getExchange();
    Endpoint senderEndpoint = exchange.getEndpoint();

    if (senderEndpoint == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("ENDPOINT_NOT_FOUND",
                                                               BUNDLE));
    }

    BindingOperationInfo boi = exchange.getBindingOperationInfo();

    if (boi == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("OPERATIONINFO_NOT_FOUND",
                                                               BUNDLE));
    }

    Server srv = isColocated(registry.getServers(), senderEndpoint, boi);

    if (srv != null) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Operation:" + boi.getName() + " dispatched as colocated call.");
        }

        InterceptorChain outChain = message.getInterceptorChain();
        outChain.abort();
        exchange.put(Bus.class, bus);
        message.put(COLOCATED, Boolean.TRUE);
        message.put(Message.WSDL_OPERATION, boi.getName());
        message.put(Message.WSDL_INTERFACE, boi.getBinding().getInterface().getName());
        invokeColocObserver(message, srv.getEndpoint());
        if (!exchange.isOneWay()) {
            invokeInboundChain(exchange, senderEndpoint);
        }
    } else {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Operation:" + boi.getName() + " dispatched as remote call.");
        }

        message.put(COLOCATED, Boolean.FALSE);
    }
}
 
Example 17
Source File: CorbaStreamInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void handleReply(Message msg) {
    ORB orb;
    ServiceInfo service;
    CorbaDestination destination;
    if (msg.getDestination() != null) {
        destination = (CorbaDestination)msg.getDestination();
    } else {
        destination = (CorbaDestination)msg.getExchange().getDestination();
    }
    service = destination.getBindingInfo().getService();

    CorbaMessage message = (CorbaMessage)msg;
    if (message.getStreamableException() != null || message.getSystemException() != null) {
        message.setContent(Exception.class,
                           message.getExchange().getOutMessage().getContent(Exception.class));

        Endpoint ep = message.getExchange().getEndpoint();
        message.getInterceptorChain().abort();
        if (ep.getInFaultObserver() != null) {
            ep.getInFaultObserver().onMessage(message);
            return;
        }
    }

    CorbaMessage outMessage = (CorbaMessage)message.getExchange().getOutMessage();
    orb = message.getExchange().get(ORB.class);
    HandlerIterator paramIterator = new HandlerIterator(outMessage, false);

    CorbaTypeEventProducer eventProducer = null;
    Exchange exchange = message.getExchange();
    BindingOperationInfo bindingOpInfo = exchange.getBindingOperationInfo();
    BindingMessageInfo msgInfo = bindingOpInfo.getOutput();

    boolean wrap = false;
    if (bindingOpInfo.isUnwrappedCapable()) {
        wrap = true;
    }

    if (wrap) {
        // wrapper element around our args
        // REVISIT, bravi, message name same as the element name
        QName wrapperElementQName = msgInfo.getMessageInfo().getName();
        eventProducer = new WrappedParameterSequenceEventProducer(wrapperElementQName,
                                                                  paramIterator,
                                                                  service,
                                                                  orb);
    } else {
        eventProducer = new ParameterEventProducer(paramIterator,
                                                   service,
                                                   orb);
    }
    CorbaStreamReader reader = new CorbaStreamReader(eventProducer);
    message.setContent(XMLStreamReader.class, reader);
}
 
Example 18
Source File: InternalContextUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * Rebase response on replyTo
 *
 * @param reference the replyTo reference
 * @param inMAPs the inbound MAPs
 * @param inMessage the current message
 */
//CHECKSTYLE:OFF Max executable statement count limitation
public static void rebaseResponse(EndpointReferenceType reference,
                                  AddressingProperties inMAPs,
                                  final Message inMessage) {

    String namespaceURI = inMAPs.getNamespaceURI();
    if (!ContextUtils.retrievePartialResponseSent(inMessage)) {
        ContextUtils.storePartialResponseSent(inMessage);
        Exchange exchange = inMessage.getExchange();
        Message fullResponse = exchange.getOutMessage();
        Message partialResponse = ContextUtils.createMessage(exchange);
        ensurePartialResponseMAPs(partialResponse, namespaceURI);

        // ensure the inbound MAPs are available in the partial response
        // message (used to determine relatesTo etc.)
        ContextUtils.propogateReceivedMAPs(inMAPs, partialResponse);
        Destination target = inMessage.getDestination();
        if (target == null) {
            return;
        }

        try {
            if (reference == null) {
                reference = ContextUtils.getNoneEndpointReference();
            }
            Conduit backChannel = target.getBackChannel(inMessage);
            if (backChannel != null) {
                partialResponse.put(Message.PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
                partialResponse.put(Message.EMPTY_PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
                boolean robust = MessageUtils.getContextualBoolean(inMessage, Message.ROBUST_ONEWAY, false);

                if (robust) {
                    BindingOperationInfo boi = exchange.getBindingOperationInfo();
                    // insert the executor in the exchange to fool the OneWayProcessorInterceptor
                    exchange.put(Executor.class, getExecutor(inMessage));
                    // pause dispatch on current thread and resume...
                    inMessage.getInterceptorChain().pause();
                    inMessage.getInterceptorChain().resume();
                    // restore the BOI for the partial response handling
                    exchange.put(BindingOperationInfo.class, boi);
                }


                // set up interceptor chains and send message
                InterceptorChain chain =
                    fullResponse != null
                    ? fullResponse.getInterceptorChain()
                    : OutgoingChainInterceptor.getOutInterceptorChain(exchange);
                exchange.setOutMessage(partialResponse);
                partialResponse.setInterceptorChain(chain);
                exchange.put(ConduitSelector.class,
                             new PreexistingConduitSelector(backChannel,
                                                            exchange.getEndpoint()));

                if (chain != null && !chain.doIntercept(partialResponse)
                    && partialResponse.getContent(Exception.class) != null) {
                    if (partialResponse.getContent(Exception.class) instanceof Fault) {
                        throw (Fault)partialResponse.getContent(Exception.class);
                    }
                    throw new Fault(partialResponse.getContent(Exception.class));
                }
                if (chain != null) {
                    chain.reset();
                }
                exchange.put(ConduitSelector.class, new NullConduitSelector());

                if (fullResponse == null) {
                    fullResponse = ContextUtils.createMessage(exchange);
                }
                exchange.setOutMessage(fullResponse);

                Destination destination = createDecoupledDestination(
                    exchange,
                    reference);
                exchange.setDestination(destination);

            }
        } catch (Exception e) {
            LOG.log(Level.WARNING, "SERVER_TRANSPORT_REBASE_FAILURE_MSG", e);
        }
    }
}
 
Example 19
Source File: PolicyVerificationInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * Determines the effective policy, and checks if one of its alternatives
 * is supported.
 *
 * @param message
 * @throws PolicyException if none of the alternatives is supported
 */
protected void handle(Message message) {

    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (null == aim) {
        return;
    }

    Exchange exchange = message.getExchange();
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    if (null == boi) {
        LOG.fine("No binding operation info.");
        return;
    }

    Endpoint e = exchange.getEndpoint();
    if (null == e) {
        LOG.fine("No endpoint.");
        return;
    }

    Bus bus = exchange.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }

    if (MessageUtils.isPartialResponse(message)) {
        LOG.fine("Not verifying policies on inbound partial response.");
        return;
    }

    getTransportAssertions(message);

    EffectivePolicy effectivePolicy = message.get(EffectivePolicy.class);
    if (effectivePolicy == null) {
        EndpointInfo ei = e.getEndpointInfo();
        if (MessageUtils.isRequestor(message)) {
            effectivePolicy = pe.getEffectiveClientResponsePolicy(ei, boi, message);
        } else {
            effectivePolicy = pe.getEffectiveServerRequestPolicy(ei, boi, message);
        }
    }
    try {
        List<List<Assertion>> usedAlternatives = aim.checkEffectivePolicy(effectivePolicy.getPolicy());
        if (usedAlternatives != null && !usedAlternatives.isEmpty() && message.getExchange() != null) {
            message.getExchange().put("ws-policy.validated.alternatives", usedAlternatives);
        }
    } catch (PolicyException ex) {
        LOG.log(Level.SEVERE, "Inbound policy verification failed: " + ex.getMessage());
        //To check if there is ws addressing policy violation and throw WSA specific
        //exception to pass jaxws2.2 tests
        if (ex.getMessage().indexOf("Addressing") > -1) {
            throw new Fault("A required header representing a Message Addressing Property "
                                + "is not present", LOG)
                .setFaultCode(new QName("http://www.w3.org/2005/08/addressing",
                                          "MessageAddressingHeaderRequired"));
        }
        throw ex;
    }
    LOG.fine("Verified policies for inbound message.");
}