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

aligned to jcoap package structure; adapt to jcoap changes

parent 9e3abe1e
......@@ -8,9 +8,9 @@ package org.ws4d.coap.test;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ws4d.coap.connection.BasicCoapChannelManager;
import org.ws4d.coap.connection.BasicCoapSocketHandler;
import org.ws4d.coap.rest.CoapResourceServer;
import org.ws4d.coap.core.connection.BasicCoapChannelManager;
import org.ws4d.coap.core.connection.BasicCoapSocketHandler;
import org.ws4d.coap.core.rest.CoapResourceServer;
import org.ws4d.coap.test.resources.LongPathResource;
import org.ws4d.coap.test.resources.QueryResource;
import org.ws4d.coap.test.resources.TestResource;
......@@ -49,23 +49,23 @@ public class CompletePlugtestServer {
System.out.println("===Run Test Server ===");
init();
resourceServer.createResource(new TestResource());
resourceServer.createResource(new LongPathResource());
resourceServer.createResource(new QueryResource());
this.resourceServer.createResource(new TestResource());
this.resourceServer.createResource(new LongPathResource());
this.resourceServer.createResource(new QueryResource());
run();
}
private void init() {
BasicCoapChannelManager.getInstance().setMessageId(2000);
if (resourceServer != null)
resourceServer.stop();
resourceServer = new CoapResourceServer();
if (this.resourceServer != null)
this.resourceServer.stop();
this.resourceServer = new CoapResourceServer();
}
private void run() {
try {
resourceServer.start();
this.resourceServer.start();
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -12,15 +12,15 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ws4d.coap.Constants;
import org.ws4d.coap.connection.BasicCoapChannelManager;
import org.ws4d.coap.connection.BasicCoapSocketHandler;
import org.ws4d.coap.interfaces.CoapChannelManager;
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.CoapRequestCode;
import org.ws4d.coap.core.CoapClient;
import org.ws4d.coap.core.CoapConstants;
import org.ws4d.coap.core.connection.BasicCoapChannelManager;
import org.ws4d.coap.core.connection.BasicCoapSocketHandler;
import org.ws4d.coap.core.connection.api.CoapChannelManager;
import org.ws4d.coap.core.connection.api.CoapClientChannel;
import org.ws4d.coap.core.enumerations.CoapRequestCode;
import org.ws4d.coap.core.messages.api.CoapRequest;
import org.ws4d.coap.core.messages.api.CoapResponse;
/**
* @author Nico Laum <nico.laum@uni-rostock.de>
......@@ -48,7 +48,7 @@ public class PlugtestClient implements CoapClient{
logger.setLevel(Level.WARNING);
PlugtestClient client = new PlugtestClient();
//client.start(args[0], Integer.parseInt(args[1]), args[2], args[3]);
client.start("127.0.0.1", Constants.COAP_DEFAULT_PORT, "TD_COAP_LINK_02", "");
client.start("127.0.0.1", CoapConstants.COAP_DEFAULT_PORT, "TD_COAP_LINK_02", "");
}
......@@ -59,13 +59,13 @@ public class PlugtestClient implements CoapClient{
this.serverAddress = serverAddress;
this.serverPort = serverPort;
this.filter = filter;
this.serverList = new HashMap<String, List<String>>();
this.serverList = new HashMap<>();
init(false, CoapRequestCode.GET);
request.setUriPath("/.well-known/core");
this.request.setUriPath("/.well-known/core");
// request.setUriPath("/test");
System.out.println("QueryPath: " + request.getUriPath() );
System.out.println("QueryPath: " + this.request.getUriPath() );
/* if (testId.equals("TD_COAP_CORE_01")) {
init(true, CoapRequestCode.GET);
......@@ -159,16 +159,16 @@ public class PlugtestClient implements CoapClient{
public void init(boolean reliable, CoapRequestCode requestCode) {
channelManager = BasicCoapChannelManager.getInstance();
channelManager.setMessageId(1000);
this.channelManager = BasicCoapChannelManager.getInstance();
this.channelManager.setMessageId(1000);
try {
clientChannel = channelManager.connect(this, InetAddress.getByName(this.serverAddress), this.serverPort);
if (clientChannel == null){
this.clientChannel = this.channelManager.connect(this, InetAddress.getByName(this.serverAddress), this.serverPort);
if (this.clientChannel == null){
System.out.println("Connect failed.");
System.exit(-1);
}
request = clientChannel.createRequest(reliable, requestCode);
this.request = this.clientChannel.createRequest(reliable, requestCode);
} catch (UnknownHostException e) {
e.printStackTrace();
......@@ -177,12 +177,12 @@ public class PlugtestClient implements CoapClient{
}
public void run() {
if(request.getPayload() != null){
System.out.println("Send Request: " + request.toString() + " (" + new String(request.getPayload()) +")");
if(this.request.getPayload() != null){
System.out.println("Send Request: " + this.request.toString() + " (" + new String(this.request.getPayload()) +")");
}else {
System.out.println("Send Request: " + request.toString());
System.out.println("Send Request: " + this.request.toString());
}
clientChannel.sendMessage(request);
this.clientChannel.sendMessage(this.request);
}
......@@ -201,7 +201,7 @@ public class PlugtestClient implements CoapClient{
} else {
System.out.println("Response: " + response.toString());
}
if (exitAfterResponse){
if (this.exitAfterResponse){
System.out.println("===END===");
System.exit(0);
}
......
......@@ -15,14 +15,14 @@
package org.ws4d.coap.test;
import org.ws4d.coap.connection.BasicCoapChannelManager;
import org.ws4d.coap.interfaces.CoapChannelManager;
import org.ws4d.coap.interfaces.CoapRequest;
import org.ws4d.coap.interfaces.CoapResponse;
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.core.CoapServer;
import org.ws4d.coap.core.connection.BasicCoapChannelManager;
import org.ws4d.coap.core.connection.api.CoapChannelManager;
import org.ws4d.coap.core.connection.api.CoapServerChannel;
import org.ws4d.coap.core.enumerations.CoapMediaType;
import org.ws4d.coap.core.enumerations.CoapResponseCode;
import org.ws4d.coap.core.messages.api.CoapRequest;
import org.ws4d.coap.core.messages.api.CoapResponse;
public class PlugtestSeparateResponseCoapServer implements CoapServer {
private static final int PORT = 5683;
......@@ -49,23 +49,23 @@ public class PlugtestSeparateResponseCoapServer implements CoapServer {
System.out.println("Received message: " + request.toString());
this.channel = channel;
response = channel.createSeparateResponse(request,
this.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());
PlugtestSeparateResponseCoapServer.this.response.setContentType(CoapMediaType.text_plain);
PlugtestSeparateResponseCoapServer.this.response.setPayload("payload...".getBytes());
try {
Thread.sleep(separateResponseTimeMs);
Thread.sleep(PlugtestSeparateResponseCoapServer.this.separateResponseTimeMs);
} catch (InterruptedException e) {
e.printStackTrace();
}
channel.sendSeparateResponse(response);
PlugtestSeparateResponseCoapServer.this.channel.sendSeparateResponse(PlugtestSeparateResponseCoapServer.this.response);
System.out
.println("Send separate Response: " + response.toString());
.println("Send separate Response: " + PlugtestSeparateResponseCoapServer.this.response.toString());
}
}
......
......@@ -8,9 +8,9 @@ package org.ws4d.coap.test;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ws4d.coap.connection.BasicCoapChannelManager;
import org.ws4d.coap.connection.BasicCoapSocketHandler;
import org.ws4d.coap.rest.CoapResourceServer;
import org.ws4d.coap.core.connection.BasicCoapChannelManager;
import org.ws4d.coap.core.connection.BasicCoapSocketHandler;
import org.ws4d.coap.core.rest.CoapResourceServer;
import org.ws4d.coap.test.resources.LongPathResource;
import org.ws4d.coap.test.resources.QueryResource;
import org.ws4d.coap.test.resources.TestResource;
......@@ -52,28 +52,28 @@ public class PlugtestServer {
System.out.println("===Run Test Server: " + testId + "===");
init();
if (testId.equals("TD_COAP_CORE_01")) {
resourceServer.createResource(new TestResource());
this.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());
this.resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_04")) {
resourceServer.createResource(new TestResource());
this.resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_05")) {
resourceServer.createResource(new TestResource());
this.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());
this.resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_08")) {
resourceServer.createResource(new TestResource());
this.resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_09")) {
/*
......@@ -83,19 +83,19 @@ public class PlugtestServer {
PlugtestSeparateResponseCoapServer server = new PlugtestSeparateResponseCoapServer();
server.start(TestConfiguration.SEPARATE_RESPONSE_TIME_MS);
} else if (testId.equals("TD_COAP_CORE_10")) {
resourceServer.createResource(new TestResource());
this.resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_11")) {
resourceServer.createResource(new TestResource());
this.resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_12")) {
resourceServer.createResource(new LongPathResource());
this.resourceServer.createResource(new LongPathResource());
run();
} else if (testId.equals("TD_COAP_CORE_13")) {
resourceServer.createResource(new QueryResource());
this.resourceServer.createResource(new QueryResource());
run();
} else if (testId.equals("TD_COAP_CORE_14")) {
resourceServer.createResource(new TestResource());
this.resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_CORE_15")) {
/*
......@@ -112,12 +112,12 @@ public class PlugtestServer {
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());
this.resourceServer.createResource(new LongPathResource());
this.resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_LINK_02")) {
resourceServer.createResource(new LongPathResource());
resourceServer.createResource(new TestResource());
this.resourceServer.createResource(new LongPathResource());
this.resourceServer.createResource(new TestResource());
run();
} else if (testId.equals("TD_COAP_BLOCK_01")) {
} else if (testId.equals("TD_COAP_BLOCK_02")) {
......@@ -137,15 +137,15 @@ public class PlugtestServer {
private void init() {
BasicCoapChannelManager.getInstance().setMessageId(2000);
if (resourceServer != null)
resourceServer.stop();
resourceServer = new CoapResourceServer();
if (this.resourceServer != null)
this.resourceServer.stop();
this.resourceServer = new CoapResourceServer();
}
private void run() {
try {
resourceServer.start();
this.resourceServer.start();
} catch (Exception e) {
e.printStackTrace();
}
......
package org.ws4d.coap.test.resources;
import org.ws4d.coap.messages.CoapMediaType;
import org.ws4d.coap.rest.BasicCoapResource;
import org.ws4d.coap.core.enumerations.CoapMediaType;
import org.ws4d.coap.core.rest.BasicCoapResource;
public class LongPathResource extends BasicCoapResource {
private LongPathResource(String path, byte[] value, CoapMediaType mediaType) {
......
package org.ws4d.coap.test.resources;
import org.ws4d.coap.messages.CoapMediaType;
import org.ws4d.coap.rest.BasicCoapResource;
import org.ws4d.coap.core.enumerations.CoapMediaType;
import org.ws4d.coap.core.rest.BasicCoapResource;
public class QueryResource extends BasicCoapResource {
......
package org.ws4d.coap.test.resources;
import org.ws4d.coap.messages.CoapMediaType;
import org.ws4d.coap.rest.BasicCoapResource;
import org.ws4d.coap.core.enumerations.CoapMediaType;
import org.ws4d.coap.core.rest.BasicCoapResource;
public class TestResource extends BasicCoapResource {
......
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