Search in sources :

Example 1 with PingWithArgs

use of org.apache.handler_test.types.PingWithArgs in project cxf by apache.

the class TestHandler method addHandlerId.

private void addHandlerId(LogicalMessage msg, T ctx, boolean outbound) {
    Object obj = msg.getPayload(jaxbCtx);
    if (obj instanceof PingResponse) {
        PingResponse origResp = (PingResponse) obj;
        PingResponse newResp = new PingResponse();
        newResp.getHandlersInfo().addAll(origResp.getHandlersInfo());
        newResp.getHandlersInfo().add(getHandlerId());
        msg.setPayload(newResp, jaxbCtx);
    } else if (obj instanceof Ping || obj instanceof PingWithArgs) {
        getHandlerInfoList(ctx).add(getHandlerId());
    }
}
Also used : PingWithArgs(org.apache.handler_test.types.PingWithArgs) Ping(org.apache.handler_test.types.Ping) PingResponse(org.apache.handler_test.types.PingResponse)

Example 2 with PingWithArgs

use of org.apache.handler_test.types.PingWithArgs in project cxf by apache.

the class TestHandler method handleMessage.

public boolean handleMessage(T ctx) {
    methodCalled("handleMessage");
    printHandlerInfo("handleMessage", isOutbound(ctx));
    boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    boolean ret = getHandleMessageRet();
    if (!isServerSideHandler()) {
        return true;
    }
    try {
        verifyJAXWSProperties(ctx);
    } catch (PingException e) {
        e.printStackTrace();
        throw new ProtocolException(e);
    }
    Object obj = ctx.getMessage().getPayload(jaxbCtx);
    if (obj instanceof Ping || obj instanceof PingResponse) {
        ret = handlePingMessage(outbound, ctx);
    } else if (obj instanceof PingWithArgs) {
        ret = handlePingWithArgsMessage(outbound, ctx);
    }
    return ret;
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) PingWithArgs(org.apache.handler_test.types.PingWithArgs) Ping(org.apache.handler_test.types.Ping) PingResponse(org.apache.handler_test.types.PingResponse) PingException(org.apache.handler_test.PingException)

Example 3 with PingWithArgs

use of org.apache.handler_test.types.PingWithArgs in project cxf by apache.

the class TestHandler method handlePingWithArgsMessage.

private boolean handlePingWithArgsMessage(boolean outbound, T ctx) {
    LogicalMessage msg = ctx.getMessage();
    Object payload = msg.getPayload(jaxbCtx);
    addHandlerId(ctx.getMessage(), ctx, outbound);
    boolean ret = true;
    if (payload instanceof PingWithArgs) {
        String arg = ((PingWithArgs) payload).getHandlersCommand();
        StringTokenizer strtok = new StringTokenizer(arg, " ");
        String hid = "";
        String direction = "";
        String command = "";
        if (strtok.countTokens() >= 3) {
            hid = strtok.nextToken();
            direction = strtok.nextToken();
            command = strtok.nextToken();
        }
        if (!getHandlerId().equals(hid)) {
            return true;
        }
        if ("stop".equals(command)) {
            if (!outbound && "inbound".equals(direction)) {
                PingResponse resp = new PingResponse();
                resp.getHandlersInfo().addAll(getHandlerInfoList(ctx));
                msg.setPayload(resp, jaxbCtx);
                ret = false;
            } else if (outbound && "outbound".equals(direction)) {
                ret = false;
            }
        } else if ("throw".equals(command)) {
            String exceptionType = null;
            String exceptionText = "HandleMessage throws exception";
            if (strtok.hasMoreTokens()) {
                exceptionType = strtok.nextToken();
            }
            if (strtok.hasMoreTokens()) {
                exceptionText = strtok.nextToken();
            }
            if (exceptionType != null && !outbound && "inbound".equals(direction)) {
                if ("RuntimeException".equals(exceptionType)) {
                    throw new RuntimeException(exceptionText);
                } else if ("ProtocolException".equals(exceptionType)) {
                    throw new ProtocolException(exceptionText);
                }
            } else if (exceptionType != null && outbound && "outbound".equals(direction)) {
                if ("RuntimeException".equals(exceptionType)) {
                    throw new RuntimeException(exceptionText);
                } else if ("ProtocolException".equals(exceptionType)) {
                    throw new ProtocolException(exceptionText);
                }
            }
        }
    }
    return ret;
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) PingWithArgs(org.apache.handler_test.types.PingWithArgs) StringTokenizer(java.util.StringTokenizer) PingResponse(org.apache.handler_test.types.PingResponse) LogicalMessage(javax.xml.ws.LogicalMessage)

Aggregations

PingResponse (org.apache.handler_test.types.PingResponse)3 PingWithArgs (org.apache.handler_test.types.PingWithArgs)3 ProtocolException (javax.xml.ws.ProtocolException)2 Ping (org.apache.handler_test.types.Ping)2 StringTokenizer (java.util.StringTokenizer)1 LogicalMessage (javax.xml.ws.LogicalMessage)1 PingException (org.apache.handler_test.PingException)1