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

The following examples show how to use org.apache.cxf.message.Message#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: WSDLGetOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Document doc = (Document)message.get(WSDLGetInterceptor.DOCUMENT_HOLDER);
    if (doc == null) {
        return;
    }
    message.remove(WSDLGetInterceptor.DOCUMENT_HOLDER);

    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
    if (writer == null) {
        return;
    }
    message.put(Message.CONTENT_TYPE, "text/xml");
    try {
        StaxUtils.writeDocument(doc, writer,
                                !MessageUtils.getContextualBoolean(message,
                                                                   StaxOutInterceptor.FORCE_START_DOCUMENT,
                                                                   false),
                                true);
    } catch (XMLStreamException e) {
        throw new Fault(e);
    }
}
 
Example 2
Source File: RMDeliveryInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handle(Message message) throws SequenceFault, RMException {
    final AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, false);
    //if wsrmp:RMAssertion and addressing is optional
    if (maps == null && isRMPolicyEnabled(message)) {
        return;
    }
    LOG.entering(getClass().getName(), "handleMessage");
    Destination dest = getManager().getDestination(message);
    final boolean robust =
        MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY, false);
    if (robust) {
        message.remove(RMMessageConstants.DELIVERING_ROBUST_ONEWAY);
        dest.acknowledge(message);
    }
    dest.processingComplete(message);

    // close InputStream of RMCaptureInInterceptor, to delete tmp files in filesystem
    Closeable closable = (Closeable)message.get("org.apache.cxf.ws.rm.content.closeable");
    if (null != closable) {
        try {
            closable.close();
        } catch (IOException e) {
            // Ignore
        }
    }
}
 
Example 3
Source File: PrototypeServiceReferenceResourceProvider.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void releaseInstance(Message m, Object o) {
    ((ServiceObjects)_serviceObjects).ungetService(o);

    m.remove(_messageKey);
}
 
Example 4
Source File: HttpUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void updatePath(Message m, String path) {
    String baseAddress = getBaseAddress(m);
    boolean pathSlash = path.startsWith("/");
    boolean baseSlash = baseAddress.endsWith("/");
    if (pathSlash && baseSlash) {
        path = path.substring(1);
    } else if (!pathSlash && !baseSlash) {
        path = "/" + path;
    }
    m.put(Message.REQUEST_URI, baseAddress + path);
    m.remove(REQUEST_PATH_TO_MATCH);
    m.remove(REQUEST_PATH_TO_MATCH_SLASH);
}
 
Example 5
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 6
Source File: MAPAggregatorImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Called for an incoming message.
 *
 * @param inMessage
 */
public void onMessage(Message inMessage) {
    // disposable exchange, swapped with real Exchange on correlation
    inMessage.setExchange(new ExchangeImpl());
    inMessage.getExchange().put(Bus.class, bus);
    inMessage.put(Message.DECOUPLED_CHANNEL_MESSAGE, Boolean.TRUE);
    inMessage.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_OK);

    // remove server-specific properties
    //inMessage.remove(AbstractHTTPDestination.HTTP_REQUEST);
    //inMessage.remove(AbstractHTTPDestination.HTTP_RESPONSE);
    inMessage.remove(Message.ASYNC_POST_RESPONSE_DISPATCH);
    updateResponseCode(inMessage);

    //cache this inputstream since it's defer to use in case of async
    try {
        InputStream in = inMessage.getContent(InputStream.class);
        if (in != null) {
            CachedOutputStream cos = new CachedOutputStream();
            IOUtils.copy(in, cos);
            inMessage.setContent(InputStream.class, cos.getInputStream());
        }
        observer.onMessage(inMessage);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: Destination.java    From cxf with Apache License 2.0 5 votes vote down vote up
void processingComplete(Message message) {
    SequenceType sequenceType = RMContextUtils.retrieveRMProperties(message, false).getSequence();
    if (null == sequenceType) {
        return;
    }

    DestinationSequence seq = getSequence(sequenceType.getIdentifier());

    if (null != seq) {
        long mn = sequenceType.getMessageNumber().longValue();
        seq.processingComplete(mn);
        seq.purgeAcknowledged(mn);
        // remove acknowledged undelivered message
        seq.removeDeliveringMessageNumber(mn);
        if (seq.isTerminated() && seq.allAcknowledgedMessagesDelivered()) {
            removeSequence(seq);
        }
    }
    CachedOutputStream saved = (CachedOutputStream)message.remove(RMMessageConstants.SAVED_CONTENT);
    if (saved != null) {
        saved.releaseTempFileHold();
        try {
            saved.close();
        } catch (IOException e) {
            // ignore
        }
    }
}
 
Example 8
Source File: LocalTransportFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public synchronized void onMessage(Message message) {
    try {
        message.remove(LocalConduit.DIRECT_DISPATCH);
        IOUtils.copy(message.getContent(InputStream.class), response, 1024);
        message.getContent(InputStream.class).close();
        response.close();
        inMessage = message;
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    } finally {
        written = true;
        notifyAll();
    }
}
 
Example 9
Source File: HTTPConduit.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Called for an incoming message.
 *
 * @param inMessage
 */
public void onMessage(Message inMessage) {
    // disposable exchange, swapped with real Exchange on correlation
    inMessage.setExchange(new ExchangeImpl());
    inMessage.getExchange().put(Bus.class, bus);
    inMessage.put(Message.DECOUPLED_CHANNEL_MESSAGE, Boolean.TRUE);
    // REVISIT: how to get response headers?
    //inMessage.put(Message.PROTOCOL_HEADERS, req.getXXX());
    Headers.getSetProtocolHeaders(inMessage);
    inMessage.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_OK);

    // remove server-specific properties
    inMessage.remove(AbstractHTTPDestination.HTTP_REQUEST);
    inMessage.remove(AbstractHTTPDestination.HTTP_RESPONSE);
    inMessage.remove(Message.ASYNC_POST_RESPONSE_DISPATCH);

    //cache this inputstream since it's defer to use in case of async
    try {
        InputStream in = inMessage.getContent(InputStream.class);
        if (in != null) {
            CachedOutputStream cos = new CachedOutputStream();
            IOUtils.copy(in, cos);
            inMessage.setContent(InputStream.class, cos.getInputStream());
        }
        incomingObserver.onMessage(inMessage);
    } catch (IOException e) {
        logStackTrace(e);
    }
}
 
