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

The following examples show how to use org.apache.cxf.message.Exchange#setOneWay() . 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: AbstractJMSTester.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static void sendoutMessage(Conduit conduit,
                              Message message,
                              boolean isOneWay,
                              boolean synchronous) throws IOException {
    final Exchange exchange = new ExchangeImpl();
    exchange.setOneWay(isOneWay);
    exchange.setSynchronous(synchronous);
    message.setExchange(exchange);
    exchange.setOutMessage(message);
    conduit.prepare(message);
    try (OutputStream os = message.getContent(OutputStream.class)) {
        if (os != null) {
            os.write(MESSAGE_CONTENT.getBytes()); // TODO encoding
            return;
        }
    }
    try (Writer writer = message.getContent(Writer.class)) {
        if (writer != null) {
            writer.write(MESSAGE_CONTENT);
            return;
        }
    }
    fail("The OutputStream and Writer should not both be null");
}
 
Example 3
Source File: JAXWSMethodInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void changeToOneway(Exchange exchange) {
    exchange.setOneWay(true);
    exchange.setOutMessage(null);
    javax.servlet.http.HttpServletResponse httpresp =
        (javax.servlet.http.HttpServletResponse)exchange.getInMessage().
            get("HTTP.RESPONSE");
    if (httpresp != null) {
        httpresp.setStatus(202);
    }
}
 
Example 4
Source File: JAXRSInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setExchangeProperties(Message message,
                                   Exchange exchange,
                                   OperationResourceInfo ori,
                                   MultivaluedMap<String, String> values,
                                   int numberOfResources) {
    final ClassResourceInfo cri = ori.getClassResourceInfo();
    exchange.put(OperationResourceInfo.class, ori);
    exchange.put(JAXRSUtils.ROOT_RESOURCE_CLASS, cri);
    message.put(RESOURCE_METHOD, ori.getMethodToInvoke());
    message.put(URITemplate.TEMPLATE_PARAMETERS, values);

    String plainOperationName = ori.getMethodToInvoke().getName();
    if (numberOfResources > 1) {
        plainOperationName = cri.getServiceClass().getSimpleName() + "#" + plainOperationName;
    }
    exchange.put(RESOURCE_OPERATION_NAME, plainOperationName);

    if (ori.isOneway()
        || PropertyUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_REQUEST, null))) {
        exchange.setOneWay(true);
    }
    ResourceProvider rp = cri.getResourceProvider();
    if (rp instanceof SingletonResourceProvider) {
        //cri.isSingleton is not guaranteed to indicate we have a 'pure' singleton
        exchange.put(Message.SERVICE_OBJECT, rp.getInstance(message));
    }
}
 
Example 5
Source File: RMInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void handleFault(Message message) {
    message.put(MAPAggregator.class.getName(), true);
    if (RMContextUtils.getProtocolVariation(message) != null) {
        if (PropertyUtils.isTrue(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY))) {
            // revert the delivering entry from the destination sequence
            try {
                Destination destination = getManager().getDestination(message);
                if (destination != null) {
                    destination.releaseDeliveringStatus(message);
                }
            } catch (RMException e) {
                LOG.log(Level.WARNING, "Failed to revert the delivering status");
            }
        } else if (isRedeliveryEnabled(message) && RMContextUtils.isServerSide(message)
                   && isApplicationMessage(message) && hasValidSequence(message)) {
            getManager().getRedeliveryQueue().addUndelivered(message);
        }
    }
    // make sure the fault is returned for an ws-rm related fault or an invalid ws-rm message
    // note that OneWayProcessingInterceptor handles the robust case, hence not handled here.
    if (isProtocolFault(message)
        && !PropertyUtils.isTrue(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY))) {
        Exchange exchange = message.getExchange();
        exchange.setOneWay(false);

        final AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, true);
        if (maps != null && !ContextUtils.isGenericAddress(maps.getFaultTo())) {
            //TODO look at how we can refactor all these decoupled faultTo stuff
            exchange.setDestination(ContextUtils.createDecoupledDestination(exchange, maps.getFaultTo()));
        }
    }
}
 
