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

The following examples show how to use org.apache.cxf.message.Exchange#getEndpoint() . 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: OutFaultChainInitiatorObserver.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void initializeInterceptors(Exchange ex, PhaseInterceptorChain chain) {
    Endpoint e = ex.getEndpoint();
    Client c = ex.get(Client.class);

    chain.add(getBus().getOutFaultInterceptors());
    if (c != null) {
        chain.add(c.getOutFaultInterceptors());
    }
    chain.add(e.getService().getOutFaultInterceptors());
    chain.add(e.getOutFaultInterceptors());
    chain.add(e.getBinding().getOutFaultInterceptors());
    if (e.getService().getDataBinding() instanceof InterceptorProvider) {
        chain.add(((InterceptorProvider)e.getService().getDataBinding()).getOutFaultInterceptors());
    }

    addToChain(chain, ex.getInMessage());
    addToChain(chain, ex.getOutFaultMessage());
}
 
Example 2
Source File: InFaultChainInitiatorObserver.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void initializeInterceptors(Exchange ex, PhaseInterceptorChain chain) {
    Endpoint e = ex.getEndpoint();
    Client c = ex.get(Client.class);
    InterceptorProvider ip = ex.get(InterceptorProvider.class);

    chain.add(getBus().getInFaultInterceptors());
    if (c != null) {
        chain.add(c.getInFaultInterceptors());
    } else if (ip != null) {
        chain.add(ip.getInFaultInterceptors());
    }
    chain.add(e.getService().getInFaultInterceptors());
    chain.add(e.getInFaultInterceptors());
    chain.add(e.getBinding().getInFaultInterceptors());
    if (e.getService().getDataBinding() instanceof InterceptorProvider) {
        chain.add(((InterceptorProvider)e.getService().getDataBinding()).getInFaultInterceptors());
    }

    addToChain(chain, ex.getInFaultMessage());
    addToChain(chain, ex.getOutMessage());
}
 
Example 3
Source File: LoadDistributorSequentialStrategy.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public List<Endpoint> getAlternateEndpoints(Exchange exchange) {

    // Get the list of endpoints, including the current one.
    // This part is required for most FailoverStrategys that provide alternate
    // target endpoints for the LoadDistributorTargetSelector.
    List<Endpoint> alternateEndpoints = getEndpoints(exchange, true);

    // Put the original endpoint at the head of the list
    // This is only required if the client wants to always try one endpoint first,
    // which is not typically desired for a load distributed configuration
    // (but is required by one of the unit tests)
    Endpoint endpoint = exchange.getEndpoint();
    String defaultAddress = endpoint.getEndpointInfo().getAddress();
    for (Endpoint alternate : alternateEndpoints) {
        if (defaultAddress.equals(alternate.getEndpointInfo().getAddress())) {
            alternateEndpoints.remove(alternate);
            alternateEndpoints.add(0, alternate);
            break;
        }
    }

    return alternateEndpoints;
}
 
Example 4
Source File: ColocUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static InterceptorChain getInInterceptorChain(Exchange ex, SortedSet<Phase> phases) {
    Bus bus = ex.getBus();
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);

    Endpoint ep = ex.getEndpoint();
    List<Interceptor<? extends Message>> il = ep.getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + il);
    }
    chain.add(il);
    il = ep.getService().getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by service: " + il);
    }
    chain.add(il);
    il = bus.getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by bus: " + il);
    }
    chain.add(il);

    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        il = ((InterceptorProvider)ep.getService().getDataBinding()).getInInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by databinding: " + il);
        }
        chain.add(il);
    }
    chain.setFaultObserver(new ColocOutFaultObserver(bus));
    modifyChain(chain, ex, true);
    return chain;
}
 
Example 5
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 6
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 7
Source File: ColocUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static InterceptorChain getOutInterceptorChain(Exchange ex, SortedSet<Phase> phases) {
    Bus bus = ex.getBus();
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);

    Endpoint ep = ex.getEndpoint();
    List<Interceptor<? extends Message>> il = ep.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + il);
    }
    chain.add(il);
    il = ep.getService().getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by service: " + il);
    }
    chain.add(il);
    il = bus.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by bus: " + il);
    }
    chain.add(il);

    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        il = ((InterceptorProvider)ep.getService().getDataBinding()).getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by databinding: " + il);
        }
        chain.add(il);
    }
    modifyChain(chain, ex, false);

    return chain;
}
 
