Package org.apache.mina.coap.resource

Examples of org.apache.mina.coap.resource.CoapResponse


        reg.register(new AbstractResourceHandler() {

            @Override
            public CoapResponse handle(CoapMessage request, IoSession session) {
                if (request.getCode() == CoapCode.GET.getCode()) {
                    return new CoapResponse(CoapCode.CONTENT.getCode(), status.getBytes());
                } else {
                    return new CoapResponse(CoapCode.METHOD_NOT_ALLOWED.getCode(), null);
                }
            }

            @Override
            public String getTittle() {
View Full Code Here


                return "demo";
            }

            @Override
            public CoapResponse handle(CoapMessage request, IoSession session) {
                return new CoapResponse(CoapCode.CONTENT.getCode(), "niah niah niah niah niah\n niah niah niah\n"
                        .getBytes(), new CoapOption(CoapOptionType.CONTENT_FORMAT, new byte[] { 0 }));
            }

            @Override
            public String getTittle() {
                return "Some demo resource";
            }

        });

        reg.register(new AbstractResourceHandler() {

            @Override
            public CoapResponse handle(CoapMessage request, IoSession session) {
                String device = null;
                try {
                    for (CoapOption o : request.getOptions()) {
                        if (o.getType() == CoapOptionType.URI_QUERY) {
                            String qr = new String(o.getData(), "UTF-8");
                            if (qr.startsWith("id=")) {
                                device = qr.substring(2);
                            }
                        }
                    }
                    if (device != null) {
                        registration.put(device, session);
                        return new CoapResponse(CoapCode.CREATED.getCode(), null);
                    } else {
                        return new CoapResponse(CoapCode.BAD_REQUEST.getCode(), "no id=xxx parameter".getBytes("UTF-8"));
                    }
                } catch (UnsupportedEncodingException e) {
                    throw new IllegalStateException("no UTF-8 in the JVM", e);
                }
            }
View Full Code Here

        reg.register(new AbstractResourceHandler() {

            @Override
            public CoapResponse handle(CoapMessage request, IoSession session) {
                if (request.getCode() == CoapCode.GET.getCode()) {
                    return new CoapResponse(CoapCode.CONTENT.getCode(), status.getBytes());
                } else {
                    return new CoapResponse(CoapCode.METHOD_NOT_ALLOWED.getCode(), null);
                }
            }

            @Override
            public String getTitle() {
View Full Code Here

                return "demo";
            }

            @Override
            public CoapResponse handle(CoapMessage request, IoSession session) {
                return new CoapResponse(CoapCode.CONTENT.getCode(), "niah niah niah niah niah\n niah niah niah\n"
                        .getBytes(), new CoapOption(CoapOptionType.CONTENT_FORMAT, new byte[] { 0 }));
            }

            @Override
            public String getTitle() {
                return "Some demo resource";
            }

        });

        reg.register(new AbstractResourceHandler() {

            @Override
            public CoapResponse handle(CoapMessage request, IoSession session) {
                String device = null;
                try {
                    for (CoapOption o : request.getOptions()) {
                        if (o.getType() == CoapOptionType.URI_QUERY) {
                            String qr = new String(o.getData(), "UTF-8");
                            if (qr.startsWith("id=")) {
                                device = qr.substring(2);
                            }
                        }
                    }
                    if (device != null) {
                        registration.put(device, session);
                        return new CoapResponse(CoapCode.CREATED.getCode(), null);
                    } else {
                        return new CoapResponse(CoapCode.BAD_REQUEST.getCode(), "no id=xxx parameter".getBytes("UTF-8"));
                    }
                } catch (UnsupportedEncodingException e) {
                    throw new IllegalStateException("no UTF-8 in the JVM", e);
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.mina.coap.resource.CoapResponse

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.