Example 6
Source File: CorbaDSIServant.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void invoke(ServerRequest request) throws CorbaBindingException {
    String opName = request.operation();
    QName requestOperation = operationMap.get(opName);

    MessageImpl msgImpl = new MessageImpl();
    msgImpl.setDestination(getDestination());
    Exchange exg = new ExchangeImpl();
    exg.put(String.class, requestOperation.getLocalPart());
    exg.put(ORB.class, getOrb());
    exg.put(ServerRequest.class, request);
    msgImpl.setExchange(exg);
    CorbaMessage msg = new CorbaMessage(msgImpl);
    msg.setCorbaTypeMap(typeMap);

    // If there's no output message part in our operation then it's a oneway op
    BindingMessageInfo bindingMsgOutputInfo = null;
    BindingOperationInfo bindingOpInfo = null;
    try {
        bindingOpInfo = this.destination.getEndPointInfo().getBinding().getOperation(requestOperation);
    } catch (Exception ex) {
        throw new CorbaBindingException("Invalid Request. Operation unknown: " + opName);
    }
    if (bindingOpInfo != null) {
        bindingMsgOutputInfo = bindingOpInfo.getOutput();
        if (bindingMsgOutputInfo == null) {
            exg.setOneWay(true);
        }
    }

    // invokes the interceptors
    getObserver().onMessage(msg);
}
 
Example 7
Source File: JMSContinuationProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoContinuationForOneWay() {
    Exchange exchange = new ExchangeImpl();
    exchange.setOneWay(true);
    Message m = new MessageImpl();
    m.setExchange(exchange);
    Counter counter = EasyMock.createMock(Counter.class);
    JMSContinuationProvider provider =
        new JMSContinuationProvider(null, m, null, counter);
    assertNull(provider.getContinuation());
}
 
Example 8
Source File: DocLiteralInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void getBindingOperationForEmptyBody(Collection<OperationInfo> operations, Endpoint ep, Exchange exchange) {
    // TO DO : check duplicate operation with no input and also check if the action matches
    for (OperationInfo op : operations) {
        MessageInfo bmsg = op.getInput();
        int bPartsNum = bmsg.getMessagePartsNumber();
        if (bPartsNum == 0
            || (bPartsNum == 1
                && Constants.XSD_ANYTYPE.equals(bmsg.getFirstMessagePart().getTypeQName()))) {
            BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
            exchange.put(BindingOperationInfo.class, boi);
            exchange.setOneWay(op.isOneWay());
        }
    }
}
 
Example 9
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 10
Source File: AbstractClient.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected Message createMessage(Object body,
                                String httpMethod,
                                MultivaluedMap<String, String> headers,
                                URI currentURI,
                                Exchange exchange,
                                Map<String, Object> invocationContext,
                                boolean proxy) {
    checkClosed();
    Message m = cfg.getConduitSelector().getEndpoint().getBinding().createMessage();
    m.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    m.put(Message.INBOUND_MESSAGE, Boolean.FALSE);

    setRequestMethod(m, httpMethod);
    m.put(Message.PROTOCOL_HEADERS, headers);
    if (currentURI.isAbsolute() && currentURI.getScheme().startsWith(HTTP_SCHEME)) {
        m.put(Message.ENDPOINT_ADDRESS, currentURI.toString());
    } else {
        m.put(Message.ENDPOINT_ADDRESS, state.getBaseURI().toString());
    }

    Object requestURIProperty = cfg.getRequestContext().get(Message.REQUEST_URI);
    if (requestURIProperty == null) {
        m.put(Message.REQUEST_URI, currentURI.toString());
    } else {
        m.put(Message.REQUEST_URI, requestURIProperty.toString());
    }

    String ct = headers.getFirst(HttpHeaders.CONTENT_TYPE);
    m.put(Message.CONTENT_TYPE, ct);

    body = checkIfBodyEmpty(body, ct);
    setEmptyRequestPropertyIfNeeded(m, body);

    m.setContent(List.class, getContentsList(body));

    m.put(URITemplate.TEMPLATE_PARAMETERS, getState().getTemplates());

    PhaseInterceptorChain chain = setupOutInterceptorChain(cfg);
    chain.setFaultObserver(setupInFaultObserver(cfg));
    m.setInterceptorChain(chain);

    exchange = createExchange(m, exchange);
    exchange.put(Message.REST_MESSAGE, Boolean.TRUE);
    exchange.setOneWay("true".equals(headers.getFirst(Message.ONE_WAY_REQUEST)));
    exchange.put(Retryable.class, new RetryableImpl());

    // context
    setContexts(m, exchange, invocationContext, proxy);

    //setup conduit selector
    prepareConduitSelector(m, currentURI, proxy);

    return m;
}
 
Example 11
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;
}