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

The following examples show how to use org.apache.cxf.message.Exchange#put() . 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: DocLiteralInInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void setUpUsingDocLit() throws Exception {
    String ns = "http://apache.org/hello_world_doc_lit_bare";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass()
        .getResource("/wsdl/jaxb/doc_lit_bare.wsdl").toString(), new QName(ns, "SOAPService"));

    service = factory.create();
    endpointInfo = service.getEndpointInfo(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] {TradePriceData.class}));
    service.setDataBinding(db);

    operation = endpointInfo.getBinding().getOperation(new QName(ns, "SayHi"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);
    operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);

    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);

    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
 
Example 2
Source File: SecureAnnotationsInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    method = TestService.class.getMethod("echo", new Class[]{});
    message.put(SecurityContext.class, new TestSecurityContext());
    Exchange ex = new ExchangeImpl();
    message.setExchange(ex);

    Service service = EasyMock.createMock(Service.class);
    ex.put(Service.class, service);
    MethodDispatcher md = EasyMock.createMock(MethodDispatcher.class);
    EasyMock.expect(service.get(MethodDispatcher.class.getName())).andReturn(md);

    BindingOperationInfo boi = EasyMock.createMock(BindingOperationInfo.class);
    ex.put(BindingOperationInfo.class, boi);
    EasyMock.expect(md.getMethod(boi)).andReturn(method);
    EasyMock.replay(service, md);
}
 
Example 3
Source File: DOM4JProviderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Message createMessage(boolean suppress) {
    ProviderFactory factory = ServerProviderFactory.getInstance();
    Message m = new MessageImpl();
    m.put("org.apache.cxf.http.case_insensitive_queries", false);
    Exchange e = new ExchangeImpl();
    e.put(DOM4JProvider.SUPPRESS_XML_DECLARATION, suppress);
    m.setExchange(e);
    e.setInMessage(m);
    Endpoint endpoint = EasyMock.createMock(Endpoint.class);
    endpoint.getEndpointInfo();
    EasyMock.expectLastCall().andReturn(null).anyTimes();
    endpoint.get(Application.class.getName());
    EasyMock.expectLastCall().andReturn(null);
    endpoint.size();
    EasyMock.expectLastCall().andReturn(0).anyTimes();
    endpoint.isEmpty();
    EasyMock.expectLastCall().andReturn(true).anyTimes();
    endpoint.get(ServerProviderFactory.class.getName());
    EasyMock.expectLastCall().andReturn(factory).anyTimes();
    EasyMock.replay(endpoint);
    e.put(Endpoint.class, endpoint);
    return m;
}
 
Example 4
Source File: ServiceInvokerInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInterceptor() throws Exception {
    ServiceInvokerInterceptor intc = new ServiceInvokerInterceptor();

    MessageImpl m = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    m.setExchange(exchange);
    exchange.setInMessage(m);

    exchange.setOutMessage(new MessageImpl());

    TestInvoker i = new TestInvoker();
    Endpoint endpoint = createEndpoint(i);
    exchange.put(Endpoint.class, endpoint);
    Object input = new Object();
    List<Object> lst = new ArrayList<>();
    lst.add(input);
    m.setContent(List.class, lst);

    intc.handleMessage(m);

    assertTrue(i.invoked);

    List<?> list = exchange.getOutMessage().getContent(List.class);
    assertEquals(input, list.get(0));
}
 
Example 5
Source File: DocLiteralInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected BindingOperationInfo getBindingOperationInfo(Exchange exchange, QName name,
                                                       boolean client) {
    BindingOperationInfo bop = ServiceModelUtil.getOperationForWrapperElement(exchange, name, client);
    if (bop == null) {
        bop = super.getBindingOperationInfo(exchange, name, client);
    }

    if (bop != null) {
        exchange.put(BindingOperationInfo.class, bop);
    }
    return bop;
}
 
