Java Code Examples for org.apache.cxf.message.MessageImpl#copyContent()
The following examples show how to use
org.apache.cxf.message.MessageImpl#copyContent() .
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: ColocOutInterceptor.java From cxf with Apache License 2.0 | 5 votes |
protected void invokeInboundChain(Exchange ex, Endpoint ep) { Message m = getInBoundMessage(ex); Message inMsg = ep.getBinding().createMessage(); MessageImpl.copyContent(m, inMsg); //Copy Response Context to Client inBound Message //TODO a Context Filter Strategy required. inMsg.putAll(m); inMsg.put(Message.REQUESTOR_ROLE, Boolean.TRUE); inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE); inMsg.setExchange(ex); Exception exc = inMsg.getContent(Exception.class); if (exc != null) { ex.setInFaultMessage(inMsg); ColocInFaultObserver observer = new ColocInFaultObserver(bus); observer.onMessage(inMsg); } else { //Handle Response ex.setInMessage(inMsg); PhaseManager pm = bus.getExtension(PhaseManager.class); SortedSet<Phase> phases = new TreeSet<>(pm.getInPhases()); ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.PRE_INVOKE); InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases); inMsg.setInterceptorChain(chain); chain.doIntercept(inMsg); } ex.put(ClientImpl.FINISHED, Boolean.TRUE); }
Example 2
Source File: LocalDestination.java From cxf with Apache License 2.0 | 5 votes |
@Override public void close(Message message) throws IOException { // set the pseudo status code if not set (REVISIT add this method in MessageUtils to be reused elsewhere?) Integer i = (Integer)message.get(Message.RESPONSE_CODE); if (i == null) { int code = ((message.getExchange().isOneWay() && !MessageUtils.isPartialResponse(message)) || MessageUtils.isEmptyPartialResponse(message)) ? 202 : 200; message.put(Message.RESPONSE_CODE, code); } if (Boolean.TRUE.equals(message.getExchange().get(LocalConduit.DIRECT_DISPATCH))) { final Exchange exchange = (Exchange)message.getExchange().get(LocalConduit.IN_EXCHANGE); MessageImpl copy = new MessageImpl(); copy.putAll(message); message.getContent(OutputStream.class).close(); CachedOutputStream stream = message.getContent(CachedOutputStream.class); message.setContent(OutputStream.class, stream); MessageImpl.copyContent(message, copy); copy.setContent(InputStream.class, stream.getInputStream()); stream.releaseTempFileHold(); if (exchange != null && exchange.getInMessage() == null) { exchange.setInMessage(copy); } conduit.getMessageObserver().onMessage(copy); return; } super.close(message); }
Example 3
Source File: LocalConduit.java From cxf with Apache License 2.0 | 5 votes |
private void dispatchDirect(Message message) throws IOException { if (destination.getMessageObserver() == null) { throw new IllegalStateException("Local destination does not have a MessageObserver on address " + destination.getAddress().getAddress().getValue()); } MessageImpl copy = new MessageImpl(); copy.put(IN_CONDUIT, this); copy.setDestination(destination); transportFactory.copy(message, copy); MessageImpl.copyContent(message, copy); OutputStream out = message.getContent(OutputStream.class); out.flush(); out.close(); CachedOutputStream stream = message.get(CachedOutputStream.class); copy.setContent(InputStream.class, stream.getInputStream()); copy.removeContent(CachedOutputStream.class); stream.releaseTempFileHold(); // Create a new incoming exchange and store the original exchange for the response ExchangeImpl ex = new ExchangeImpl(); ex.setInMessage(copy); ex.put(IN_EXCHANGE, message.getExchange()); ex.put(LocalConduit.DIRECT_DISPATCH, true); ex.setDestination(destination); destination.getMessageObserver().onMessage(copy); }
Example 4
Source File: ColocMessageObserver.java From cxf with Apache License 2.0 | 4 votes |
public void onMessage(Message m) { Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus); ClassLoaderHolder origLoader = null; try { if (loader != null) { origLoader = ClassLoaderUtils.setThreadContextClassloader(loader); } if (LOG.isLoggable(Level.FINER)) { LOG.finer("Processing Message at collocated endpoint. Request message: " + m); } Exchange ex = new ExchangeImpl(); setExchangeProperties(ex, m); Message inMsg = endpoint.getBinding().createMessage(); MessageImpl.copyContent(m, inMsg); //Copy Request Context to Server inBound Message //TODO a Context Filter Strategy required. inMsg.putAll(m); inMsg.put(COLOCATED, Boolean.TRUE); inMsg.put(Message.REQUESTOR_ROLE, Boolean.FALSE); inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE); BindingOperationInfo boi = ex.getBindingOperationInfo(); OperationInfo oi = boi != null ? boi.getOperationInfo() : null; if (oi != null) { inMsg.put(MessageInfo.class, oi.getInput()); } ex.setInMessage(inMsg); inMsg.setExchange(ex); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Build inbound interceptor chain."); } //Add all interceptors between USER_LOGICAL and INVOKE. SortedSet<Phase> phases = new TreeSet<>(bus.getExtension(PhaseManager.class).getInPhases()); ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.INVOKE); InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases); chain.add(addColocInterceptors()); inMsg.setInterceptorChain(chain); //Convert the coloc object type if necessary BindingOperationInfo bop = m.getExchange().getBindingOperationInfo(); OperationInfo soi = bop != null ? bop.getOperationInfo() : null; if (soi != null && oi != null) { if (ColocUtil.isAssignableOperationInfo(soi, Source.class) && !ColocUtil.isAssignableOperationInfo(oi, Source.class)) { // converting source -> pojo ColocUtil.convertSourceToObject(inMsg); } else if (ColocUtil.isAssignableOperationInfo(oi, Source.class) && !ColocUtil.isAssignableOperationInfo(soi, Source.class)) { // converting pojo -> source ColocUtil.convertObjectToSource(inMsg); } } chain.doIntercept(inMsg); if (soi != null && oi != null) { if (ColocUtil.isAssignableOperationInfo(soi, Source.class) && !ColocUtil.isAssignableOperationInfo(oi, Source.class) && ex.getOutMessage() != null) { // converting pojo -> source ColocUtil.convertObjectToSource(ex.getOutMessage()); } else if (ColocUtil.isAssignableOperationInfo(oi, Source.class) && !ColocUtil.isAssignableOperationInfo(soi, Source.class) && ex.getOutMessage() != null) { // converting pojo -> source ColocUtil.convertSourceToObject(ex.getOutMessage()); } } //Set Server OutBound Message onto InBound Exchange. setOutBoundMessage(ex, m.getExchange()); } finally { if (origBus != bus) { BusFactory.setThreadDefaultBus(origBus); } if (origLoader != null) { origLoader.reset(); } } }