Example 8
Source File: AbstractStaticFailoverStrategy.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Get the endpoints for this invocation.
 *
 * @param exchange the current Exchange
 * @param acceptCandidatesWithSameAddress true to accept candidates with the same address
 * @return a List of alternate endpoints if available
 */
protected List<Endpoint> getEndpoints(Exchange exchange, boolean acceptCandidatesWithSameAddress) {
    Endpoint endpoint = exchange.getEndpoint();
    Collection<ServiceInfo> services = endpoint.getService().getServiceInfos();
    
    // If there are no services associated with this endpoint (often in case of JAX-RS), 
    // returning the endpoint itself if allowed.
    if (services.isEmpty() && acceptCandidatesWithSameAddress) {
        return Collections.singletonList(endpoint);
    }
    
    QName currentBinding = endpoint.getBinding().getBindingInfo().getName();
    List<Endpoint> alternates = new ArrayList<>();
    for (ServiceInfo service : services) {
        Collection<EndpointInfo> candidates = service.getEndpoints();
        for (EndpointInfo candidate : candidates) {
            QName candidateBinding = candidate.getBinding().getName();
            if (candidateBinding.equals(currentBinding)) {
                if (acceptCandidatesWithSameAddress || !candidate.getAddress().equals(
                         endpoint.getEndpointInfo().getAddress())) {
                    Endpoint alternate =
                        endpoint.getService().getEndpoints().get(candidate.getName());
                    if (alternate != null) {
                        if (LOG.isLoggable(Level.FINE)) {
                            LOG.log(Level.FINE,
                                    "FAILOVER_CANDIDATE_ACCEPTED",
                                    candidate.getName());
                        }
                        alternates.add(alternate);
                    }
                }
            } else if (LOG.isLoggable(Level.FINE)) {
                LOG.log(Level.FINE,
                        "FAILOVER_CANDIDATE_REJECTED",
                        new Object[] {candidate.getName(), candidateBinding});
            }
        }
    }
    return alternates;
}
 
Example 9
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 10
Source File: RedeliveryQueueImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static InterceptorChain getRedeliveryInterceptorChain(Message m, String phase) {
    Exchange exchange = m.getExchange();
    Endpoint ep = exchange.getEndpoint();
    Bus bus = exchange.getBus();

    PhaseManager pm = bus.getExtension(PhaseManager.class);
    SortedSet<Phase> phases = new TreeSet<>(pm.getInPhases());
    for (Iterator<Phase> it = phases.iterator(); it.hasNext();) {
        Phase p = it.next();
        if (phase.equals(p.getName())) {
            break;
        }
        it.remove();
    }
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    List<Interceptor<? extends Message>> il = ep.getInInterceptors();
    addInterceptors(chain, il);
    il = ep.getService().getInInterceptors();
    addInterceptors(chain, il);
    il = ep.getBinding().getInInterceptors();
    addInterceptors(chain, il);
    il = bus.getInInterceptors();
    addInterceptors(chain, il);
    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        il = ((InterceptorProvider)ep.getService().getDataBinding()).getInInterceptors();
        addInterceptors(chain, il);
    }

    return chain;
}
 
Example 11
Source File: MAPAggregatorImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private EndpointReferenceType getReplyTo(Message message,
                                         EndpointReferenceType originalReplyTo) {
    Exchange exchange = message.getExchange();
    Endpoint info = exchange.getEndpoint();
    if (info == null) {
        return originalReplyTo;
    }
    synchronized (info) {
        EndpointInfo ei = info.getEndpointInfo();
        Destination dest = ei.getProperty(DECOUPLED_DESTINATION, Destination.class);
        if (dest == null) {
            dest = createDecoupledDestination(message);
            if (dest != null) {
                info.getEndpointInfo().setProperty(DECOUPLED_DESTINATION, dest);
            }
        }
        if (dest != null) {
            // if the decoupled endpoint context prop is set and the address is relative, return the absolute url.
            final String replyTo = dest.getAddress().getAddress().getValue();
            if (replyTo.startsWith("/")) {
                String debase =
                    (String)message.getContextualProperty(WSAContextUtils.DECOUPLED_ENDPOINT_BASE_PROPERTY);
                if (debase != null) {
                    return EndpointReferenceUtils.getEndpointReference(debase + replyTo);
                }
            }
            return dest.getAddress();
        }
    }
    return originalReplyTo;
}
 