Example 6
Source File: AbstractJAXWSHandlerInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected HandlerChainInvoker getInvoker(T message) {
    Exchange ex = message.getExchange();
    HandlerChainInvoker invoker =
        ex.get(HandlerChainInvoker.class);
    if (null == invoker) {
        invoker = new HandlerChainInvoker(binding.getHandlerChain(),
                                          isOutbound(message));
        ex.put(HandlerChainInvoker.class, invoker);
    }

    boolean outbound = isOutbound(message, ex);
    if (outbound) {
        invoker.setOutbound();
    } else {
        invoker.setInbound();
    }
    invoker.setRequestor(isRequestor(message));

    if (ex.isOneWay()
        || ((isRequestor(message) && !outbound)
            || (!isRequestor(message) && outbound))) {
        invoker.setResponseExpected(false);
    } else {
        invoker.setResponseExpected(true);
    }

    return invoker;
}
 
Example 7
Source File: CorbaStreamInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected NVList prepareArguments(CorbaMessage corbaMsg,
                                  InterfaceInfo info,
                                  OperationType opType,
                                  QName opQName,
                                  CorbaTypeMap typeMap,
                                  CorbaDestination destination,
                                  ServiceInfo service) {
    BindingInfo bInfo = destination.getBindingInfo();
    EndpointInfo eptInfo = destination.getEndPointInfo();
    BindingOperationInfo bOpInfo = bInfo.getOperation(opQName);
    OperationInfo opInfo = bOpInfo.getOperationInfo();
    Exchange exg = corbaMsg.getExchange();
    exg.put(BindingInfo.class, bInfo);
    exg.put(InterfaceInfo.class, info);
    exg.put(EndpointInfo.class, eptInfo);
    exg.put(EndpointReferenceType.class, destination.getAddress());
    exg.put(ServiceInfo.class, service);
    exg.put(BindingOperationInfo.class, bOpInfo);
    exg.put(OperationInfo.class, opInfo);
    exg.put(MessageInfo.class, opInfo.getInput());
    exg.put(String.class, opQName.getLocalPart());
    exg.setInMessage(corbaMsg);

    corbaMsg.put(MessageInfo.class, opInfo.getInput());

    List<ParamType> paramTypes = opType.getParam();
    CorbaStreamable[] arguments = new CorbaStreamable[paramTypes.size()];
    return prepareDIIArgsList(corbaMsg, bOpInfo,
                              arguments, paramTypes,
                              typeMap,
                              exg.get(ORB.class), service);
}
 
Example 8
Source File: HTTPConduit.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected int doProcessResponseCode() throws IOException {
    Exchange exchange = outMessage.getExchange();
    int rc = getResponseCode();
    if (rc == -1) {
        LOG.warning("HTTP Response code appears to be corrupted");
    }
    if (exchange != null) {
        exchange.put(Message.RESPONSE_CODE, rc);
        if (rc == 404 || rc == 503) {
            exchange.put("org.apache.cxf.transport.service_not_available", true);
        }
    }

    // "org.apache.cxf.transport.no_io_exceptions" property should be set in case the exceptions
    // should not be handled here; for example jax rs uses this

    // "org.apache.cxf.transport.process_fault_on_http_400" property should be set in case a
    // soap fault because of a HTTP 400 should be returned back to the client (SOAP 1.2 spec)

    if (rc >= 400 && rc != 500
        && !MessageUtils.getContextualBoolean(outMessage, NO_IO_EXCEPTIONS)
        && (rc > 400 || !MessageUtils.getContextualBoolean(outMessage, PROCESS_FAULT_ON_HTTP_400))) {

        throw new HTTPException(rc, getResponseMessage(), url.toURL());
    }
    return rc;
}
 
Example 9
Source File: ExceptionUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Message createMessage() {
    Message m = new MessageImpl();
    Exchange e = new ExchangeImpl();
    m.setExchange(e);
    e.setInMessage(m);
    e.put("org.apache.cxf.jaxrs.provider.ServerProviderFactory", ServerProviderFactory.getInstance());
    return m;
}
 
Example 10
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 11
Source File: SpnegoContextTokenInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
private void unmapSecurityProps(Message message) {
    Exchange ex = message.getExchange();
    for (String s : SecurityConstants.ALL_PROPERTIES) {
        Object v = message.getContextualProperty(s);
        if (v != null) {
            ex.put(s, v);
        }
    }
}
 
