javax.xml.ws.LogicalMessage Java Examples

The following examples show how to use javax.xml.ws.LogicalMessage. 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: TestHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
private boolean checkServerOutBindStopHandler(boolean outbound, T ctx) {
    if (outbound) {
        LogicalMessage msg = ctx.getMessage();
        Object obj = msg.getPayload(jaxbCtx);
        if (obj instanceof PingResponse) {
            // only check if we need call for the server response handler false
            PingResponse origResp = (PingResponse)obj;
            for (String handler : origResp.getHandlersInfo()) {
                if (handler.indexOf("server") == 0 && handler.indexOf(getHandlerId()) > 0
                    && handler.indexOf("stop") > 0) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #2
Source File: DispatchHandlerInvocationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public boolean handleMessage(LogicalMessageContext ctx) {
    LogicalMessage msg = ctx.getMessage();

    Source payload = msg.getPayload();
    assertNotNull(payload);

    return true;
}
 
Example #3
Source File: TestHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
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());
        }
    }
 
Example #4
Source File: TestHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean handlePingMessage(boolean outbound, T ctx) {
    LogicalMessage msg = ctx.getMessage();
    addHandlerId(msg, ctx, outbound);
    if (checkServerOutBindStopHandler(outbound, ctx)) {
        return false;
    }
    return getHandleMessageRet();
}
 
Example #5
Source File: ModifyNumberHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
public final boolean handleMessage(LogicalMessageContext messageContext) {
    //System.out.println("LogicalMessageHandler handleMessage called");

    try {
        // get the LogicalMessage from our context
        LogicalMessage msg = messageContext.getMessage();

        // check the payload, if its an AddNumbers request, we'll intervene
        JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
        Object payload = msg.getPayload(jaxbContext);
        Object value = payload;
        if (payload instanceof JAXBElement) {
            value = ((JAXBElement<?>)payload).getValue();
        }

        if (value instanceof AddNumbers) {
            AddNumbers req = (AddNumbers)value;

            int a = req.getArg0();
            req.setArg0(a * 10);
            msg.setPayload(payload, jaxbContext);
        }
        return true;
    } catch (JAXBException ex) {
        throw new ProtocolException(ex);
    }

}
 
Example #6
Source File: LogicalMessageContextImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public LogicalMessage getMessage() {
    if(lm == null)
        lm = new LogicalMessageImpl(defaultJaxbContext, packet);
    return lm;
}
 
Example #7
Source File: LogicalMessageContextImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public LogicalMessage getMessage() {
    return new LogicalMessageImpl(this);
}
 
Example #8
Source File: HandlerInvocationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testSOAPHandlerHandleMessageReturnTrueClient() throws Exception {
    TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(false);
    TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
        public boolean handleMessage(LogicalMessageContext ctx) {
            super.handleMessage(ctx);
            try {
                Boolean outbound = (Boolean)ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                if (!outbound) {
                    LogicalMessage msg = ctx.getMessage();
                    Source source = msg.getPayload();
                    assertNotNull(source);
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
            return true;
        }
    };

    TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
    TestSOAPHandler soapHandler2 = new TestSOAPHandler(false);

    addHandlersToChain((BindingProvider)handlerTest, handler1, handler2, soapHandler1, soapHandler2);

    List<String> resp = handlerTest.ping();
    assertNotNull(resp);

    assertEquals("handle message was not invoked", 2, handler1.getHandleMessageInvoked());
    assertEquals("handle message was not invoked", 2, handler2.getHandleMessageInvoked());
    assertEquals("handle message was not invoked", 2, soapHandler1.getHandleMessageInvoked());
    assertEquals("handle message was not invoked", 2, soapHandler2.getHandleMessageInvoked());

    assertEquals("close must be called", 1, handler1.getCloseInvoked());
    assertEquals("close must be called", 1, handler2.getCloseInvoked());
    assertEquals("close must be called", 1, soapHandler1.getCloseInvoked());
    assertEquals("close must be called", 1, soapHandler2.getCloseInvoked());

    assertTrue(soapHandler2.getInvokeOrderOfClose()
               < soapHandler1.getInvokeOrderOfClose());
    assertTrue(soapHandler1.getInvokeOrderOfClose()
               < handler2.getInvokeOrderOfClose());
    assertTrue(handler2.getInvokeOrderOfClose()
               < handler1.getInvokeOrderOfClose());

    // the server has encoded into the response the order in
    // which the handlers have been invoked, parse it and make
    // sure everything is ok expected order for inbound interceptors
    String[] handlerNames = {"soapHandler4", "soapHandler3", "handler2", "handler1", "servant",
                             "handler1", "handler2", "soapHandler3", "soapHandler4"};

    assertEquals(handlerNames.length, resp.size());

    Iterator<String> iter = resp.iterator();
    for (String expected : handlerNames) {
        assertEquals(expected, iter.next());
    }
}
 
Example #9
Source File: TestHandler.java    From cxf with Apache License 2.0 4 votes vote down vote up
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;
    }
 
Example #10
Source File: SmallNumberHandler.java    From cxf with Apache License 2.0 4 votes vote down vote up
public final boolean handleMessage(LogicalMessageContext messageContext) {
    //System.out.println("LogicalMessageHandler handleMessage called");

    try {
        boolean outbound = (Boolean)messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        if (outbound) {
            // get the LogicalMessage from our context
            LogicalMessage msg = messageContext.getMessage();

            // check the payload, if its an AddNumbers request, we'll intervene
            JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
            Object payload = msg.getPayload(jaxbContext);
            if (payload instanceof JAXBElement) {
                payload = ((JAXBElement<?>)payload).getValue();
            }

            if (payload instanceof AddNumbers) {
                AddNumbers req = (AddNumbers)payload;

                // now, if the arguments are small, let's do the calculation here
                int a = req.getArg0();
                int b = req.getArg1();

                if (isSmall(a) && isSmall(b)) {
                    int answer = a + b;

                    //System.out.printf("SmallNumberHandler addNumbers(%d, %d) == %d\n", a, b, answer);
                    // ok, we've done the calculation, so build the
                    // response and set it as the payload of the message

                    AddNumbersResponse resp = new AddNumbersResponse();
                    resp.setReturn(answer);
                    msg.setPayload(new ObjectFactory().createAddNumbersResponse(resp),
                                   jaxbContext);

                    Source src = msg.getPayload();
                    msg.setPayload(src);

                    payload = msg.getPayload(jaxbContext);
                    if (payload instanceof JAXBElement) {
                        payload = ((JAXBElement<?>)payload).getValue();
                    }

                    AddNumbersResponse resp2 = (AddNumbersResponse)payload;
                    if (resp2 == resp) {
                        throw new WebServiceException("Shouldn't be the same object");
                    }

                    // finally, return false, indicating that request
                    // processing stops here and our answer will be
                    // returned to the client
                    return false;
                }
            }
        }
        return true;
    } catch (JAXBException ex) {
        throw new ProtocolException(ex);
    }

}
 
Example #11
Source File: SmallNumberHandler.java    From cxf with Apache License 2.0 4 votes vote down vote up
public final boolean handleMessage(LogicalMessageContext messageContext) {
    System.out.println("LogicalMessageHandler handleMessage called");

    try {
        boolean outbound = (Boolean)messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        if (outbound) {
            // get the LogicalMessage from our context
            //
            LogicalMessage msg = messageContext.getMessage();

            // check the payload, if its an AddNumbers request, we'll intervene
            //
            JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
            Object payload = msg.getPayload(jaxbContext);
            if (payload instanceof JAXBElement) {
                payload = ((JAXBElement<?>)payload).getValue();
            }

            if (payload instanceof AddNumbers) {
                AddNumbers req = (AddNumbers)payload;

                // now, if the arguments are small, let's do the calculation here
                //
                int a = req.getArg0();
                int b = req.getArg1();

                if (isSmall(a) && isSmall(b)) {
                    int answer = a + b;

                    //System.out.printf("SmallNumberHandler addNumbers(%d, %d) == %d\n", a, b, answer);
                    // ok, we've done the calculation, so build the
                    // response and set it as the payload of the message

                    AddNumbersResponse resp = new AddNumbersResponse();
                    resp.setReturn(answer);
                    msg.setPayload(new ObjectFactory().createAddNumbersResponse(resp),
                                   jaxbContext);

                    Source src = msg.getPayload();
                    msg.setPayload(src);

                    payload = msg.getPayload(jaxbContext);
                    if (payload instanceof JAXBElement) {
                        payload = ((JAXBElement<?>)payload).getValue();
                    }

                    AddNumbersResponse resp2 = (AddNumbersResponse)payload;
                    if (resp2 == resp) {
                        throw new WebServiceException("Shouldn't be the same object");
                    }

                    // finally, return false, indicating that request
                    // processing stops here and our answer will be
                    // returned to the client
                    return false;
                }
            }
        }
        return true;
    } catch (JAXBException ex) {
        throw new ProtocolException(ex);
    }

}
 
Example #12
Source File: LogicalMessageContextImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public LogicalMessage getMessage() {
    if(lm == null)
        lm = new LogicalMessageImpl(defaultJaxbContext, packet);
    return lm;
}
 
Example #13
Source File: LogicalMessageContextImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public LogicalMessage getMessage() {
    if(lm == null)
        lm = new LogicalMessageImpl(defaultJaxbContext, packet);
    return lm;
}
 
Example #14
Source File: LogicalMessageContextImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public LogicalMessage getMessage() {
    if(lm == null)
        lm = new LogicalMessageImpl(defaultJaxbContext, packet);
    return lm;
}
 
Example #15
Source File: LogicalMessageContextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public LogicalMessage getMessage() {
    if(lm == null)
        lm = new LogicalMessageImpl(defaultJaxbContext, packet);
    return lm;
}
 
Example #16
Source File: LogicalMessageContextImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public LogicalMessage getMessage() {
    if(lm == null)
        lm = new LogicalMessageImpl(defaultJaxbContext, packet);
    return lm;
}
 
Example #17
Source File: LogicalMessageContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public LogicalMessage getMessage() {
    if(lm == null)
        lm = new LogicalMessageImpl(defaultJaxbContext, packet);
    return lm;
}
 
Example #18
Source File: LogicalMessageContextImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public LogicalMessage getMessage() {
    if(lm == null)
        lm = new LogicalMessageImpl(defaultJaxbContext, packet);
    return lm;
}
 
Example #19
Source File: LogicalMessageContext.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns <code>null</code> if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();
 
Example #20
Source File: LogicalMessageContext.java    From Java8CN with Apache License 2.0 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns <code>null</code> if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();
 
Example #21
Source File: LogicalMessageContext.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns <code>null</code> if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();
 
Example #22
Source File: LogicalMessageContext.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns {@code null} if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();
 
Example #23
Source File: LogicalMessageContext.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns <code>null</code> if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();
 
Example #24
Source File: LogicalMessageContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns <code>null</code> if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();
 
Example #25
Source File: LogicalMessageContext.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns <code>null</code> if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();
 
Example #26
Source File: LogicalMessageContext.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns <code>null</code> if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();
 
Example #27
Source File: LogicalMessageContext.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns <code>null</code> if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();
 
Example #28
Source File: LogicalMessageContext.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns <code>null</code> if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();
 
Example #29
Source File: LogicalMessageContext.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/** Gets the message from this message context
 *
 *  @return The contained message; returns <code>null</code> if no
 *          message is present in this message context
**/
public LogicalMessage getMessage();