All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.leshan.standalone.servlet.log.CoapMessage Maven / Gradle / Ivy

There is a newer version: 0.1.11-M7
Show newest version
/*******************************************************************************
 * Copyright (c) 2015 Sierra Wireless and others.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 * 
 * The Eclipse Public License is available at
 *    http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 *    http://www.eclipse.org/org/documents/edl-v10.html.
 * 
 * Contributors:
 *     Sierra Wireless - initial API and implementation
 *******************************************************************************/
package org.eclipse.leshan.standalone.servlet.log;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.Charsets;
import org.apache.commons.lang.StringUtils;
import org.eclipse.californium.core.coap.CoAP.Type;
import org.eclipse.californium.core.coap.EmptyMessage;
import org.eclipse.californium.core.coap.Option;
import org.eclipse.californium.core.coap.OptionNumberRegistry;
import org.eclipse.californium.core.coap.OptionSet;
import org.eclipse.californium.core.coap.Request;
import org.eclipse.californium.core.coap.Response;

public class CoapMessage {

    public long timestamp;

    // true for received message and false for sent messages
    public boolean incoming;

    // Confirmable, Non-confirmable, Acknowledgment, Reset
    public String type;

    // Request method or Response code
    public String code;

    public int mId;

    public String token;

    public String options;

    public String payload;

    public CoapMessage(Request request, boolean incoming) {
        this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request
                .getPayload());
        this.code = request.getCode().toString();
    }

    public CoapMessage(Response request, boolean incoming) {
        this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request
                .getPayload());
        this.code = request.getCode().toString();
    }

    public CoapMessage(EmptyMessage request, boolean incoming) {
        this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request
                .getPayload());
    }

    private CoapMessage(boolean incoming, Type type, int mId, String token, OptionSet options, byte[] payload) {
        this.incoming = incoming;
        this.timestamp = System.currentTimeMillis();
        this.type = type.toString();
        this.mId = mId;
        this.token = token;

        if (options != null) {
            List




© 2015 - 2025 Weber Informatics LLC | Privacy Policy