Search in sources :

Example 11 with PhaseInterceptor

use of org.apache.cxf.phase.PhaseInterceptor in project cxf by apache.

the class TruncatedTest method truncatedInboundInterceptorInputStream.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void truncatedInboundInterceptorInputStream() throws IOException {
    Message message = new MessageImpl();
    ByteArrayInputStream inputStream = new ByteArrayInputStream("TestMessage".getBytes(StandardCharsets.UTF_8));
    message.setContent(InputStream.class, inputStream);
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    LogEventSenderMock logEventSender = new LogEventSenderMock();
    LoggingInInterceptor interceptor = new LoggingInInterceptor(logEventSender);
    // set limit to 1 byte in order to get a truncated message!
    interceptor.setLimit(1);
    Collection<PhaseInterceptor<? extends Message>> interceptors = interceptor.getAdditionalInterceptors();
    for (PhaseInterceptor intercept : interceptors) {
        intercept.handleMessage(message);
    }
    interceptor.handleMessage(message);
    LogEvent event = logEventSender.getLogEvent();
    assertNotNull(event);
    // only the first byte is read!
    assertEquals("T", event.getPayload());
    assertTrue(event.isTruncated());
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 12 with PhaseInterceptor

use of org.apache.cxf.phase.PhaseInterceptor in project ddf by codice.

the class GuestInterceptorWrapper method handleMessage.

@Override
public void handleMessage(SoapMessage msg) throws Fault {
    BundleContext context = getContext();
    PhaseInterceptor guestIntercep = null;
    Collection<ServiceReference<PhaseInterceptor>> guestIntercepRefs = null;
    if (context != null) {
        try {
            guestIntercepRefs = context.getServiceReferences(PhaseInterceptor.class, "(interceptor=guest)");
        } catch (InvalidSyntaxException e) {
        // ignore, it isn't invalid
        }
        if (guestIntercepRefs != null && guestIntercepRefs.size() > 0) {
            Iterator<ServiceReference<PhaseInterceptor>> iterator = guestIntercepRefs.iterator();
            guestIntercep = context.getService(iterator.next());
        }
        if (guestIntercep != null) {
            guestIntercep.handleMessage(msg);
        } else {
            LOGGER.debug("Guest Interceptor is not installed, ignoring");
        }
    } else {
        LOGGER.debug("Unable to acquire bundle context for guest interceptor");
    }
}
Also used : PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

PhaseInterceptor (org.apache.cxf.phase.PhaseInterceptor)12 Message (org.apache.cxf.message.Message)11 Interceptor (org.apache.cxf.interceptor.Interceptor)6 LogEvent (org.apache.cxf.ext.logging.event.LogEvent)5 Exchange (org.apache.cxf.message.Exchange)5 Test (org.junit.Test)5 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)4 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)4 MessageImpl (org.apache.cxf.message.MessageImpl)4 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)4 IOException (java.io.IOException)3 MessageSenderInterceptor (org.apache.cxf.interceptor.MessageSenderInterceptor)3 AbstractWrappedOutputStream (org.apache.cxf.io.AbstractWrappedOutputStream)3 AbstractPhaseInterceptor (org.apache.cxf.phase.AbstractPhaseInterceptor)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringReader (java.io.StringReader)2 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 Fault (org.apache.cxf.interceptor.Fault)2 AttributedURIType (org.apache.cxf.ws.addressing.AttributedURIType)2