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

The following examples show how to use org.apache.cxf.message.Exchange#remove() . 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: ExchangeUtils.java    From fuchsia with Apache License 2.0 6 votes vote down vote up
public static void closeConduit(Exchange exchange) throws IOException {
    ConduitSelector conduitSelector = null;
    synchronized (exchange) {
        conduitSelector = exchange.get(ConduitSelector.class);
        if (conduitSelector != null) {
            exchange.remove(ConduitSelector.class.getName());
        }
    }

    Conduit selectedConduit = null;
    Message message = exchange.getInMessage() == null ? exchange
            .getOutMessage() : exchange.getInMessage();

    if (conduitSelector != null && message != null) {
        selectedConduit = conduitSelector.selectConduit(message);
        selectedConduit.close(message);
    }

    //TODO the line below was removed, check the impact on the protobuffer importer/exporter
    //selectedConduit.close(message);
}
 
Example 2
Source File: JAXRSInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
private ResourceProvider getResourceProvider(Exchange exchange) {
    Object provider = exchange.remove(JAXRSUtils.ROOT_PROVIDER);
    if (provider == null) {
        OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
        ClassResourceInfo cri = ori.getClassResourceInfo();
        return cri.getResourceProvider();
    }
    return (ResourceProvider)provider;
}
 
Example 3
Source File: JAXRSInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Object getServiceObject(Exchange exchange) {

        Object root = exchange.remove(JAXRSUtils.ROOT_INSTANCE);
        if (root != null) {
            return root;
        }

        OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
        ClassResourceInfo cri = ori.getClassResourceInfo();

        return cri.getResourceProvider().getInstance(exchange.getInMessage());
    }
 
Example 4
Source File: MEXInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    String action = (String)message.get(SoapBindingConstants.SOAP_ACTION);
    if (action == null) {
        AddressingProperties inProps = (AddressingProperties)message
            .getContextualProperty(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND);
        if (inProps != null && inProps.getAction() != null) {
            action = inProps.getAction().getValue();
        }
    }
    if ("http://schemas.xmlsoap.org/ws/2004/09/transfer/Get".equals(action)
        || "http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Request".equals(action)) {
        message.remove(AssertionInfoMap.class.getName());
        Exchange ex = message.getExchange();
        Endpoint endpoint = createEndpoint(message);
        ex.put(Endpoint.class, endpoint);
        ex.put(Service.class, endpoint.getService());
        ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
        ex.put(BindingOperationInfo.class,
               endpoint.getBinding().getBindingInfo()
                   .getOperation(new QName("http://mex.ws.cxf.apache.org/", "Get2004")));
        ex.remove(BindingOperationInfo.class);
        message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
        message.getInterceptorChain().add(endpoint.getInInterceptors());
        message.getInterceptorChain().add(endpoint.getBinding().getInInterceptors());
    }

}
 
Example 5
Source File: FailoverTargetSelector.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Called on completion of the MEP for which the Conduit was required.
 *
 * @param exchange represents the completed MEP
 */
public void complete(Exchange exchange) {
    String key = String.valueOf(System.identityHashCode(exchange));
    InvocationContext invocation = getInvocationContext(key);
    if (invocation == null) {
        super.complete(exchange);
        return;
    }

    boolean failover = false;
    final Exception ex = getExceptionIfPresent(exchange);
    if (requiresFailover(exchange, ex)) {
        onFailure(invocation, ex);
        Conduit old = (Conduit)exchange.getOutMessage().remove(Conduit.class.getName());

        Endpoint failoverTarget = getFailoverTarget(exchange, invocation);
        if (failoverTarget != null) {
            setEndpoint(failoverTarget);
            removeConduit(old);
            failover = performFailover(exchange, invocation);
        } else {
            exchange.remove(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY);
            setOriginalEndpoint(invocation);
        }
    } else {
        getLogger().fine("FAILOVER_NOT_REQUIRED");
        onSuccess(invocation);
    }

    if (!failover) {
        inProgress.remove(key);
        doComplete(exchange);
    }
}
 
Example 6
Source File: FailoverTargetSelector.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected boolean performFailover(Exchange exchange, InvocationContext invocation) {
    Exception prevExchangeFault = (Exception)exchange.remove(Exception.class.getName());
    Message outMessage = exchange.getOutMessage();
    Exception prevMessageFault = outMessage.getContent(Exception.class);
    outMessage.setContent(Exception.class, null);
    overrideAddressProperty(invocation.getContext());

    Retryable retry = exchange.get(Retryable.class);
    exchange.clear();
    boolean failover = false;
    if (retry != null) {
        try {
            failover = true;
            long delay = getDelayBetweenRetries();
            if (delay > 0) {
                Thread.sleep(delay);
            }
            retry.invoke(invocation.getBindingOperationInfo(),
                         invocation.getParams(),
                         invocation.getContext(),
                         exchange);
        } catch (Exception e) {
            if (exchange.get(Exception.class) != null) {
                exchange.put(Exception.class, prevExchangeFault);
            }
            if (outMessage.getContent(Exception.class) != null) {
                outMessage.setContent(Exception.class,
                                      prevMessageFault);
            }
        }
    }
    return failover;
}
 
