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

Organized imports

Improved existent documentation
Prepared further documentation
parent 3717eeed
......@@ -10,14 +10,12 @@ import org.ws4d.coap.interfaces.CoapClient;
import org.ws4d.coap.interfaces.CoapClientChannel;
import org.ws4d.coap.interfaces.CoapRequest;
import org.ws4d.coap.interfaces.CoapResponse;
import org.ws4d.coap.messages.CoapEmptyMessage;
import org.ws4d.coap.messages.CoapRequestCode;
import org.ws4d.coap.messages.CoapBlockOption.CoapBlockSize;
import org.ws4d.coap.messages.CoapRequestCode;
/**
* @author Christian Lerche <christian.lerche@uni-rostock.de>
*/
public class BasicCoapBlockClient implements CoapClient {
private static final String SERVER_ADDRESS = "129.132.15.80";
private static final int PORT = Constants.COAP_DEFAULT_PORT;
......
......@@ -13,16 +13,13 @@ import org.ws4d.coap.interfaces.CoapClientChannel;
import org.ws4d.coap.interfaces.CoapRequest;
import org.ws4d.coap.interfaces.CoapResponse;
import org.ws4d.coap.messages.CoapBlockOption;
import org.ws4d.coap.messages.CoapEmptyMessage;
import org.ws4d.coap.messages.CoapMediaType;
import org.ws4d.coap.messages.CoapRequestCode;
import org.ws4d.coap.messages.CoapBlockOption.CoapBlockSize;
import org.ws4d.coap.messages.CoapRequestCode;
/**
* @author Christian Lerche <christian.lerche@uni-rostock.de>
* Bjoern Konieczek <bjoern.konieczek@uni-rostock.de>
*/
public class BasicCoapClient implements CoapClient {
private String SERVER_ADDRESS;
private int PORT;
......
......@@ -38,7 +38,6 @@ import org.apache.http.nio.util.SimpleInputBuffer;
* @author Christian Lerche <christian.lerche@uni-rostock.de>
* @author Andy Seidel <andy.seidel@uni-rostock.de>
*/
class ByteContentListener implements ContentListener {
final SimpleInputBuffer input = new SimpleInputBuffer(2048, new HeapByteBufferAllocator());
......
......@@ -31,16 +31,8 @@ import net.sf.ehcache.Element;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.ws4d.coap.interfaces.CoapRequest;
import org.ws4d.coap.interfaces.CoapResponse;
import org.ws4d.coap.messages.CoapRequestCode;
import org.ws4d.coap.messages.CoapResponseCode;
/**
* @author Christian Lerche <christian.lerche@uni-rostock.de>
......
......@@ -32,8 +32,6 @@ import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import net.sf.ehcache.Element;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
......
......@@ -17,21 +17,12 @@ package org.ws4d.coap.server;
import org.ws4d.coap.Constants;
import org.ws4d.coap.connection.BasicCoapChannelManager;
import org.ws4d.coap.interfaces.CoapChannelManager;
import org.ws4d.coap.interfaces.CoapMessage;
import org.ws4d.coap.interfaces.CoapRequest;
import org.ws4d.coap.interfaces.CoapServer;
import org.ws4d.coap.interfaces.CoapServerChannel;
import org.ws4d.coap.messages.CoapMediaType;
import org.ws4d.coap.messages.CoapResponseCode;
import org.ws4d.coap.rest.BasicCoapResource;
import org.ws4d.coap.rest.CoapResource;
import org.ws4d.coap.rest.CoapResourceServer;
/**
* @author Christian Lerche <christian.lerche@uni-rostock.de>
*/
public class BasicCoapServer {
private int port = Constants.COAP_DEFAULT_PORT;
private CoapResourceServer resourceServer = null;
......
package org.ws4d.coap.udp;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.channels.SelectionKey;
......
......@@ -10,9 +10,7 @@ import java.util.logging.Logger;
import org.ws4d.coap.connection.BasicCoapChannelManager;
import org.ws4d.coap.connection.BasicCoapSocketHandler;
import org.ws4d.coap.rest.BasicCoapResource;
import org.ws4d.coap.rest.CoapResourceServer;
import org.ws4d.coap.rest.CoreResource;
import org.ws4d.coap.test.resources.LongPathResource;
import org.ws4d.coap.test.resources.QueryResource;
import org.ws4d.coap.test.resources.TestResource;
......@@ -24,51 +22,52 @@ import org.ws4d.coap.test.resources.TestResource;
*/
public class CompletePlugtestServer {
private static CompletePlugtestServer plugtestServer;
private CoapResourceServer resourceServer;
private static Logger logger = Logger
.getLogger(BasicCoapSocketHandler.class.getName());
/**
* @param args
*/
public static void main(String[] args) {
private static CompletePlugtestServer plugtestServer;
private CoapResourceServer resourceServer;
private static Logger logger = Logger
.getLogger(BasicCoapSocketHandler.class.getName());
logger.setLevel(Level.WARNING);
plugtestServer = new CompletePlugtestServer();
plugtestServer.start();
/**
* @param args
*/
public static void main(String[] args) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("PlugtestServer is now stopping.");
System.out.println("===END===");
}
});
}
logger.setLevel(Level.WARNING);
plugtestServer = new CompletePlugtestServer();
plugtestServer.start();
public void start() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("PlugtestServer is now stopping.");
System.out.println("===END===");
}
});
}
public void start() {
System.out.println("===Run Test Server ===");
init();
resourceServer.createResource(new TestResource());
resourceServer.createResource(new LongPathResource());
resourceServer.createResource(new QueryResource());
run();
}
private void init() {
BasicCoapChannelManager.getInstance().setMessageId(2000);
if (resourceServer != null)
resourceServer.stop();
resourceServer = new CoapResourceServer();
}
resourceServer.createResource(new TestResource());
resourceServer.createResource(new LongPathResource());
resourceServer.createResource(new QueryResource());
run();
}
private void init() {
BasicCoapChannelManager.getInstance().setMessageId(2000);
if (resourceServer != null)
resourceServer.stop();
resourceServer = new CoapResourceServer();
}
private void run() {
private void run() {
try {
resourceServer.start();
resourceServer.start();
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
......@@ -5,9 +5,7 @@
*/
package org.ws4d.coap.test;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.List;
......@@ -22,14 +20,11 @@ import org.ws4d.coap.interfaces.CoapClient;
import org.ws4d.coap.interfaces.CoapClientChannel;
import org.ws4d.coap.interfaces.CoapRequest;
import org.ws4d.coap.interfaces.CoapResponse;
import org.ws4d.coap.messages.CoapEmptyMessage;
import org.ws4d.coap.messages.CoapMediaType;
import org.ws4d.coap.messages.CoapRequestCode;
/**
* @author Nico Laum <nico.laum@uni-rostock.de>
* @author Christian Lerche <christian.lerche@uni-rostock.de>
*
*/
public class PlugtestClient implements CoapClient{
CoapChannelManager channelManager = null;
......@@ -60,7 +55,7 @@ public class PlugtestClient implements CoapClient{
public void start(String serverAddress, int serverPort, String testcase, String filter){
System.out.println("===START=== (Run Test Client: " + testcase + ")");
String testId = testcase;
//String testId = testcase;
this.serverAddress = serverAddress;
this.serverPort = serverPort;
this.filter = filter;
......
......@@ -25,17 +25,18 @@ import org.ws4d.coap.messages.CoapMediaType;
import org.ws4d.coap.messages.CoapResponseCode;
public class PlugtestSeparateResponseCoapServer implements CoapServer {
private static final int PORT = 5683;
static int counter = 0;
CoapResponse response = null;
CoapServerChannel channel = null;
int separateResponseTimeMs = 4000;
public void start(int separateResponseTimeMs){
CoapChannelManager channelManager = BasicCoapChannelManager.getInstance();
channelManager.createServerListener(this, PORT);
this.separateResponseTimeMs = separateResponseTimeMs;
}
private static final int PORT = 5683;
static int counter = 0;
CoapResponse response = null;
CoapServerChannel channel = null;
int separateResponseTimeMs = 4000;
public void start(int separateResponseTimeMs) {
CoapChannelManager channelManager = BasicCoapChannelManager
.getInstance();
channelManager.createServerListener(this, PORT);
this.separateResponseTimeMs = separateResponseTimeMs;
}
@Override
public CoapServer onAccept(CoapRequest request) {
......@@ -48,29 +49,35 @@ public class PlugtestSeparateResponseCoapServer implements CoapServer {
System.out.println("Received message: " + request.toString());
this.channel = channel;
response = channel.createSeparateResponse(request, CoapResponseCode.Content_205);
(new Thread( new SendDelayedResponse())).start();
response = channel.createSeparateResponse(request,
CoapResponseCode.Content_205);
(new Thread(new SendDelayedResponse())).start();
}
public class SendDelayedResponse implements Runnable
{
public void run()
{
response.setContentType(CoapMediaType.text_plain);
response.setPayload("payload...".getBytes());
try {
Thread.sleep(separateResponseTimeMs);
} catch (InterruptedException e) {
e.printStackTrace();
}
channel.sendSeparateResponse(response);
System.out.println("Send separate Response: " + response.toString());
}
public class SendDelayedResponse implements Runnable {
public void run() {
response.setContentType(CoapMediaType.text_plain);
response.setPayload("payload...".getBytes());
try {
Thread.sleep(separateResponseTimeMs);
} catch (InterruptedException e) {
e.printStackTrace();
}
channel.sendSeparateResponse(response);
System.out
.println("Send separate Response: " + response.toString());
}
}
@Override
public void onSeparateResponseFailed(CoapServerChannel channel) {
System.out.println("Separate Response failed");
}
@Override
public void onReset(CoapRequest lastRequest) {
// TODO Auto-generated method stub
}
}
......@@ -22,131 +22,132 @@ import org.ws4d.coap.test.resources.TestResource;
*/
public class PlugtestServer {
private static PlugtestServer plugtestServer;
private CoapResourceServer resourceServer;
private static Logger logger = Logger
.getLogger(BasicCoapSocketHandler.class.getName());
/**
* @param args
*/
public static void main(String[] args) {
if (args.length > 1 || args.length < 1) {
System.err.println("illegal number of arguments");
System.exit(1);
}
logger.setLevel(Level.WARNING);
plugtestServer = new PlugtestServer();
plugtestServer.start(args[0]);
private static PlugtestServer plugtestServer;
private CoapResourceServer resourceServer;
private static Logger logger = Logger
.getLogger(BasicCoapSocketHandler.class.getName());
/**
* @param args
*/
public static void main(String[] args) {
if (args.length > 1 || args.length < 1) {
System.err.println("illegal number of arguments");
System.exit(1);
}
logger.setLevel(Level.WARNING);
plugtestServer = new PlugtestServer();
plugtestServer.start(args[0]);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("PlugtestServer is now stopping.");
System.out.println("===END===");
}
});
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("PlugtestServer is now stopping.");
System.out.println("===END===");
}
});
}
public void start(String testId) {
System.out.println("===Run Test Server: " + testId + "===");
init();
if (testId.equals("TD_COAP_CORE_01")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_02")) {
/* Nothing to setup, POST creates new resource */
run();
} else if (testId.equals("TD_COAP_CORE_03")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_04")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_05")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_06")) {
/* Nothing to setup, POST creates new resource */
run();
} else if (testId.equals("TD_COAP_CORE_07")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_08")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_09")) {
public void start(String testId) {
System.out.println("===Run Test Server: " + testId + "===");
init();
if (testId.equals("TD_COAP_CORE_01")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_02")) {
/* Nothing to setup, POST creates new resource */
run();
} else if (testId.equals("TD_COAP_CORE_03")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_04")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_05")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_06")) {
/* Nothing to setup, POST creates new resource */
run();
} else if (testId.equals("TD_COAP_CORE_07")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_08")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_09")) {
/*
* === SPECIAL CASE: Separate Response: for these tests we cannot
* use the resource server
*/
PlugtestSeparateResponseCoapServer server = new PlugtestSeparateResponseCoapServer();
server.start(TestConfiguration.SEPARATE_RESPONSE_TIME_MS);
} else if (testId.equals("TD_COAP_CORE_10")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_11")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_12")) {
resourceServer.createResource(new LongPathResource());
run();
} else if (testId.equals("TD_COAP_CORE_13")) {
resourceServer.createResource(new QueryResource());
run();
} else if (testId.equals("TD_COAP_CORE_14")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_15")) {
/*
* === SPECIAL CASE: Separate Response: for these tests we cannot
* use the resource server
*/
PlugtestSeparateResponseCoapServer server = new PlugtestSeparateResponseCoapServer();
server.start(TestConfiguration.SEPARATE_RESPONSE_TIME_MS);
} else if (testId.equals("TD_COAP_CORE_10")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_11")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_12")) {
resourceServer.createResource(new LongPathResource());
run();
} else if (testId.equals("TD_COAP_CORE_13")) {
resourceServer.createResource(new QueryResource());
run();
} else if (testId.equals("TD_COAP_CORE_14")) {
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_15")) {
/*
* === SPECIAL CASE: Separate Response: for these tests we cannot
* use the resource server
*/
PlugtestSeparateResponseCoapServer server = new PlugtestSeparateResponseCoapServer();
server.start(TestConfiguration.SEPARATE_RESPONSE_TIME_MS);
} else if (testId.equals("TD_COAP_CORE_16")) {
/*
* === SPECIAL CASE: Separate Response: for these tests we cannot
* use the resource server
*/
PlugtestSeparateResponseCoapServer server = new PlugtestSeparateResponseCoapServer();
server.start(TestConfiguration.SEPARATE_RESPONSE_TIME_MS);
} else if (testId.equals("TD_COAP_LINK_01")) {
resourceServer.createResource(new LongPathResource());
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_LINK_02")) {
resourceServer.createResource(new LongPathResource());
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_BLOCK_01")) {
} else if (testId.equals("TD_COAP_BLOCK_02")) {
} else if (testId.equals("TD_COAP_BLOCK_03")) {
} else if (testId.equals("TD_COAP_BLOCK_04")) {
} else if (testId.equals("TD_COAP_OBS_01")) {
} else if (testId.equals("TD_COAP_OBS_02")) {
} else if (testId.equals("TD_COAP_OBS_03")) {
} else if (testId.equals("TD_COAP_OBS_04")) {
} else if (testId.equals("TD_COAP_OBS_05")) {
} else {
System.out.println("unknown test case");
System.exit(-1);
PlugtestSeparateResponseCoapServer server = new PlugtestSeparateResponseCoapServer();
server.start(TestConfiguration.SEPARATE_RESPONSE_TIME_MS);
} else if (testId.equals("TD_COAP_CORE_16")) {
/*
* === SPECIAL CASE: Separate Response: for these tests we cannot
* use the resource server
*/
PlugtestSeparateResponseCoapServer server = new PlugtestSeparateResponseCoapServer();
server.start(TestConfiguration.SEPARATE_RESPONSE_TIME_MS);
} else if (testId.equals("TD_COAP_LINK_01")) {
resourceServer.createResource(new LongPathResource());
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_LINK_02")) {
resourceServer.createResource(new LongPathResource());
resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_BLOCK_01")) {
} else if (testId.equals("TD_COAP_BLOCK_02")) {
} else if (testId.equals("TD_COAP_BLOCK_03")) {
} else if (testId.equals("TD_COAP_BLOCK_04")) {
} else if (testId.equals("TD_COAP_OBS_01")) {
} else if (testId.equals("TD_COAP_OBS_02")) {
} else if (testId.equals("TD_COAP_OBS_03")) {
} else if (testId.equals("TD_COAP_OBS_04")) {
} else if (testId.equals("TD_COAP_OBS_05")) {
} else {
System.out.println("unknown test case");
System.exit(-1);
}
}
}
private void init() {
BasicCoapChannelManager.getInstance().setMessageId(2000);
if (resourceServer != null)
resourceServer.stop();
resourceServer = new CoapResourceServer();
private void init() {
BasicCoapChannelManager.getInstance().setMessageId(2000);
if (resourceServer != null)
resourceServer.stop();
resourceServer = new CoapResourceServer();
}
}
private void run() {
try {
resourceServer.start();
} catch (Exception e) {
e.printStackTrace();
private void run() {
try {
resourceServer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}