Skip to content
Open
10 changes: 10 additions & 0 deletions client/client-multi/client-java-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>californium-core</artifactId>
<version>1.1.0-SNAPSHOT</version>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid snapshot versions of external libraries.
Please use one of the release versions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Californium version changed to 2.0.0-M2 .

</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>element-connector</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public class TransportProtocolIdConstants {
private static final int TCP_TRANSPORT_PROTOCOL_VERSION = 1;
public static final TransportProtocolId TCP_TRANSPORT_ID = new TransportProtocolId(
TCP_TRANSPORT_PROTOCOL_ID, TCP_TRANSPORT_PROTOCOL_VERSION);
private static final int COAP_TRANSPORT_PROTOCOL_ID = 0x0b5d1174;
private static final int COAP_TRANSPORT_PROTOCOL_VERSION = 1;
public static final TransportProtocolId COAP_TRANSPORT_ID = new TransportProtocolId(
COAP_TRANSPORT_PROTOCOL_ID, COAP_TRANSPORT_PROTOCOL_VERSION);




private TransportProtocolIdConstants() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
package org.kaaproject.kaa.client.channel.impl.channels;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs Apache license header. Both Jenkins and Travis are currently failing because of missing Apache license headers.


import org.eclipse.californium.core.CoapClient;
import org.eclipse.californium.core.CoapResponse;
import org.eclipse.californium.core.Utils;
import org.eclipse.californium.core.coap.MediaTypeRegistry;
import org.kaaproject.kaa.client.channel.ChannelDirection;
import org.kaaproject.kaa.client.channel.IpTransportInfo;
import org.kaaproject.kaa.client.channel.KaaDataChannel;
import org.kaaproject.kaa.client.channel.KaaDataDemultiplexer;
import org.kaaproject.kaa.client.channel.KaaDataMultiplexer;
import org.kaaproject.kaa.client.channel.ServerType;
import org.kaaproject.kaa.client.channel.TransportConnectionInfo;
import org.kaaproject.kaa.client.channel.TransportProtocolId;
import org.kaaproject.kaa.client.channel.TransportProtocolIdConstants;

import org.kaaproject.kaa.client.channel.connectivity.ConnectivityChecker;
import org.kaaproject.kaa.common.TransportType;
import org.kaaproject.kaa.common.endpoint.security.MessageEncoderDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
* Created with IntelliJ IDEA.
* User: root
* Date: 10/24/16
* Time: 10:52 AM
* To change this template use File | Settings | File Templates.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove the auto-generated class header. (git already handles such info much better.)

public class CoapChannel implements KaaDataChannel {

public static final Logger LOG = LoggerFactory // NOSONAR
.getLogger(CoapChannel.class);

private static final Map<TransportType, ChannelDirection> SUPPORTED_TYPES = new HashMap<TransportType, ChannelDirection>();

static {
SUPPORTED_TYPES.put(TransportType.PROFILE, ChannelDirection.BIDIRECTIONAL);
SUPPORTED_TYPES.put(TransportType.CONFIGURATION, ChannelDirection.BIDIRECTIONAL);
SUPPORTED_TYPES.put(TransportType.NOTIFICATION, ChannelDirection.BIDIRECTIONAL);
}

private static final String CHANNEL_ID = "default_coap_channel";
private KaaDataDemultiplexer demultiplexer;
private KaaDataMultiplexer multiplexer;
// private volatile State channelState = State.CLOSED;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented-out code is not allowed.

It's always a code smell, you know. Weeks after the next guys does a refactoring and wonders what's the purpose of commented out code, why it is commented, should it be uncommented or deleted?

private IpTransportInfo currentServer;

@Override
public void sync(TransportType type) {
sync(Collections.singleton(type));
}

@Override
public void sync(Set<TransportType> types) {

// if (channelState == State.SHUTDOWN) {
// LOG.info("Can't sync. Channel [{}] is down", getId());
// return;
// }
// if (channelState == State.PAUSE) {
// LOG.info("Can't sync. Channel [{}] is paused", getId());
// return;
// }
// if (channelState != State.OPENED) {
// LOG.info("Can't sync. Channel [{}] is waiting for CONNACK message + KAASYNC message", getId());
// return;
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code (see my comment above)

if (multiplexer == null) {
LOG.warn("Can't sync. Channel {} multiplexer is not set", getId());
return;
}
if (demultiplexer == null) {
LOG.warn("Can't sync. Channel {} demultiplexer is not set", getId());
return;
}
// if (currentServer == null || socket == null) {
// LOG.warn("Can't sync. Server is {}, socket is \"{}\"", currentServer, socket);
// return;
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code (see my comment above)


Map<TransportType, ChannelDirection> typeMap = new HashMap<>(getSupportedTransportTypes().size());
for (TransportType type : types) {
LOG.info("Processing sync {} for channel [{}]", type, getId());
ChannelDirection direction = getSupportedTransportTypes().get(type);
if (direction != null) {
typeMap.put(type, direction);
} else {
LOG.error("Unsupported type {} for channel [{}]", type, getId());
}
for (Map.Entry<TransportType, ChannelDirection> typeIt : getSupportedTransportTypes().entrySet()) {
if (!typeIt.getKey().equals(type)) {
typeMap.put(typeIt.getKey(), ChannelDirection.DOWN);
}
}
}
// try {
// sendKaaSyncRequest(typeMap);
// } catch (Exception e) {
// LOG.error("Failed to sync channel [{}]", getId(), e);
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code (see my comment above)



}

@Override
public void syncAll() {
//To change body of implemented methods use File | Settings | File Templates.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove auto-generated stubs comments. Basically, we should try keeping all comments as informative as possible—reading stubs is not fun 🙂

}

@Override
public void syncAck(TransportType type) {
LOG.info("Adding sync acknowledgement for type {} as a regular sync for channel [{}]", type, getId());
syncAck(Collections.singleton(type));
}

@Override
public void syncAck(Set<TransportType> type) {
//To change body of implemented methods use File | Settings | File Templates.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stubs comments (see comment above)

}

@Override
public String getId() {
return CHANNEL_ID;
}

@Override
public TransportProtocolId getTransportProtocolId() {
return TransportProtocolIdConstants.COAP_TRANSPORT_ID;
}

@Override
public ServerType getServerType() {
return ServerType.OPERATIONS;
}

@Override
public void setDemultiplexer(KaaDataDemultiplexer demultiplexer) {
if (demultiplexer != null) {
this.demultiplexer = demultiplexer;
}
}

@Override
public void setMultiplexer(KaaDataMultiplexer multiplexer) {
if (multiplexer != null) {
this.multiplexer = multiplexer;
}
}

@Override
public void setServer(TransportConnectionInfo server) {

LOG.info("Setting server [{}] for channel [{}]", server, getId());
if (server == null) {
LOG.warn("Server is null for Channel [{}].", getId());
return;
}

IpTransportInfo oldServer = currentServer;
this.currentServer = new IpTransportInfo(server);
//this.encDec = new MessageEncoderDecoder(state.getPrivateKey(), state.getPublicKey(), currentServer.getPublicKey());
//uncompelete!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should be finished here?


}

@Override
public TransportConnectionInfo getServer() {
return currentServer;

}

@Override
public void setConnectivityChecker(ConnectivityChecker checker) {
//To change body of implemented methods use File | Settings | File Templates.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stubs comments (see my comment above)

}

@Override
public Map<TransportType, ChannelDirection> getSupportedTransportTypes() {
return SUPPORTED_TYPES;
}

@Override
public void shutdown() {
}

@Override
public void pause() {
}

@Override
public void resume() {
}

/**
*
Copy link

@odovhai odovhai Feb 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we need some more java-docs with explanation. It would be better if all comments inside this method are moved to the java-doc .

* @param myUri uri of source
* @param method CoAP method like POST,GET,...
* @param payload Message Payload
* @param msgType Confirmable or Non confirmable
* @return server response
*/
public CoapResponse sendData(String myUri, String method, String payload, String msgType) {
LOG.info("this is SendData function!");
URI uri = null;

if (myUri != null) {
// input URI from command line arguments
try {
uri = new URI(myUri);
} catch (URISyntaxException exception) {
LOG.info("Invalid URI: " + exception.getMessage());
// System.exit(-1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code (see my comment above)

}

CoapClient client = new CoapClient(uri);
LOG.info(" new coap client is registerd");

CoapResponse response;

if (msgType == "NON") {
client.useNONs();
} else {
client.useCONs();
}

if (method == "post") {
response = client.post(payload, MediaTypeRegistry.TEXT_PLAIN);
} else {
response = client.get();
}

if (response != null) {

LOG.info(String.valueOf(response.getCode()));
LOG.info(String.valueOf(response.getOptions()));
LOG.info(response.getResponseText());

LOG.info("\nADVANCED\n");
// access advanced API with access to more details through .advanced()
LOG.info(Utils.prettyPrint(response));

} else {
LOG.info("No response received.");
}

return response;
} else {
// display help
LOG.info("Californium (Cf) GET Client");
LOG.info("(c) 2014, Institute for Pervasive Computing, ETH Zurich");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you own copyrights for the code in question?

Californium GET Client is licensed under Eclipse Public License, which is not mixable with Apache 2.0.

String simpleName = CoapChannel.class.getSimpleName();
LOG.info("Usage: " + simpleName + " URI");
LOG.info("URI: The CoAP URI of the remote resource to GET");
return null;
}
}
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1439,5 +1439,10 @@ Copyright 2014-2016 CyberVision, Inc.
<id>repository.kaaproject.snapshots</id>
<url>http://repository.kaaproject.org/repository/snapshots/</url>
</repository>
<repository>
<id>repo.eclipse.org</id>
<name>Californium Repository</name>
<url>https://repo.eclipse.org/content/repositories/californium/</url>
</repository>
</repositories>
</project>
14 changes: 14 additions & 0 deletions server/node/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@
<artifactId>config</artifactId>
<classifier>tcp</classifier>
</dependency>

<dependency>
<groupId>org.kaaproject.kaa.server.transports.coap</groupId>
<artifactId>transport</artifactId>
<version>0.11.0-SNAPSHOT</version>
<classifier>coap</classifier>
</dependency>
<dependency>
<groupId>org.kaaproject.kaa.server.transports.coap</groupId>
<artifactId>config</artifactId>
<version>0.11.0-SNAPSHOT</version>
<classifier>coap</classifier>
</dependency>

<dependency>
<groupId>org.kaaproject.kaa.server.common</groupId>
<artifactId>log-shared</artifactId>
Expand Down
Loading