Java 8 LogicalMessage - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 LogicalMessage class.

This code example shows how to use the following methods:getPayload, setPayload
 
public class TestLogicalHandler implements LogicalHandler<LogicalMessageContext> {
    public boolean handleMessage(LogicalMessageContext ctx) {
        try { 
            LogicalMessage msg = ctx.getMessage();
            Source payload = msg.getPayload();
            String request = getSourceAsString(payload);
            // System.out.println(getSourceAsString(payload)); 
 
            // Make sure SOAP handler has changed the value successfully. 
            if (request.indexOf("ServerSOAPHandler") >= 0) {
                InputStream greetMeInputStream = getClass()
                    .getResourceAsStream("resources/GreetMeRpcLiteralReqLogical.xml");
                StreamSource source = new StreamSource();
                source.setInputStream(greetMeInputStream);
                msg.setPayload(source);
            } else if (request.indexOf("TestGreetMeResponse") >= 0) {
                InputStream greetMeInputStream = getClass()
                    .getResourceAsStream("resources/GreetMeRpcLiteralRespLogical.xml");
                StreamSource source = new StreamSource();

5
CodeRank
This code example shows how to use the following methods:getPayload, setPayload
            // 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) {

5
CodeRank
This code example shows how to use the following methods:getPayload, LogicalMessage.getPayload, LogicalMessage.setPayload
                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;

5
CodeRank
This code example shows how to use the following methods:getPayload, LogicalMessage.getPayload, LogicalMessage.setPayload
                // 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;
 

5
CodeRank
This code example shows how to use the following methods:getPayload, setPayload
    public boolean handleMessage(LogicalMessageContext messagecontext) {
        Boolean outbound = (Boolean)messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        tracker.handleMessage(outbound);
        if (outbound) {  // outbound request on the client
            LogicalMessage msg = messagecontext.getMessage();
            Source payload = msg.getPayload();
            String st = getStringFromSourcePayload(payload);
            String txt = String.valueOf(Integer.valueOf(getFirstArg(st)) * 2);
            st = replaceFirstArg(st, txt);
            msg.setPayload(new StreamSource(new StringBufferInputStream(st)));
        } 
        return true; 
    } 
     
    private static String getFirstArg(String payloadString) {
        StringTokenizer st = new StringTokenizer(payloadString, ">");
        st.nextToken();  // skip first token.
        st.nextToken();  // skip second
        String tempString = st.nextToken();
        String returnString = new StringTokenizer(tempString, "<").nextToken();
5
CodeRank
This code example shows how to use the following methods:getPayload, setPayload
    public boolean handleFault(LogicalMessageContext messagecontext) {
        Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        tracker.handleFault(outbound);
        if (outbound) {  // outbound response if we're on the server
            LogicalMessage msg = messagecontext.getMessage();
            String st = getStringFromSourcePayload(msg.getPayload());
            st = st.replaceFirst("blarg", "AddNumbersLogicalHandler2 was here");
            msg.setPayload(new StreamSource(new ByteArrayInputStream(st.getBytes())));
        } 
        return true; 
    } 
 
    /* 
     * this test handleMessage method is obviously not what a customer might write, but it does 
     * the trick for kicking the tires in the handler framework.  The AddNumbers service takes two 
     * ints as incoming params, adds them, and returns the sum.  This method subtracts 1 from the  
     * first int on the inbound request, and subtracts "deduction" from the int on the outbound 
     * response.  So the client app should expect a sum 3 less than a sum with this handler  
     * manipulating the SOAP message. 
     */ 
5
CodeRank
This code example shows how to use the following methods:getPayload, setPayload
        LogicalMessageContext lmc = createSampleContext();
         
        LogicalMessage msg = lmc.getMessage();
        assertTrue("The returned LogicalMessage was null", msg != null);
         
        Source payload = msg.getPayload();
        assertTrue("The returned payload (Source) was null", payload != null);
         
        String resultContent = _getStringFromSource(payload);
        assertTrue("The content returned was null", resultContent != null);
        assertTrue("The content returned was incorrect", resultContent.indexOf(INPUT) > 0);
 
        // Now manipluate the content and set it back on the message. 
        int start = resultContent.indexOf(INPUT);
        int end = start + INPUT.length();
         
        String newInput = "new content goes here";
        String newContent = resultContent.substring(0, start) + newInput + resultContent.substring(end);
         
        ByteArrayInputStream bais = new ByteArrayInputStream(newContent.getBytes());

4
CodeRank
This code example shows how to use the following methods:getPayload
      HandlerUtils.printMessageContext("Service LogicalHandler", mc);
      if (Boolean.FALSE.equals(mc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) {
         try { 
            LogicalMessage msg = mc.getMessage();
            JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
            Object payload = msg.getPayload(jaxbContext);
            if (payload instanceof DoubleIt) { 
               DoubleIt req = (DoubleIt) payload;
               if (req.getNumberToDouble() == 30) {
                  throw new ProtocolException(
                        "Doubling 30 is not allowed by the web service provider."); 
               } 
            } 
         } catch (JAXBException ex) {
            throw new ProtocolException(ex);
         } 
      } 
      return true; 
   } 
 
4
CodeRank
This code example shows how to use the following methods:getPayload
    public void testInboundFaultFlow() throws Exception {
        MessageContext mc = createSampleFaultMessageContext();
         
        LogicalMessageContext lmc = MessageContextFactory.createLogicalMessageContext(mc);
        LogicalMessage lm = lmc.getMessage();
        Source payload = lm.getPayload();
        assertTrue("The returned payload (Source) was null", payload != null);
         
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        StreamResult result = new StreamResult(baos);
        Transformer t = TransformerFactory.newInstance().newTransformer();
        t.transform(payload, result);
         
        String content = new String(baos.toByteArray());
        assertTrue("The returned content (String) from the payload was null", content != null);
        assertTrue("The <faultcode> element was not found", content.indexOf("faultcode") > -1);
        assertTrue("The <faultstring> element was not found", content.indexOf("faultstring") > -1);
        assertTrue("The fault did not contain the expected fault string", content.indexOf(FAULT_INPUT) > -1);
                 
        SoapMessageContext smc = MessageContextFactory.createSoapMessageContext(mc);
4
CodeRank
This code example shows how to use the following methods:getPayload
    public boolean handleFault(LogicalMessageContext messagecontext) {
        Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        tracker.handleFault(outbound);
        // let's see if we can do this 
        LogicalMessage lm = messagecontext.getMessage();
        String s = getStringFromSourcePayload(lm.getPayload());
        tracker.log("RETURNING FALSE", outbound);
        return false; 
    } 
 
    public boolean handleMessage(LogicalMessageContext messagecontext) {
        Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        tracker.handleMessage(outbound);
        return true; 
    } 
     
    private static String getStringFromSourcePayload(Source payload) {
        try { 
 
            TransformerFactory factory = TransformerFactory.newInstance();
4
CodeRank
See Code Examples for Java 8 LogicalMessage Methods: