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

The following examples show how to use org.apache.cxf.message.Message#getExchange() . 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: ResponseTimeMessageOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    boolean forceDisabled = Boolean.FALSE.equals(ex.get("org.apache.cxf.management.counter.enabled"));
    if (!forceDisabled && isServiceCounterEnabled(ex)) {
        if (ex.get(Exception.class) != null) {
            endHandlingMessage(ex);
            return;
        }
        if (Boolean.TRUE.equals(message.get(Message.PARTIAL_RESPONSE_MESSAGE))) {
            return;
        }
        if (isClient(message)) {
            if (ex.isOneWay()) {
                message.getInterceptorChain().add(ending);
            }
            beginHandlingMessage(ex);
        } else { // the message is handled by server
            endHandlingMessage(ex);
        }
    }
}
 
Example 2
Source File: TransformOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private String getEncoding(Message message) {
    Exchange ex = message.getExchange();
    String encoding = (String)message.get(Message.ENCODING);
    if (encoding == null && ex.getInMessage() != null) {
        encoding = (String) ex.getInMessage().get(Message.ENCODING);
        message.put(Message.ENCODING, encoding);
    }

    if (encoding == null) {
        encoding = StandardCharsets.UTF_8.name();
        message.put(Message.ENCODING, encoding);
    }
    return encoding;
}
 
Example 3
Source File: XmlSecOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private String getEncoding(Message message) {
    Exchange ex = message.getExchange();
    String encoding = (String) message.get(Message.ENCODING);
    if (encoding == null && ex.getInMessage() != null) {
        encoding = (String) ex.getInMessage().get(Message.ENCODING);
        message.put(Message.ENCODING, encoding);
    }

    if (encoding == null) {
        encoding = StandardCharsets.UTF_8.name();
        message.put(Message.ENCODING, encoding);
    }
    return encoding;
}
 
Example 4
Source File: LocalConduit.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void dispatchViaPipe(final Message message) throws IOException {
    final LocalConduit conduit = this;
    final Exchange exchange = message.getExchange();

    if (destination.getMessageObserver() == null) {
        throw new IllegalStateException("Local destination does not have a MessageObserver on address "
                                        + destination.getAddress().getAddress().getValue());
    }

    AbstractWrappedOutputStream cout
        = new LocalConduitOutputStream(conduit, exchange, message);
    message.setContent(OutputStream.class, cout);
}
 
Example 5
Source File: ClientMessageObserver.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void onMessage(Message m) {

        Message message = cfg.getConduitSelector().getEndpoint().getBinding().createMessage(m);
        message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
        message.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
        PhaseInterceptorChain chain = AbstractClient.setupInInterceptorChain(cfg);
        message.setInterceptorChain(chain);
        message.getExchange().setInMessage(message);
        Bus bus = cfg.getBus();
        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
        ClassLoaderHolder origLoader = null;
        try {
            if (loader != null) {
                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
            // execute chain
            chain.doIntercept(message);
        } finally {
            if (origBus != bus) {
                BusFactory.setThreadDefaultBus(origBus);
            }
            if (origLoader != null) {
                origLoader.reset();
            }
            synchronized (message.getExchange()) {
                message.getExchange().notifyAll();
            }
        }
    }
 
Example 6
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 7
Source File: MessageStreamUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Set Writer or OutputStream in message that calls the sender on close with
 * the content of the stream
 *
 * @param message where to set the content
 * @param isTextPayload decides about stream type true:Writer, false: OutputStream
 * @param sender will be called on close
 */
public static void prepareStream(final Message message, boolean isTextPayload,
                                 final JMSExchangeSender sender) {
    if (isTextPayload) {
        message.setContent(Writer.class, new SendingWriter(sender, message.getExchange()));
    } else {
        SendingOutputStream out = new SendingOutputStream(sender, message.getExchange());
        message.setContent(OutputStream.class, out);
    }
}
 
Example 8
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 9
Source File: ResponseTimeMessageInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void handleFault(Message message) {
    Exchange ex = message.getExchange();
    if (Boolean.TRUE.equals(ex.get("org.apache.cxf.management.counter.enabled"))) {
        FaultMode mode = message.get(FaultMode.class);
        if (mode == null) {
            mode = FaultMode.UNCHECKED_APPLICATION_FAULT;
        }
        ex.put(FaultMode.class, mode);
    }
}
 
Example 10
Source File: RMInInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void testAppMessage(boolean onServer, boolean deferredAbort)
    throws SequenceFault, RMException, NoSuchMethodException {
    Method m1 = RMInInterceptor.class.getDeclaredMethod("processAcknowledgments",
        new Class[] {RMEndpoint.class, RMProperties.class, ProtocolVariation.class});
    Method m2 = RMInInterceptor.class.getDeclaredMethod("processAcknowledgmentRequests",
        new Class[] {Destination.class, Message.class});
    Method m3 = RMInInterceptor.class.getDeclaredMethod("processSequence",
        new Class[] {Destination.class, Message.class});
    Method m4 = RMInInterceptor.class.getDeclaredMethod("processDeliveryAssurance",
        new Class[] {RMProperties.class});
    interceptor =
        EasyMock.createMockBuilder(RMInInterceptor.class)
            .addMockedMethods(m1, m2, m3, m4).createMock(control);
    Message message = setupInboundMessage("greetMe", true);
    Destination d = control.createMock(Destination.class);
    EasyMock.expect(manager.getDestination(message)).andReturn(d);
    interceptor.processAcknowledgments(rme, rmps, ProtocolVariation.RM10WSA200408);
    EasyMock.expectLastCall();
    interceptor.processAcknowledgmentRequests(d, message);
    EasyMock.expectLastCall();
    interceptor.processSequence(d, message);
    EasyMock.expectLastCall();
    interceptor.processDeliveryAssurance(rmps);
    EasyMock.expectLastCall();
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);

    Exchange ex = control.createMock(Exchange.class);
    message.getExchange();
    EasyMock.expectLastCall().andReturn(ex).anyTimes();
    ex.get("deferred.uncorrelated.message.abort");
    EasyMock.expectLastCall().andReturn(Boolean.TRUE);
    InterceptorChain chain = control.createMock(InterceptorChain.class);
    message.getInterceptorChain();
    EasyMock.expectLastCall().andReturn(chain);
    chain.abort();
    EasyMock.expectLastCall();

    control.replay();
    interceptor.handle(message);
}
 