Example 10
Source File: HttpUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static void resetRequestURI(Message m, String requestURI) {
    m.remove(REQUEST_PATH_TO_MATCH_SLASH);
    m.remove(REQUEST_PATH_TO_MATCH);
    m.put(Message.REQUEST_URI, requestURI);
}
 
Example 11
Source File: Destination.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * Acknowledges receipt of a message. If the message is the last in the
 * sequence, sends an out-of-band SequenceAcknowledgement unless there a
 * response will be sent to the acksTo address onto which the acknowldegment
 * can be piggybacked.
 *
 * @param message the message to be acknowledged
 * @throws SequenceFault if the sequence specified in
 *             <code>sequenceType</code> does not exist
 */
public void acknowledge(Message message) throws SequenceFault, RMException {
    RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
    SequenceType sequenceType = rmps.getSequence();
    if (null == sequenceType) {
        return;
    }

    DestinationSequence seq = getSequence(sequenceType.getIdentifier());

    if (null != seq) {
        if (seq.applyDeliveryAssurance(sequenceType.getMessageNumber(), message)) {
            if (PropertyUtils.isTrue(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY))) {
                return;
            }

            seq.acknowledge(message);

            if (null != rmps.getCloseSequence()) {
                seq.setLastMessageNumber(sequenceType.getMessageNumber());
                ackImmediately(seq, message);
            }
        } else {
            try {
                message.getInterceptorChain().abort();
                if (seq.sendAcknowledgement()) {
                    ackImmediately(seq, message);
                }
                Exchange exchange = message.getExchange();
                Conduit conduit = exchange.getDestination().getBackChannel(message);
                if (conduit != null) {
                    //for a one-way, the back channel could be
                    //null if it knows it cannot send anything.
                    if (seq.sendAcknowledgement()) {
                        AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
                        InternalContextUtils.rebaseResponse(null, maps, message);
                    } else {
                        Message response = createMessage(exchange);
                        response.setExchange(exchange);
                        response.remove(Message.CONTENT_TYPE);
                        conduit.prepare(response);
                        conduit.close(response);
                    }
                }
            } catch (IOException e) {
                LOG.log(Level.SEVERE, e.getMessage());
                throw new RMException(e);
            }
        }
    } else {
        ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
        RMConstants consts = protocol.getConstants();
        SequenceFaultFactory sff = new SequenceFaultFactory(consts);
        throw sff.createUnknownSequenceFault(sequenceType.getIdentifier());
    }

}
 
Example 12
Source File: AbstractHTTPDestination.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected OutputStream flushHeaders(Message outMessage, boolean getStream) throws IOException {
    if (isResponseRedirected(outMessage)) {
        return null;
    }

    cacheInput(outMessage);
    HTTPServerPolicy sp = calcServerPolicy(outMessage);
    if (sp != null) {
        new Headers(outMessage).setFromServerPolicy(sp);
    }

    OutputStream responseStream = null;
    boolean oneWay = isOneWay(outMessage);

    HttpServletResponse response = getHttpResponseFromMessage(outMessage);

    int responseCode = getReponseCodeFromMessage(outMessage);
    if (responseCode >= 300) {
        String ec = (String)outMessage.get(Message.ERROR_MESSAGE);
        if (!StringUtils.isEmpty(ec)) {
            response.sendError(responseCode, ec);
            return null;
        }
    }
    response.setStatus(responseCode);
    new Headers(outMessage).copyToResponse(response);

    outMessage.put(RESPONSE_HEADERS_COPIED, "true");

    if (hasNoResponseContent(outMessage)) {
        response.setContentLength(0);
        response.flushBuffer();
        closeResponseOutputStream(response);
    } else if (!getStream) {
        closeResponseOutputStream(response);
    } else {
        responseStream = response.getOutputStream();
    }

    if (oneWay) {
        outMessage.remove(HTTP_RESPONSE);
    }
    return responseStream;
}