Commit fb29fea6 authored by Björn Butzin's avatar Björn Butzin
Browse files

added some logging; added interface description

parent 673fa682
......@@ -89,7 +89,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
<version>2.10.0</version>
</dependency>
</dependencies>
<organization>
......
......@@ -99,6 +99,7 @@ public class BasicCoapChannelManager implements CoapChannelManager {
SocketInformation socketInfo = new SocketInformation(new BasicCoapSocketHandler(this, localPort),
listener);
this.socketMap.put(localPort, socketInfo);
logger.info("Server is listening on port "+localPort);
} catch (IOException e) {
logger.warn(e.getLocalizedMessage());
}
......
......@@ -116,18 +116,21 @@ public class BasicCoapSocketHandler implements CoapSocketHandler {
try{
this.dgramSocket.joinGroup(InetAddress.getByName(CoapConstants.COAP_ALL_NODES_IPV6_LL_MC_ADDR));
logger.info("joined IPv6 link local multicast group");
} catch(Exception e1){
logger.warn("IPv6 link local multicast not available. Continuing without.");
logger.debug(e1.getLocalizedMessage());
}
try{
this.dgramSocket.joinGroup(InetAddress.getByName(CoapConstants.COAP_ALL_NODES_IPV6_SL_MC_ADDR));
logger.info("joined IPv6 site local multicast group");
} catch(Exception e1){
logger.warn("IPv6 site local multicast not available. Continuing without.");
logger.debug(e1.getLocalizedMessage());
}
try{
this.dgramSocket.joinGroup(InetAddress.getByName(CoapConstants.COAP_ALL_NODES_IPV4_MC_ADDR));
logger.info("joined IPv4 multicast group");
} catch(Exception e1){
logger.warn("IPv4 multicast not available. Continuing without.");
logger.debug(e1.getLocalizedMessage());
......
......@@ -82,6 +82,7 @@ public class BasicCoapResource implements CoapResource {
this.path = initPath;
this.content = initValue;
this.mediaType = initMediaType;
this.compileIf();
}
public synchronized CoapResource setCoapMediaType(CoapMediaType mediaType) {
......@@ -204,11 +205,13 @@ public class BasicCoapResource implements CoapResource {
public synchronized BasicCoapResource setPostable(boolean postable) {
this.postable = postable;
this.compileIf();
return this;
}
public synchronized BasicCoapResource setPutable(boolean putable) {
this.putable = putable;
this.compileIf();
return this;
}
......@@ -228,6 +231,7 @@ public class BasicCoapResource implements CoapResource {
public synchronized BasicCoapResource setDeletable(boolean deletable) {
this.deletable = deletable;
this.compileIf();
return this;
}
......@@ -307,6 +311,7 @@ public class BasicCoapResource implements CoapResource {
public BasicCoapResource setGetable(boolean getable) {
this.getable = getable;
this.compileIf();
return this;
}
......@@ -325,4 +330,22 @@ public class BasicCoapResource implements CoapResource {
public void removeTag(String tag) {
this.tags.remove(tag);
}
private void compileIf() {
String ifTag = "";
if(this.isGetable()) ifTag += "GET";
if(this.isPutable()) {
if(!ifTag.isEmpty()) {ifTag += " ";}
ifTag += "PUT";
}
if(this.isPostable()) {
if(!ifTag.isEmpty()) {ifTag += " ";}
ifTag += "POST";
}
if(this.isDeletable()) {
if(!ifTag.isEmpty()) {ifTag += " ";}
ifTag += "DELETE";
}
this.setInterfaceDescription(ifTag);
}
}
\ No newline at end of file
......@@ -122,7 +122,7 @@ public class CoreResource extends BasicCoapResource {
// add ',' if this is not the first entry
if (!first) {
returnString.append(",");
returnString.append(", ");
} else {
first = false;
}
......@@ -136,7 +136,7 @@ public class CoreResource extends BasicCoapResource {
while(it.hasNext()){
String key = it.next();
String value = resource.getTags().get(key);
returnString.append(";");
returnString.append("; ");
returnString.append(key);
if(null != value){
returnString.append("=\"");
......@@ -147,7 +147,7 @@ public class CoreResource extends BasicCoapResource {
// size estimate to be displayed?
// only display sz when larger than MTU
if (resource.getSizeEstimate() > CoapConstants.COAP_PAYLOAD_SIZE_MAX) {
returnString.append(";sz=\"");
returnString.append("; sz=\"");
returnString.append(resource.getSizeEstimate());
returnString.append("\"");
}
......
......@@ -86,8 +86,12 @@ public class MultiTypeResource extends BasicCoapResource {
}
@Override
public synchronized boolean post(byte[] data, CoapMediaType type) {
return this.resourceHandler.get(type).handlePost(data);
public synchronized boolean post(byte[] data, CoapMediaType mediaType) {
ResourceHandler rh = this.resourceHandler.get(mediaType);
if(rh != null) {
return rh.handlePost(data);
}
return false;
}
@Override
......@@ -97,7 +101,11 @@ public class MultiTypeResource extends BasicCoapResource {
@Override
public synchronized boolean put(byte[] data, CoapMediaType mediaType) {
return this.resourceHandler.get(mediaType).handlePut(data);
ResourceHandler rh = this.resourceHandler.get(mediaType);
if(rh != null) {
return rh.handlePut(data);
}
return false;
}
@Override
......
......@@ -295,7 +295,7 @@ public class PlugTest {
clientChannel.sendMessage(request);
while (null == receivedResponse)Thread.sleep(10);
Assert.assertEquals("</.well-known/core>;obs,</resource1>;rt=\"resource1Type\";if=\"resource1Description\"",
Assert.assertEquals("</.well-known/core>; obs; if=\"GET\", </resource1>; rt=\"resource1Type\"; if=\"resource1Description\"",
Encoder.ByteToString(receivedResponse.getPayload()));
}
......@@ -315,7 +315,7 @@ public class PlugTest {
while (null == receivedResponse)Thread.sleep(10);
Assert.assertEquals("</resource1>;rt=\"resource1Type\";if=\"resource1Description\"",
Assert.assertEquals("</resource1>; rt=\"resource1Type\"; if=\"resource1Description\"",
Encoder.ByteToString(receivedResponse.getPayload()));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment