org.apache.cxf.interceptor.MessageSenderInterceptor Java Examples

The following examples show how to use org.apache.cxf.interceptor.MessageSenderInterceptor. 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: EndpointImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
public EndpointImpl(Bus bus, Service s, EndpointInfo ei) throws EndpointException {
    if (ei == null) {
        throw new NullPointerException("EndpointInfo can not be null!");
    }

    if (bus == null) {
        this.bus = BusFactory.getThreadDefaultBus();
    } else {
        this.bus = bus;
    }
    service = s;
    endpointInfo = ei;

    createBinding(endpointInfo.getBinding());

    inFaultObserver = new InFaultChainInitiatorObserver(bus);
    outFaultObserver = new OutFaultChainInitiatorObserver(bus);

    getInFaultInterceptors().add(new ClientFaultConverter());
    getOutInterceptors().add(new MessageSenderInterceptor());
    getOutFaultInterceptors().add(new MessageSenderInterceptor());
}
 
Example #2
Source File: WSDLGetInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void cleanUpOutInterceptors(Message outMessage) {
    // TODO - how can I improve this to provide a specific interceptor chain that just has the
    // stax, gzip and message sender components, while also ensuring that GZIP is only provided
    // if its already configured for the endpoint.
    Iterator<Interceptor<? extends Message>> iterator = outMessage.getInterceptorChain().iterator();
    while (iterator.hasNext()) {
        Interceptor<? extends Message> inInterceptor = iterator.next();
        if (!inInterceptor.getClass().equals(StaxOutInterceptor.class)
                && !inInterceptor.getClass().equals(GZIPOutInterceptor.class)
                && !inInterceptor.getClass().equals(MessageSenderInterceptor.class)) {
            outMessage.getInterceptorChain().remove(inInterceptor);
        }
    }

}
 
Example #3
Source File: MessageLossSimulator.java    From servicemix with Apache License 2.0 4 votes vote down vote up
public MessageLossSimulator() {
    super(Phase.PREPARE_SEND);
    addBefore(MessageSenderInterceptor.class.getName());
}
 
Example #4
Source File: MessageLossSimulator.java    From cxf with Apache License 2.0 4 votes vote down vote up
public MessageLossSimulator() {
    super(Phase.PREPARE_SEND);
    addBefore(MessageSenderInterceptor.class.getName());
}
 
Example #5
Source File: MessageLossSimulator.java    From cxf with Apache License 2.0 4 votes vote down vote up
public MessageLossSimulator() {
    super(Phase.PREPARE_SEND);
    addBefore(MessageSenderInterceptor.class.getName());
}
 
Example #6
Source File: MessageLossSimulator.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true);
    String action = null;
    if (maps != null && null != maps.getAction()) {
        action = maps.getAction().getValue();
    }
    if (RMContextUtils.isRMProtocolMessage(action)) {
        return;
    }
    if (MessageUtils.isPartialResponse(message)) {
        return;
    }
    if (Boolean.TRUE.equals(message.get(RMMessageConstants.RM_RETRANSMISSION))) {
        return;
    }

    if (mode == 1) {
        // never lose
        return;
    } else if (mode == -1) {
        // always lose
    } else {
        // alternatively lose
        synchronized (this) {
            appMessageCount++;
            if (0 != (appMessageCount % 2)) {
                return;
            }
        }
    }

    InterceptorChain chain = message.getInterceptorChain();
    ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
    while (it.hasNext()) {
        PhaseInterceptor<?> pi = (PhaseInterceptor<? extends Message>)it.next();
        if (MessageSenderInterceptor.class.getName().equals(pi.getId())) {
            chain.remove(pi);
            LOG.fine("Removed MessageSenderInterceptor from interceptor chain.");
            break;
        }
    }

    message.setContent(OutputStream.class, new WrappedOutputStream(message));

    message.getInterceptorChain().add(new MessageLossEndingInterceptor(throwsException));
}
 
Example #7
Source File: RetransmissionInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public RetransmissionInterceptor() {
    super(Phase.PREPARE_SEND);
    addAfter(MessageSenderInterceptor.class.getName());
    addBefore(GZIPOutInterceptor.class.getName());
}
 
Example #8
Source File: MetricsMessageOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public MetricsMessageOutInterceptor(MetricsProvider[] p) {
    super(Phase.PREPARE_SEND_ENDING, p);
    addBefore(MessageSenderInterceptor.MessageSenderEndingInterceptor.class.getName());
}
 
Example #9
Source File: ResponseTimeMessageOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public ResponseTimeMessageOutInterceptor() {
    super(Phase.PREPARE_SEND_ENDING);
    addBefore(MessageSenderInterceptor.MessageSenderEndingInterceptor.class.getName());
}
 
Example #10
Source File: OutMessageRecorder.java    From cxf with Apache License 2.0 4 votes vote down vote up
public OutMessageRecorder() {
    super(Phase.PREPARE_SEND);
    addAfter(MessageSenderInterceptor.class.getName());
}
 
Example #11
Source File: GZIPOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public GZIPOutInterceptor() {
    super(Phase.PREPARE_SEND);
    addAfter(MessageSenderInterceptor.class.getName());
}
 
Example #12
Source File: GZIPOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public GZIPOutInterceptor(int threshold) {
    super(Phase.PREPARE_SEND);
    addAfter(MessageSenderInterceptor.class.getName());
    this.threshold = threshold;
}
 
Example #13
Source File: CxfClientIT.java    From pinpoint with Apache License 2.0 2 votes vote down vote up
@Test
    public void test() throws Exception {

        String address = webServer.getCallHttpUrl();

        String json = "{\"id\" : 12345, \"name\" : \"victor\"}";

        WebClient client = WebClient.create(address, true);

        ClientConfiguration configuration = WebClient.getConfig(client);

        // add logging interceptor
        configuration.getInInterceptors().add(new LoggingInInterceptor());
        configuration.getOutInterceptors().add(new LoggingOutInterceptor());

        client.path("/test1").accept("application/json").type("application/json; charset=UTF-8").post(json).close();

        PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();

        verifier.printCache();

        verifier.ignoreServiceType("JDK_HTTPURLCONNECTOR");

        verifier.verifyTrace(event("CXF_MESSAGE_SENDER", MessageSenderInterceptor.class.getDeclaredMethod("handleMessage", Message.class)));

        verifier.verifyTrace(event("CXF_LOGGING_OUT", LoggingOutInterceptor.class.getDeclaredMethod("formatLoggingMessage", LoggingMessage.class),
                annotation("cxf.address", address + "/test1"),
                annotation("cxf.http.method", "POST"),
                annotation("cxf.content.type", "application/json; charset=UTF-8"),
                annotation("cxf.headers", "{Accept=[application/json], Content-Type=[application/json; charset=UTF-8]}"),
                annotation("cxf.payload", "{\"id\" : 12345, \"name\" : \"victor\"}")
        ));

//        verifier.verifyTrace(event("CXF_LOGGING_IN", LoggingInInterceptor.class.getDeclaredMethod("formatLoggingMessage", LoggingMessage.class),
//                annotation("cxf.response.code", "200"),
//                annotation("cxf.encoding", "ISO-8859-1"),
//                annotation("cxf.content.type", "text/html"),
//                annotation("cxf.headers", "{connection=[keep-alive], Content-Length=[2], content-type=[text/html], Date=[" + new Date() + "]}"),
//                annotation("cxf.payload", "{}")
//        ));

        verifier.verifyTraceCount(1);

        client.close();

    }