Package de.uniluebeck.itm.ncoap.message

Examples of de.uniluebeck.itm.ncoap.message.CoapMessage$LinkedHashSetSupplier


    }

    @Test
    public void test2ndReceivedMessageHasMsgTypeCON() {
        SortedMap<Long, CoapMessage> receivedMessages = endpoint.getReceivedCoapMessages();
        CoapMessage receivedMessage = receivedMessages.get(receivedMessages.lastKey());
        String message = "Response Msg EventType is not CON";
        assertEquals(message, MessageType.Name.CON, receivedMessage.getMessageTypeName());
    }
View Full Code Here


            ctx.sendDownstream(evt);
            return;
        }

        InetSocketAddress remoteEndpoint = (InetSocketAddress) ((MessageEvent) evt).getRemoteAddress();
        CoapMessage coapMessage = (CoapMessage) ((MessageEvent) evt).getMessage();

        try{
            Channels.write(ctx, evt.getFuture(), encode(coapMessage), remoteEndpoint);
        }
        catch(Exception ex){
            evt.getFuture().setFailure(ex);
            sendInternalEncodingFailedMessage(ctx, remoteEndpoint, coapMessage.getMessageID(), coapMessage.getToken(),
                    ex);
        }
    }
View Full Code Here


    @Test
    public void testAllRequestsAreEqual(){
        SortedMap<Long, CoapMessage> receivedMessages = testEndpoint.getReceivedCoapMessages();
        CoapMessage firstMessage = receivedMessages.get(receivedMessages.firstKey());

        for(CoapMessage message : receivedMessages.values()){
            assertEquals("Received requests did not equal.", firstMessage, message);
        }
    }
View Full Code Here

        assertEquals(2, endpoint.getReceivedCoapMessages().size());
    }

    @Test
    public void testFirstMessageisEmptyAck(){
        CoapMessage message1 = endpoint.getReceivedMessage(0);

        assertEquals("First message is not empty!", MessageCode.Name.EMPTY, message1.getMessageCodeName());
        assertEquals("First message has wrong ID!", messageID, message1.getMessageID());
        assertEquals("First message is no ACK!", MessageType.Name.ACK, message1.getMessageTypeName());
    }
View Full Code Here

        assertEquals("First message is no ACK!", MessageType.Name.ACK, message1.getMessageTypeName());
    }

    @Test
    public void testSecondMessage(){
        CoapMessage message2 = endpoint.getReceivedMessage(1);

        assertEquals("Third message has wrong message code!", MessageCode.Name.CONTENT_205,
                message2.getMessageCodeName());

        assertEquals("3rd message has wrong message type!", MessageType.Name.ACK, message2.getMessageTypeName());
    }
View Full Code Here

    }


    private void handleOutboundCoapMessage(ChannelHandlerContext ctx, MessageEvent me){

        CoapMessage coapMessage = (CoapMessage) me.getMessage();
        InetSocketAddress remoteEndpoint = (InetSocketAddress) me.getRemoteAddress();

        if(coapMessage.getMessageID() != CoapMessage.UNDEFINED_MESSAGE_ID){
            int messageID = coapMessage.getMessageID();

            if(coapMessage instanceof CoapResponse && ((CoapResponse) coapMessage).isUpdateNotification()
                    && coapMessage.getMessageTypeName() != MessageType.Name.ACK){

                if(this.transfers.contains(remoteEndpoint, messageID)){

                    if(updateConfirmableUpdateNotification(remoteEndpoint, (CoapResponse) coapMessage)){
                        return;
                    }

                    else{
                        //There was no update notification (which is very unlikely)
                        coapMessage.setMessageID(CoapMessage.UNDEFINED_MESSAGE_ID);
                    }
                }
            }

            else{
                ctx.sendDownstream(me);
                return;
            }
        }

        int messageID = this.messageIDFactory.getNextMessageID(remoteEndpoint);

        if(messageID == CoapMessage.UNDEFINED_MESSAGE_ID){
            MiscellaneousErrorEvent event = new MiscellaneousErrorEvent(remoteEndpoint, messageID,
            coapMessage.getToken(), "No message ID available for remote endpoint: " + remoteEndpoint);
            Channels.fireMessageReceived(ctx.getChannel(), event);
            return;
        }

        else if(coapMessage.getMessageTypeName() == MessageType.Name.CON){
            coapMessage.setMessageID(messageID);
            this.addTransfer(remoteEndpoint, coapMessage, true);
            log.debug("DOWNSTREAM AFTER (to {}): {}.", me.getRemoteAddress(), me.getMessage());
            ctx.sendDownstream(me);
        }

        else if(coapMessage.getMessageTypeName() == MessageType.Name.NON){
            coapMessage.setMessageID(messageID);
            this.addTransfer(remoteEndpoint, coapMessage, false);
            log.debug("DOWNSTREAM AFTER (to {}): {}.", me.getRemoteAddress(), me.getMessage());
            ctx.sendDownstream(me);
        }

        else{
            coapMessage.setMessageID(messageID);
            log.debug("DOWNSTREAM AFTER (to {}): {}.", me.getRemoteAddress(), me.getMessage());
            ctx.sendDownstream(me);
        }

        MessageIDAssignedEvent event = new MessageIDAssignedEvent(remoteEndpoint, messageID, coapMessage.getToken());
        Channels.fireMessageReceived(ctx.getChannel(), event);
    }
View Full Code Here

    }


     private void handleInboundCoapMessage(ChannelHandlerContext ctx, MessageEvent me){

         CoapMessage coapMessage = (CoapMessage) me.getMessage();
         InetSocketAddress remoteEndpoint = (InetSocketAddress) me.getRemoteAddress();

         MessageCode.Name messageCode = coapMessage.getMessageCodeName();
         MessageType.Name messageType = coapMessage.getMessageTypeName();

         int messageID = coapMessage.getMessageID();

         if(messageType == MessageType.Name.ACK){
             OutboundMessageTransfer messageExchange = removeTransfer(remoteEndpoint, messageID);

             if(messageExchange != null && messageExchange instanceof OutboundReliableMessageTransfer){
View Full Code Here

TOP

Related Classes of de.uniluebeck.itm.ncoap.message.CoapMessage$LinkedHashSetSupplier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.