Example 7
Source File: NegotiationUtils.java    From steady with Apache License 2.0 4 votes vote down vote up
static void recalcEffectivePolicy(
    SoapMessage message, 
    String namespace, 
    Policy policy,
    Invoker invoker,
    boolean secConv
) {
    Exchange ex = message.getExchange();
    Bus bus = ex.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Destination destination = ex.getDestination();
    try {
        Endpoint endpoint = message.getExchange().getEndpoint();

        TokenStore store = getTokenStore(message);
        if (secConv) {
            endpoint = STSUtils.createSCEndpoint(bus, 
                                                 namespace,
                                                 endpoint.getEndpointInfo().getTransportId(),
                                                 destination.getAddress().getAddress().getValue(),
                                                 message.getVersion().getBindingId(), 
                                                 policy);
        } else {
            endpoint = STSUtils.createSTSEndpoint(bus, 
                                                  namespace,
                                                  endpoint.getEndpointInfo().getTransportId(),
                                                  destination.getAddress().getAddress().getValue(),
                                                  message.getVersion().getBindingId(), 
                                                  policy,
                                                  null);
        } 
        endpoint.getEndpointInfo().setProperty(TokenStore.class.getName(), store);
        message.getExchange().put(TokenStore.class.getName(), store);

        EndpointPolicy ep = pe.getServerEndpointPolicy(endpoint.getEndpointInfo(), destination);
        List<Interceptor<? extends Message>> interceptors = ep.getInterceptors();
        for (Interceptor<? extends Message> i : interceptors) {
            message.getInterceptorChain().add(i);
        }

        Collection<Assertion> assertions = ep.getVocabulary();
        if (null != assertions) {
            message.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
        }
        endpoint.getService().setInvoker(invoker);
        ex.put(Endpoint.class, endpoint);
        ex.put(Service.class, endpoint.getService());
        ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
        ex.remove(BindingOperationInfo.class);
        message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
    } catch (Exception exc) {
        throw new Fault(exc);
    }
}
 
Example 8
Source File: NegotiationUtils.java    From steady with Apache License 2.0 4 votes vote down vote up
static void recalcEffectivePolicy(
    SoapMessage message, 
    String namespace, 
    Policy policy,
    Invoker invoker,
    boolean secConv
) {
    Exchange ex = message.getExchange();
    Bus bus = ex.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Destination destination = ex.getDestination();
    try {
        Endpoint endpoint = message.getExchange().getEndpoint();

        TokenStore store = getTokenStore(message);
        if (secConv) {
            endpoint = STSUtils.createSCEndpoint(bus, 
                                                 namespace,
                                                 endpoint.getEndpointInfo().getTransportId(),
                                                 destination.getAddress().getAddress().getValue(),
                                                 message.getVersion().getBindingId(), 
                                                 policy);
        } else {
            endpoint = STSUtils.createSTSEndpoint(bus, 
                                                  namespace,
                                                  endpoint.getEndpointInfo().getTransportId(),
                                                  destination.getAddress().getAddress().getValue(),
                                                  message.getVersion().getBindingId(), 
                                                  policy,
                                                  null);
        } 
        endpoint.getEndpointInfo().setProperty(TokenStore.class.getName(), store);
        message.getExchange().put(TokenStore.class.getName(), store);

        EndpointPolicy ep = pe.getServerEndpointPolicy(endpoint.getEndpointInfo(), destination);
        List<Interceptor<? extends Message>> interceptors = ep.getInterceptors();
        for (Interceptor<? extends Message> i : interceptors) {
            message.getInterceptorChain().add(i);
        }

        Collection<Assertion> assertions = ep.getVocabulary();
        if (null != assertions) {
            message.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
        }
        endpoint.getService().setInvoker(invoker);
        ex.put(Endpoint.class, endpoint);
        ex.put(Service.class, endpoint.getService());
        ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
        ex.remove(BindingOperationInfo.class);
        message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
    } catch (Exception exc) {
        throw new Fault(exc);
    }
}
 
Example 9
Source File: NegotiationUtils.java    From steady with Apache License 2.0 4 votes vote down vote up
static void recalcEffectivePolicy(
    SoapMessage message, 
    String namespace, 
    Policy policy,
    Invoker invoker,
    boolean secConv
) {
    Exchange ex = message.getExchange();
    Bus bus = ex.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Destination destination = ex.getDestination();
    try {
        Endpoint endpoint = message.getExchange().getEndpoint();

        TokenStore store = getTokenStore(message);
        if (secConv) {
            endpoint = STSUtils.createSCEndpoint(bus, 
                                                 namespace,
                                                 endpoint.getEndpointInfo().getTransportId(),
                                                 destination.getAddress().getAddress().getValue(),
                                                 message.getVersion().getBindingId(), 
                                                 policy);
        } else {
            endpoint = STSUtils.createSTSEndpoint(bus, 
                                                  namespace,
                                                  endpoint.getEndpointInfo().getTransportId(),
                                                  destination.getAddress().getAddress().getValue(),
                                                  message.getVersion().getBindingId(), 
                                                  policy,
                                                  null);
        } 
        endpoint.getEndpointInfo().setProperty(TokenStore.class.getName(), store);
        message.getExchange().put(TokenStore.class.getName(), store);

        EndpointPolicy ep = pe.getServerEndpointPolicy(endpoint.getEndpointInfo(), destination);
        List<Interceptor<? extends Message>> interceptors = ep.getInterceptors();
        for (Interceptor<? extends Message> i : interceptors) {
            message.getInterceptorChain().add(i);
        }

        Collection<Assertion> assertions = ep.getVocabulary();
        if (null != assertions) {
            message.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
        }
        endpoint.getService().setInvoker(invoker);
        ex.put(Endpoint.class, endpoint);
        ex.put(Service.class, endpoint.getService());
        ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
        ex.remove(BindingOperationInfo.class);
        message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
    } catch (Exception exc) {
        throw new Fault(exc);
    }
}
 
