Package org.apache.mina.coap

Examples of org.apache.mina.coap.CoapMessage


        Mockito.verifyNoMoreInteractions(readController);
    }

    @Test
    public void retry_confirmable_message() throws InterruptedException {
        CoapMessage msg = new CoapMessage(1, MessageType.CONFIRMABLE, 1, 1234, null, null, null);

        WriteRequest writeRequest = new DefaultWriteRequest(msg);
        filter.messageWriting(session, writeRequest, writeController);

        // verify
View Full Code Here


    @Test
    public void no_retry_if_ack_received() throws InterruptedException {

        // confirmable
        CoapMessage msg = new CoapMessage(1, MessageType.CONFIRMABLE, 1, 1234, null, null, null);
        WriteRequest writeRequest = new DefaultWriteRequest(msg);
        filter.messageWriting(session, writeRequest, writeController);

        // ack
        CoapMessage ack = new CoapMessage(1, MessageType.ACK, 1, 1234, null, null, null);
        filter.messageReceived(session, ack, readController);

        // wait more than the first timeout
        Thread.sleep(3500L);
View Full Code Here

    @Test
    public void no_retry_if_reset_received() throws InterruptedException {

        // confirmable
        CoapMessage msg = new CoapMessage(1, MessageType.CONFIRMABLE, 1, 1234, null, null, null);
        WriteRequest writeRequest = new DefaultWriteRequest(msg);
        filter.messageWriting(session, writeRequest, writeController);

        // reset
        CoapMessage ack = new CoapMessage(1, MessageType.RESET, 1, 1234, null, null, null);
        filter.messageReceived(session, ack, readController);

        // wait more than the first timeout
        Thread.sleep(3500L);
View Full Code Here

        verify(session, Mockito.never()).write(any(CoapMessage.class));
    }

    @Test
    public void non_confirmable_message_writing() {
        CoapMessage msg = new CoapMessage(1, MessageType.NON_CONFIRMABLE, 1, 1234, "token".getBytes(), null,
                "payload".getBytes());
        WriteRequest writeRequest = new DefaultWriteRequest(msg);

        filter.messageWriting(session, writeRequest, writeController);
View Full Code Here

    public void timeout() {

        IoSession session = Mockito.mock(IoSession.class);
        Mockito.when(session.getId()).thenReturn(1L);

        CoapTransmission transmission = new CoapTransmission(session, new CoapMessage(1, MessageType.CONFIRMABLE, 1,
                1234, "token".getBytes(), null, "payload".getBytes()));

        assertTrue(transmission.getNextTimeout() > MIN_INIT_TIMEOUT);
        assertTrue(transmission.getNextTimeout() < MAX_INIT_TIMEOUT);
View Full Code Here

        String url = urlBuilder.toString();
        LOG.debug("requested URL : {}", url);

        if (url.length() < 1) {
            // 4.00 !
            return new CoapMessage(1, MessageType.ACK, CoapCode.BAD_REQUEST.getCode(), request.getId(),
                    request.getToken(), new CoapOption[] { new CoapOption(CoapOptionType.CONTENT_FORMAT,
                            new byte[] { 0 }) }, "no URL !".getBytes());
        }
        if (".well-known/core".equalsIgnoreCase(url)) {
            // discovery !
            return new CoapMessage(1, MessageType.ACK, CoapCode.CONTENT.getCode(), request.getId(), request.getToken(),
                    new CoapOption[] { new CoapOption(CoapOptionType.CONTENT_FORMAT, new byte[] { 40 }) },
                    getDiscovery());
        } else {
            ResourceHandler handler = handlers.get(url);
            if (handler == null) {
                // 4.04 !
                return new CoapMessage(1, MessageType.ACK, CoapCode.NOT_FOUND.getCode(), request.getId(),
                        request.getToken(), new CoapOption[] { new CoapOption(CoapOptionType.CONTENT_FORMAT,
                                new byte[] { 0 }) }, "not found !".getBytes());
            } else {
                CoapResponse response = handler.handle(request, session);
                return new CoapMessage(1, request.getType() == MessageType.CONFIRMABLE ? MessageType.ACK
                        : MessageType.NON_CONFIRMABLE, response.getCode(), request.getId(), request.getToken(),
                        response.getOptions(), response.getContent());
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.mina.coap.CoapMessage

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.