Example 12
Source File: SelectMethodCandidatesTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Message createMessage(boolean setKeepSubProp) {
    Message m = new MessageImpl();
    m.put("org.apache.cxf.http.case_insensitive_queries", false);
    if (setKeepSubProp) {
        m.put("keep.subresource.candidates", true);
    }
    Exchange e = new ExchangeImpl();
    m.setExchange(e);
    e.setInMessage(m);
    Endpoint endpoint = mockEndpoint();
    e.put(Endpoint.class, endpoint);
    return m;
}
 
Example 13
Source File: SecureConversationInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
private void unmapSecurityProps(Message message) {
    Exchange ex = message.getExchange();
    for (String s : SecurityConstants.ALL_PROPERTIES) {
        Object v = message.getContextualProperty(s + ".sct");
        if (v != null) {
            ex.put(s, v);
        }
    }
}
 
Example 14
Source File: AbstractLoggingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void createExchangeId(Message message) {
    Exchange exchange = message.getExchange();
    String exchangeId = (String)exchange.get(LogEvent.KEY_EXCHANGE_ID);
    if (exchangeId == null) {
        exchangeId = UUID.randomUUID().toString();
        exchange.put(LogEvent.KEY_EXCHANGE_ID, exchangeId);
    }
}
 
Example 15
Source File: SpnegoContextTokenInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void unmapSecurityProps(Message message) {
    Exchange ex = message.getExchange();
    for (String s : SecurityConstants.ALL_PROPERTIES) {
        Object v = message.getContextualProperty(s);
        if (v != null) {
            ex.put(s, v);
        }
    }
}
 
Example 16
Source File: SecureConversationInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
private void unmapSecurityProps(Message message) {
    Exchange ex = message.getExchange();
    for (String s : SecurityConstants.ALL_PROPERTIES) {
        Object v = message.getContextualProperty(s + ".sct");
        if (v != null) {
            ex.put(s, v);
        }
    }
}
 
Example 17
Source File: SpnegoContextTokenInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
private void unmapSecurityProps(Message message) {
    Exchange ex = message.getExchange();
    for (String s : SecurityConstants.ALL_PROPERTIES) {
        Object v = message.getContextualProperty(s);
        if (v != null) {
            ex.put(s, v);
        }
    }
}
 
Example 18
Source File: WadlGeneratorJsonTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Message mockMessage(String baseAddress, String pathInfo, String query,
                            ClassResourceInfo cri) throws Exception {
    Message m = new MessageImpl();
    Exchange e = new ExchangeImpl();
    e.put(Service.class, new JAXRSServiceImpl(Collections.singletonList(cri)));
    m.setExchange(e);
    control.reset();
    ServletDestination d = control.createMock(ServletDestination.class);
    EndpointInfo epr = new EndpointInfo();
    epr.setAddress(baseAddress);
    d.getEndpointInfo();
    EasyMock.expectLastCall().andReturn(epr).anyTimes();

    Endpoint endpoint = new EndpointImpl(null, null, epr);
    e.put(Endpoint.class, endpoint);

    e.setDestination(d);
    BindingInfo bi = control.createMock(BindingInfo.class);
    epr.setBinding(bi);
    bi.getProperties();
    EasyMock.expectLastCall().andReturn(Collections.emptyMap()).anyTimes();
    m.put(Message.REQUEST_URI, pathInfo);
    m.put(Message.QUERY_STRING, query);
    m.put(Message.HTTP_REQUEST_METHOD, "GET");
    control.replay();
    return m;
}
 
Example 19
Source File: AbstractInDatabindingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a BindingOperationInfo if the operation is indentified as
 * a wrapped method,  return null if it is not a wrapped method
 * (i.e., it is a bare method)
 *
 * @param exchange
 * @param name
 * @param client
 */
protected BindingOperationInfo getBindingOperationInfo(Exchange exchange, QName name,
                                                          boolean client) {
    String local = name.getLocalPart();
    if (client && local.endsWith("Response")) {
        local = local.substring(0, local.length() - 8);
    }

    BindingOperationInfo bop = ServiceModelUtil.getOperation(exchange, local);

    if (bop != null) {
        exchange.put(BindingOperationInfo.class, bop);
    }
    return bop;
}
 
Example 20
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);
}