Example 12
Source File: ServiceModelUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static BindingOperationInfo getOperation(Exchange exchange, String opName) {
    Endpoint ep = exchange.getEndpoint();
    if (ep == null) {
        return null;
    }
    BindingInfo service = ep.getEndpointInfo().getBinding();

    for (BindingOperationInfo b : service.getOperations()) {
        if (b.getName().getLocalPart().equals(opName)) {
            return b;
        }
    }
    return null;
}
 
Example 13
Source File: WrappedMessageContext.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static EndpointInfo getEndpointInfo(Exchange exchange) {
    if (exchange != null) {
        Endpoint endpoint = exchange.getEndpoint();
        if (endpoint != null) {
            return endpoint.getEndpointInfo();
        }
    }
    return null;
}
 
Example 14
Source File: Servant.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Object invoke(Exchange exchange, Object o) {
    LOG.fine("Invoking on RM Endpoint");
    final ProtocolVariation protocol = RMContextUtils.getProtocolVariation(exchange.getInMessage());
    OperationInfo oi = exchange.getBindingOperationInfo().getOperationInfo();
    if (null == oi) {
        LOG.fine("No operation info.");
        return null;
    }

    if (RM10Constants.INSTANCE.getCreateSequenceOperationName().equals(oi.getName())
        || RM11Constants.INSTANCE.getCreateSequenceOperationName().equals(oi.getName())
        || RM10Constants.INSTANCE.getCreateSequenceOnewayOperationName().equals(oi.getName())
        || RM11Constants.INSTANCE.getCreateSequenceOnewayOperationName().equals(oi.getName())) {
        try {
            return Collections.singletonList(createSequence(exchange.getInMessage()));
        } catch (RuntimeException ex) {
            LOG.log(Level.WARNING, "Sequence creation rejected", ex);
            SequenceFault sf =
                new SequenceFaultFactory(protocol.getConstants()).createCreateSequenceRefusedFault();
            Endpoint e = exchange.getEndpoint();
            Binding b = null == e ? null : e.getBinding();
            if (null != b) {
                RMManager m = reliableEndpoint.getManager();
                LOG.fine("Manager: " + m);
                BindingFaultFactory bff = m.getBindingFaultFactory(b);
                Fault f = bff.createFault(sf, exchange.getInMessage());
                // log with warning instead sever, as this may happen for some delayed messages
                LogUtils.log(LOG, Level.WARNING, "SEQ_FAULT_MSG", bff.toString(f));
                throw f;
            }
            throw new Fault(sf);
        }
    } else if (RM10Constants.INSTANCE.getCreateSequenceResponseOnewayOperationName().equals(oi.getName())
        || RM11Constants.INSTANCE.getCreateSequenceResponseOnewayOperationName().equals(oi.getName())) {
        EncoderDecoder codec = protocol.getCodec();
        CreateSequenceResponseType createResponse =
            codec.convertReceivedCreateSequenceResponse(getParameter(exchange.getInMessage()));
        createSequenceResponse(createResponse, protocol);
    } else if (RM10Constants.INSTANCE.getTerminateSequenceOperationName().equals(oi.getName())
        || RM11Constants.INSTANCE.getTerminateSequenceOperationName().equals(oi.getName())) {
        Object tsr = terminateSequence(exchange.getInMessage());
        if (tsr != null) {
            return Collections.singletonList(tsr);
        }
    } else if (RM11Constants.INSTANCE.getCloseSequenceOperationName().equals(oi.getName())) {
        return Collections.singletonList(closeSequence(exchange.getInMessage()));
    }

    return null;
}
 
Example 15
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 16
Source File: SoapActionInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static void getAndSetOperation(SoapMessage message, String action, boolean strict) {
    if (StringUtils.isEmpty(action)) {
        return;
    }

    Exchange ex = message.getExchange();
    Endpoint ep = ex.getEndpoint();
    if (ep == null) {
        return;
    }

    BindingOperationInfo bindingOp = null;

    Collection<BindingOperationInfo> bops = ep.getEndpointInfo()
        .getBinding().getOperations();
    if (bops != null) {
        for (BindingOperationInfo boi : bops) {
            if (isActionMatch(message, boi, action)) {
                if (bindingOp != null) {
                    //more than one op with the same action, will need to parse normally
                    return;
                }
                bindingOp = boi;
            }
            if (matchWSAAction(boi, action)) {
                if (bindingOp != null && bindingOp != boi) {
                    //more than one op with the same action, will need to parse normally
                    return;
                }
                bindingOp = boi;
            }
        }
    }

    if (bindingOp == null) {
        if (strict) {
            //we didn't match the an operation, we'll try again later to make
            //sure the incoming message did end up matching an operation.
            //This could occur in some cases like WS-RM and WS-SecConv that will
            //intercept the message with a new endpoint/operation
            message.getInterceptorChain().add(new SoapActionInAttemptTwoInterceptor(action));
        }
        return;
    }

    ex.put(BindingOperationInfo.class, bindingOp);
}
 