Example 11
Source File: SecureConversationInInterceptor.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 + ".sct");
        if (v == null) {
            v = message.getContextualProperty(s);
        }
        if (v != null) {
            ex.put(s, v);
        }
    }
}
 
Example 12
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 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: ServiceUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static SchemaValidationType getSchemaValidationTypeFromModel(Message message) {
    Exchange exchange = message.getExchange();
    SchemaValidationType validationType = null;

    if (exchange != null) {

        BindingOperationInfo boi = exchange.getBindingOperationInfo();
        if (boi != null) {
            OperationInfo opInfo = boi.getOperationInfo();
            if (opInfo != null) {
                validationType = getSchemaValidationTypeFromModel(opInfo);
            }
        }

        if (validationType == null) {
            Endpoint endpoint = exchange.getEndpoint();
            if (endpoint != null) {
                EndpointInfo ep = endpoint.getEndpointInfo();
                if (ep != null) {
                    validationType = getSchemaValidationTypeFromModel(ep);
                }
            }
        }
    }

    return validationType;
}
 
Example 15
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 16
Source File: ContextUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Retreive Conduit from Exchange if not already available
 *
 * @param conduit the current value for the Conduit
 * @param message the current message
 * @return the Conduit if available
 */
public static Conduit getConduit(Conduit conduit, Message message) {
    if (conduit == null) {
        Exchange exchange = message.getExchange();
        conduit = exchange != null ? exchange.getConduit(message) : null;
    }
    return conduit;
}
 
