Package de.uniluebeck.itm.ncoap.application.server.webservice

Examples of de.uniluebeck.itm.ncoap.application.server.webservice.WrappedResourceStatus


    }


    public void processCoapGetRequest(SettableFuture<CoapResponse> responseFuture, CoapRequest coapRequest){
        //create resource status
        WrappedResourceStatus resourceStatus;
        if(coapRequest.getAcceptedContentFormats().isEmpty())
            resourceStatus = getWrappedResourceStatus(DEFAULT_CONTENT_FORMAT);

        else
            resourceStatus = getWrappedResourceStatus(coapRequest.getAcceptedContentFormats());

        //create CoAP response
        CoapResponse coapResponse;
        if(resourceStatus == null){
            coapResponse = new CoapResponse(coapRequest.getMessageTypeName(), MessageCode.Name.NOT_ACCEPTABLE_406);
            coapResponse.setContent("None of the accepted content formats is supported!".getBytes(CoapMessage.CHARSET),
                    ContentFormat.TEXT_PLAIN_UTF8);
        }

        else{
            coapResponse = new CoapResponse(coapRequest.getMessageTypeName(), MessageCode.Name.CONTENT_205);
            coapResponse.setContent(resourceStatus.getContent(), resourceStatus.getContentFormat());
            coapResponse.setEtag(resourceStatus.getEtag());
            coapResponse.setMaxAge(resourceStatus.getMaxAge());
        }

        responseFuture.set(coapResponse);
    }
View Full Code Here


        //If accept option is not set in the request, use the default (TEXT_PLAIN_UTF8)
        if(contentFormats.isEmpty())
            contentFormats.add(DEFAULT_CONTENT_FORMAT);

        //Generate the payload of the response (depends on the accepted content formats, resp. the default
        WrappedResourceStatus resourceStatus = null;
        Iterator<Long> iterator = contentFormats.iterator();
        long contentFormat = DEFAULT_CONTENT_FORMAT;

        while(resourceStatus == null && iterator.hasNext()){
            contentFormat = iterator.next();
            resourceStatus = getWrappedResourceStatus(contentFormat);
        }

        //generate the CoAP response
        CoapResponse coapResponse;

        //if the payload could be generated, i.e. at least one of the accepted content formats (according to the
        //requests accept option(s)) is offered by the Webservice then set payload and content format option
        //accordingly
        if(resourceStatus != null){
            coapResponse = new CoapResponse(coapRequest.getMessageTypeName(), MessageCode.Name.CONTENT_205);
            coapResponse.setContent(resourceStatus.getContent(), contentFormat);

            coapResponse.setEtag(resourceStatus.getEtag());
            coapResponse.setMaxAge(resourceStatus.getMaxAge());

            if(coapRequest.getObserve() == 0)
                coapResponse.setObserve();
        }
View Full Code Here

                                   InetSocketAddress remoteEndpoint){


        Set<Long> acceptedContentFormats = coapRequest.getAcceptedContentFormats();

        WrappedResourceStatus wrappedResourceStatus = null;
        long contentFormat;

        //Use default content format if there was no accept option set in the request
        if(acceptedContentFormats.isEmpty()){
            contentFormat = DEFAULT_CONTENT_FORMAT;
            wrappedResourceStatus = getWrappedResourceStatus(contentFormat);
        }

        //Try all accepted content formats (if accept option was set in the request)
        else{
            for(long acceptedContentFormat : acceptedContentFormats){
                wrappedResourceStatus = getWrappedResourceStatus(acceptedContentFormat);

                if(wrappedResourceStatus != null)
                    break;
            }
        }

        if(wrappedResourceStatus == null){
            CoapResponse coapResponse =
                    new CoapResponse(coapRequest.getMessageTypeName(), MessageCode.Name.BAD_REQUEST_400);

            String content = "Resource status is not available in any of the accepted content formats!";
            coapResponse.setContent(content.getBytes(CoapMessage.CHARSET), ContentFormat.TEXT_PLAIN_UTF8);

            responseFuture.set(coapResponse);
        }

        else{
            CoapResponse coapResponse =
                    new CoapResponse(coapRequest.getMessageTypeName(), MessageCode.Name.CONTENT_205);

            coapResponse.setContent(wrappedResourceStatus.getContent(), wrappedResourceStatus.getContentFormat());
            coapResponse.setEtag(wrappedResourceStatus.getEtag());
            coapResponse.setMaxAge(wrappedResourceStatus.getMaxAge());

            if(coapRequest.getObserve() == 0){
                coapResponse.setObserve();
            }
View Full Code Here

TOP

Related Classes of de.uniluebeck.itm.ncoap.application.server.webservice.WrappedResourceStatus

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.