Example 10
Source File: NegotiationUtils.java    From steady with Apache License 2.0 4 votes vote down vote up
static void recalcEffectivePolicy(
    SoapMessage message, 
    String namespace, 
    Policy policy,
    Invoker invoker,
    boolean secConv
) {
    Exchange ex = message.getExchange();
    Bus bus = ex.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Destination destination = ex.getDestination();
    try {
        Endpoint endpoint = message.getExchange().getEndpoint();

        TokenStore store = getTokenStore(message);
        if (secConv) {
            endpoint = STSUtils.createSCEndpoint(bus, 
                                                 namespace,
                                                 endpoint.getEndpointInfo().getTransportId(),
                                                 destination.getAddress().getAddress().getValue(),
                                                 message.getVersion().getBindingId(), 
                                                 policy);
        } else {
            endpoint = STSUtils.createSTSEndpoint(bus, 
                                                  namespace,
                                                  endpoint.getEndpointInfo().getTransportId(),
                                                  destination.getAddress().getAddress().getValue(),
                                                  message.getVersion().getBindingId(), 
                                                  policy,
                                                  null);
        } 
        endpoint.getEndpointInfo().setProperty(TokenStore.class.getName(), store);
        message.getExchange().put(TokenStore.class.getName(), store);

        EndpointPolicy ep = pe.getServerEndpointPolicy(endpoint.getEndpointInfo(), destination);
        List<Interceptor<? extends Message>> interceptors = ep.getInterceptors();
        for (Interceptor<? extends Message> i : interceptors) {
            message.getInterceptorChain().add(i);
        }

        Collection<Assertion> assertions = ep.getVocabulary();
        if (null != assertions) {
            message.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
        }
        endpoint.getService().setInvoker(invoker);
        ex.put(Endpoint.class, endpoint);
        ex.put(Service.class, endpoint.getService());
        ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
        ex.remove(BindingOperationInfo.class);
        message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
    } catch (Exception exc) {
        throw new Fault(exc);
    }
}
 
Example 11
Source File: NegotiationUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
static void recalcEffectivePolicy(
    SoapMessage message,
    String namespace,
    Policy policy,
    Invoker invoker,
    boolean secConv
) {
    Exchange ex = message.getExchange();
    Bus bus = ex.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Destination destination = ex.getDestination();
    try {
        Endpoint endpoint = message.getExchange().getEndpoint();

        TokenStore store = TokenStoreUtils.getTokenStore(message);
        if (secConv) {
            endpoint = STSUtils.createSCEndpoint(bus,
                                                 namespace,
                                                 endpoint.getEndpointInfo().getTransportId(),
                                                 destination.getAddress().getAddress().getValue(),
                                                 message.getVersion().getBindingId(),
                                                 policy);
        } else {
            endpoint = STSUtils.createSTSEndpoint(bus,
                                                  namespace,
                                                  endpoint.getEndpointInfo().getTransportId(),
                                                  destination.getAddress().getAddress().getValue(),
                                                  message.getVersion().getBindingId(),
                                                  policy,
                                                  null);
        }
        endpoint.getEndpointInfo().setProperty(TokenStore.class.getName(), store);
        message.getExchange().put(TokenStore.class.getName(), store);

        EndpointPolicy ep = pe.getServerEndpointPolicy(endpoint.getEndpointInfo(), destination, message);
        List<Interceptor<? extends Message>> interceptors = ep.getInterceptors(message);
        message.getInterceptorChain().add(interceptors);

        Collection<Assertion> assertions = ep.getVocabulary(message);
        if (null != assertions) {
            message.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
        }
        endpoint.getService().setInvoker(invoker);
        ex.put(Endpoint.class, endpoint);
        ex.put(Service.class, endpoint.getService());
        ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
        ex.remove(BindingOperationInfo.class);
        message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
    } catch (Exception exc) {
        throw new Fault(exc);
    }
}
 
Example 12
Source File: FailoverTargetSelector.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void setupExchangeExceptionProperties(Exchange ex) {
    if (!isSupportNotAvailableErrorsOnly()) {
        ex.remove("org.apache.cxf.transport.no_io_exceptions");
    }
    ex.put(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY, true);
}