Example 17
Source File: GiornaleEventiOutInterceptor.java    From govpay with GNU General Public License v3.0 4 votes vote down vote up
@Override
	public void handleMessage(Message message) throws Fault {
		String url = null;
		String httpMethodS = null;
		try {
			if(this.giornaleEventiConfig.isAbilitaGiornaleEventi()) {
				IContext context = ContextThreadLocal.get();
				GpContext appContext = (GpContext) context.getApplicationContext();
				EventoContext eventoCtx = appContext.getEventoCtx();
				
				Exchange exchange = message.getExchange();
				Message inMessage = exchange.getInMessage();
				final LogEvent eventRequest = new DefaultLogEventMapper().map(inMessage);
				url = eventoCtx.getUrl() != null ? eventoCtx.getUrl() : eventRequest.getAddress();
				httpMethodS = eventoCtx.getMethod() != null ? eventoCtx.getMethod() : eventRequest.getHttpMethod();
				Date dataUscita = new Date();

				Integer responseCode = 200;
				if (!Boolean.TRUE.equals(message.get(Message.DECOUPLED_CHANNEL_MESSAGE))) {
					// avoid logging the default responseCode 200 for the decoupled responses
					responseCode = (Integer)message.get(Message.RESPONSE_CODE);
				}

				this.log.debug("Log Evento API: ["+this.giornaleEventiConfig.getApiName()+"] Method ["+httpMethodS+"], Url ["+url+"], StatusCode ["+responseCode+"]");

				// informazioni gia' calcolate nell'interceptor di dump
				if(eventoCtx.isRegistraEvento()) {
					if(eventoCtx.getDettaglioRisposta() == null)
						eventoCtx.setDettaglioRisposta(new DettaglioRisposta());
					
					if(this.giornaleEventiConfig.getApiNameEnum().equals(Componente.API_PAGOPA)) {
//						HttpServletResponse httpResponse = (HttpServletResponse) message.get(AbstractHTTPDestination.HTTP_RESPONSE);
//						httpResponse.setHeader(Costanti.HEADER_NAME_OUTPUT_TRANSACTION_ID, context.getTransactionId());
						
						@SuppressWarnings("unchecked")
						Map<String, List<String>> responseHeaders = (Map<String, List<String>>)message.get(Message.PROTOCOL_HEADERS);
						if (responseHeaders != null) {
							responseHeaders.put(Costanti.HEADER_NAME_OUTPUT_TRANSACTION_ID, Arrays.asList(context.getTransactionId()));
						}
					}

					final LogEvent eventResponse = new DefaultLogEventMapper().map(message);
					eventoCtx.getDettaglioRisposta().setHeadersFromMap(eventResponse.getHeaders());
					eventoCtx.getDettaglioRisposta().setStatus(responseCode);
					eventoCtx.getDettaglioRisposta().setDataOraRisposta(dataUscita);

					eventoCtx.setDataRisposta(dataUscita);
					eventoCtx.setStatus(responseCode);
					// se non ho impostato un sottotipo esito genero uno di default che corrisponde allo status code
					if(responseCode != null && eventoCtx.getSottotipoEsito() == null)
						eventoCtx.setSottotipoEsito(responseCode + "");

					PutEventoDTO putEventoDTO = new PutEventoDTO(context.getAuthentication());
					putEventoDTO.setEvento(eventoCtx);
					this.eventiDAO.inserisciEvento(putEventoDTO);
				}
			}
		} catch (Throwable e) {
			this.log.error(e.getMessage(),e);
		} finally {
			ContextThreadLocal.unset();
		}
	}
 
Example 18
Source File: ResponseTimeMessageOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    endHandlingMessage(ex);
}
 
Example 19
Source File: ColocOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    if (bus == null) {
        bus = message.getExchange().getBus();
        if (bus == null) {
            bus = BusFactory.getDefaultBus(false);
        }
        if (bus == null) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("BUS_NOT_FOUND", BUNDLE));
        }
    }

    ServerRegistry registry = bus.getExtension(ServerRegistry.class);

    if (registry == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("SERVER_REGISTRY_NOT_FOUND", BUNDLE));
    }

    Exchange exchange = message.getExchange();
    Endpoint senderEndpoint = exchange.getEndpoint();

    if (senderEndpoint == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("ENDPOINT_NOT_FOUND",
                                                               BUNDLE));
    }

    BindingOperationInfo boi = exchange.getBindingOperationInfo();

    if (boi == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("OPERATIONINFO_NOT_FOUND",
                                                               BUNDLE));
    }

    Server srv = isColocated(registry.getServers(), senderEndpoint, boi);

    if (srv != null) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Operation:" + boi.getName() + " dispatched as colocated call.");
        }

        InterceptorChain outChain = message.getInterceptorChain();
        outChain.abort();
        exchange.put(Bus.class, bus);
        message.put(COLOCATED, Boolean.TRUE);
        message.put(Message.WSDL_OPERATION, boi.getName());
        message.put(Message.WSDL_INTERFACE, boi.getBinding().getInterface().getName());
        invokeColocObserver(message, srv.getEndpoint());
        if (!exchange.isOneWay()) {
            invokeInboundChain(exchange, senderEndpoint);
        }
    } else {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Operation:" + boi.getName() + " dispatched as remote call.");
        }

        message.put(COLOCATED, Boolean.FALSE);
    }
}
 
Example 20
Source File: AbstractJsonpOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected String getCallbackValue(Message message) {
    Exchange exchange = message.getExchange();
    return (String) exchange.get(JsonpInInterceptor.CALLBACK_KEY);
}