Example 17
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private Message setUpMessage(SetupMessageArgs args)
    throws Exception {

    Message message = getMessage();
    Exchange exchange = getExchange();
    setUpOutbound(message, exchange, args.outbound, args.fault);
    setUpMessageProperty(message,
                         REQUESTOR_ROLE,
                         Boolean.valueOf(args.requestor));
    if (args.outbound && args.requestor) {
        if (args.usingAddressing) {
            setUpConduit(message, exchange);
        }
        setUpUsingAddressing(message, exchange, args.usingAddressing);
        if (args.usingAddressing) {
            setUpRequestor(message,
                           exchange,
                           args.oneway,
                           args.mapsInContext,
                           args.decoupled,
                           args.zeroLengthAction);
        }
    } else if (!args.requestor) {
        SetupResponderArgs srArgs = new SetupResponderArgs();
        srArgs.oneway = args.oneway;
        srArgs.outbound = args.outbound;
        srArgs.decoupled = args.decoupled;
        srArgs.zeroLengthAction = args.zeroLengthAction;
        srArgs.fault = args.fault;
        srArgs.noMessageId = args.noMessageId;

        Endpoint endpoint = control.createMock(Endpoint.class);
        exchange.getEndpoint();
        EasyMock.expectLastCall().andReturn(endpoint).anyTimes();

        setUpResponder(message,
                       exchange,
                       srArgs, 
                       endpoint);

        endpoint.getOutInterceptors();
        EasyMock.expectLastCall().andReturn(new ArrayList<Interceptor<? extends Message>>()).anyTimes();
        Service serv = control.createMock(Service.class);
        endpoint.getService();
        EasyMock.expectLastCall().andReturn(serv).anyTimes();
        serv.getOutInterceptors();
        EasyMock.expectLastCall().andReturn(new ArrayList<Interceptor<? extends Message>>()).anyTimes();
    }
    control.replay();
    return message;
}
 
Example 18
Source File: ClientImpl.java    From cxf with 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;
}
 
Example 19
Source File: OutgoingChainInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static PhaseInterceptorChain getChain(Exchange ex, PhaseChainCache chainCache) {
    Bus bus = ex.getBus();
    Binding binding = ex.getBinding();

    Endpoint ep = ex.getEndpoint();

    List<Interceptor<? extends Message>> i1 = bus.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by bus: " + i1);
    }
    List<Interceptor<? extends Message>> i2 = ep.getService().getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by service: " + i2);
    }
    List<Interceptor<? extends Message>> i3 = ep.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + i3);
    }
    List<Interceptor<? extends Message>> i4 = null;
    if (binding != null) {
        i4 = binding.getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by binding: " + i4);
        }
    }
    List<Interceptor<? extends Message>> i5 = null;
    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        i5 = ((InterceptorProvider)ep.getService().getDataBinding()).getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by databinding: " + i5);
        }
        if (i4 == null) {
            i4 = i5;
            i5 = null;
        }
    }
    PhaseInterceptorChain chain;
    if (i5 != null) {
        chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(),
                               i1, i2, i3, i4, i5);
    } else if (i4 != null) {
        chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(),
                               i1, i2, i3, i4);
    } else {
        chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(),
                               i1, i2, i3);
    }

    modifyChain(chain, ex);
    chain.setFaultObserver(ep.getOutFaultObserver());
    return chain;
}
 
Example 20
Source File: AbstractInDatabindingInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
    for (Iterator<OperationInfo> itr = operations.iterator(); itr.hasNext();) {
        OperationInfo op = itr.next();

        final BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
        if (boi == null) {
            continue;
        }
        final BindingMessageInfo msgInfo;
        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().isEmpty()) {
            // 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;
}