Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkuppe2009-11-25 16:09:30 +0000
committermkuppe2009-11-25 16:09:30 +0000
commit04e82608b28d2f6a60cc6f9fc9227ddd65256e88 (patch)
treedd6b11a50042c7f346aa872b2d7e147d03fb1541
parentcb37934928c9aefc61657984fff0a6eb644d89f7 (diff)
downloadorg.eclipse.ecf-04e82608b28d2f6a60cc6f9fc9227ddd65256e88.tar.gz
org.eclipse.ecf-04e82608b28d2f6a60cc6f9fc9227ddd65256e88.tar.xz
org.eclipse.ecf-04e82608b28d2f6a60cc6f9fc9227ddd65256e88.zip
NEW - bug 296145: [Discovery][jSLP] Refactor SLPMessage to write message header in super classv20091201-0801
https://bugs.eclipse.org/bugs/show_bug.cgi?id=296145
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AttributeReply.java17
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AttributeRequest.java3
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/DAAdvertisement.java2
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java2
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPDaemonImpl.java2
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java22
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceAcknowledgement.java5
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceDeregistration.java3
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceRegistration.java5
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceReply.java5
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceRequest.java3
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceTypeReply.java5
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceTypeRequest.java5
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/test/java/ch/ethz/iks/slp/impl/AttributeParserTest.java4
14 files changed, 40 insertions, 43 deletions
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AttributeReply.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AttributeReply.java
index 88897a645..9f48f9bed 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AttributeReply.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AttributeReply.java
@@ -124,14 +124,13 @@ class AttributeReply extends ReplyMessage {
* if an IO Exception occurs.
* @throws IOException
*/
- void writeTo(final DataOutputStream out) throws IOException {
- super.writeHeader(out, getSize());
- out.writeShort(errorCode);
- out.writeUTF(listToString(attributes, ","));
- out.write(authBlocks.length);
- for (int i = 0; i < authBlocks.length; i++) {
- authBlocks[i].write(out);
- }
+ protected void writeTo(final DataOutputStream out) throws IOException {
+ out.writeShort(errorCode);
+ out.writeUTF(listToString(attributes, ","));
+ out.write(authBlocks.length);
+ for (int i = 0; i < authBlocks.length; i++) {
+ authBlocks[i].write(out);
+ }
}
/**
@@ -140,7 +139,7 @@ class AttributeReply extends ReplyMessage {
* @return the length of the message.
* @see ch.ethz.iks.slp.impl.SLPMessage#getSize()
*/
- int getSize() {
+ protected int getSize() {
int len = getHeaderSize() + 4 + listToString(attributes, ",").length() + 1;
for (int i=0; i<authBlocks.length; i++) {
len += authBlocks[i].getLength();
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AttributeRequest.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AttributeRequest.java
index ca662db1a..0d9800b63 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AttributeRequest.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AttributeRequest.java
@@ -169,7 +169,6 @@ class AttributeRequest extends RequestMessage {
* if an IO Exception occurs.
*/
protected void writeTo(final DataOutputStream out) throws IOException {
- super.writeHeader(out, getSize());
out.writeUTF(listToString(prevRespList, ","));
out.writeUTF(url);
out.writeUTF(listToString(scopeList, ","));
@@ -183,7 +182,7 @@ class AttributeRequest extends RequestMessage {
* @return the length of the message.
* @see ch.ethz.iks.slp.impl.SLPMessage#getSize()
*/
- int getSize() {
+ protected int getSize() {
return getHeaderSize() + 2 + listToString(prevRespList, ",").length()
+ 2 + url.length() + 2 + listToString(scopeList, ",").length()
+ 2 + listToString(tagList, ",").length() + 2 + spi.length();
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/DAAdvertisement.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/DAAdvertisement.java
index 08554c23a..61dcbd8d5 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/DAAdvertisement.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/DAAdvertisement.java
@@ -180,7 +180,7 @@ class DAAdvertisement extends ReplyMessage {
* @return the length of the message.
* @see ch.ethz.iks.slp.impl.SLPMessage#getSize()
*/
- int getSize() {
+ protected int getSize() {
int len = getHeaderSize() + 8 + origURL.length() + 2
+ origScopes.length() + 2 + origAttrs.length() + 2
+ spi.length() + 1;
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java
index a224599ac..794761ec8 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java
@@ -672,7 +672,7 @@ public abstract class SLPCore {
DataOutputStream out = new DataOutputStream(socket
.getOutputStream());
DataInputStream in = new DataInputStream(socket.getInputStream());
- msg.writeTo(out);
+ out.write(msg.getBytes());
final ReplyMessage reply = (ReplyMessage) SLPMessage.parse(
msg.address, msg.port, in, true);
socket.close();
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPDaemonImpl.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPDaemonImpl.java
index 758fb9104..d6e0fa795 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPDaemonImpl.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPDaemonImpl.java
@@ -510,7 +510,7 @@ public final class SLPDaemonImpl implements SLPDaemon {
DataOutputStream out = new DataOutputStream(con
.getOutputStream());
- reply.writeTo(out);
+ out.write(reply.getBytes());
/*
* TODO the RFC encourages to keep the connection open
* to allow the other side to send multiple requests per
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java
index a2ae287b6..e45e8534a 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java
@@ -53,8 +53,6 @@ import ch.ethz.iks.slp.impl.attr.gen.Rule;
*/
public abstract class SLPMessage {
- private static final int SLP_VERSION = 2;
-
/**
* the <code>Locale</code> of the message.
*/
@@ -90,6 +88,12 @@ public abstract class SLPMessage {
*/
boolean multicast;
+
+ /**
+ * the message version according to RFC 2608, Version = 2.
+ */
+ public static final byte VERSION = 2;
+
/**
* the message funcID values according to RFC 2608, Service Request = 1.
*/
@@ -165,7 +169,7 @@ public abstract class SLPMessage {
* @throws ServiceLocationException
* in case of IOExceptions.
*/
- protected void writeHeader(final DataOutputStream out, int msgSize)
+ private void writeHeader(final DataOutputStream out)
throws IOException {
byte flags = 0;
if (funcID == SRVREG) {
@@ -174,10 +178,11 @@ public abstract class SLPMessage {
if (multicast) {
flags |= 0x20;
}
+ int msgSize = getSize();
if (!tcp && msgSize > SLPCore.CONFIG.getMTU()) {
flags |= 0x80;
}
- out.write(SLP_VERSION);
+ out.write(VERSION);
out.write(funcID);
out.write((byte) ((msgSize) >> 16));
out.write((byte) (((msgSize) >> 8) & 0xFF));
@@ -194,7 +199,7 @@ public abstract class SLPMessage {
/**
*
*/
- abstract void writeTo(final DataOutputStream out) throws IOException;
+ protected abstract void writeTo(final DataOutputStream out) throws IOException;
/**
*
@@ -202,6 +207,7 @@ public abstract class SLPMessage {
byte[] getBytes() throws IOException {
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
final DataOutputStream out = new DataOutputStream(bytes);
+ writeHeader(out);
writeTo(out);
return bytes.toByteArray();
}
@@ -245,7 +251,7 @@ public abstract class SLPMessage {
throws ServiceLocationException, ProtocolException {
try {
final int version = in.readByte(); // version
- if (version != SLP_VERSION) {
+ if (version != VERSION) {
in.readByte(); // funcID
final int length = in.readShort();
byte[] drop = new byte[length - 4];
@@ -338,7 +344,7 @@ public abstract class SLPMessage {
*
* @return
*/
- int getHeaderSize() {
+ protected int getHeaderSize() {
return 14 + locale.getLanguage().length();
}
@@ -346,7 +352,7 @@ public abstract class SLPMessage {
*
* @return
*/
- abstract int getSize();
+ protected abstract int getSize();
/**
* Get a string representation of the message. Overridden by message
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceAcknowledgement.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceAcknowledgement.java
index 6dc18b572..b48dedaee 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceAcknowledgement.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceAcknowledgement.java
@@ -39,7 +39,7 @@ import ch.ethz.iks.slp.ServiceLocationException;
* a ServiceAcknowledgement is sent by a DA as reaction to a ServiceRegistration
* or ServiceDeregistration.
*
- * @author Jan S. Rellermeyer, ETH Zürich
+ * @author Jan S. Rellermeyer, ETH Z�rich
* @since 0.1
*/
class ServiceAcknowledgement extends ReplyMessage {
@@ -95,7 +95,6 @@ class ServiceAcknowledgement extends ReplyMessage {
* if an IO Exception occurs.
*/
protected void writeTo(final DataOutputStream out) throws IOException {
- super.writeHeader(out, getSize());
out.writeShort(errorCode);
}
@@ -105,7 +104,7 @@ class ServiceAcknowledgement extends ReplyMessage {
* @return the length of the message.
* @see ch.ethz.iks.slp.impl.SLPMessage#getSize()
*/
- int getSize() {
+ protected int getSize() {
return getHeaderSize() + 2;
}
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceDeregistration.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceDeregistration.java
index a74ce8e92..c6a30e6a0 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceDeregistration.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceDeregistration.java
@@ -138,7 +138,6 @@ class ServiceDeregistration extends SLPMessage {
* in case of IO errors.
*/
protected void writeTo(final DataOutputStream out) throws IOException {
- super.writeHeader(out, getSize());
out.writeUTF(listToString(scopeList, ","));
url.writeTo(out);
out.writeUTF(listToString(attList, ","));
@@ -150,7 +149,7 @@ class ServiceDeregistration extends SLPMessage {
* @return the length of the message.
* @see ch.ethz.iks.slp.impl.SLPMessage#getSize()
*/
- int getSize() {
+ protected int getSize() {
return getHeaderSize() + 2 + listToString(scopeList, ",").length()
+ url.getLength() + 2
+ listToString(attList, ",").length();
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceRegistration.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceRegistration.java
index 2e9dc0ea8..5a8743961 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceRegistration.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceRegistration.java
@@ -173,8 +173,7 @@ class ServiceRegistration extends SLPMessage {
* @throws ServiceLocationException
* if an IO Exception occurs.
*/
- void writeTo(final DataOutputStream out) throws IOException {
- super.writeHeader(out, getSize());
+ protected void writeTo(final DataOutputStream out) throws IOException {
url.writeTo(out);
out.writeUTF(serviceType.toString());
out.writeUTF(listToString(scopeList, ","));
@@ -191,7 +190,7 @@ class ServiceRegistration extends SLPMessage {
* @return the length of the message.
* @see ch.ethz.iks.slp.impl.SLPMessage#getSize()
*/
- int getSize() {
+ protected int getSize() {
int len = getHeaderSize() + url.getLength() + 2
+ serviceType.toString().length() + 2
+ listToString(scopeList, ",").length() + 2
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceReply.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceReply.java
index ac1eb40c0..ab6182ad0 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceReply.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceReply.java
@@ -40,7 +40,7 @@ import ch.ethz.iks.slp.ServiceURL;
/**
* a ServiceReply Message is sent as reaction to a ServiceRequest.
*
- * @author Jan S. Rellermeyer, ETH Zürich
+ * @author Jan S. Rellermeyer, ETH Z�rich
* @since 0.1
*/
class ServiceReply extends ReplyMessage {
@@ -119,7 +119,6 @@ class ServiceReply extends ReplyMessage {
* if an IO Exception occurs.
*/
protected void writeTo(final DataOutputStream out) throws IOException {
- super.writeHeader(out, getSize());
out.writeShort(errorCode);
out.writeShort(urlList.size());
for (int i = 0; i < urlList.size(); i++) {
@@ -133,7 +132,7 @@ class ServiceReply extends ReplyMessage {
* @return the length of the message.
* @see ch.ethz.iks.slp.impl.SLPMessage#getSize()
*/
- int getSize() {
+ protected int getSize() {
int len = getHeaderSize() + 2 + 2;
for (int i = 0; i < urlList.size(); i++) {
len += ((ServiceURL) urlList.get(i)).getLength();
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceRequest.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceRequest.java
index 778a2b9fb..baa32f177 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceRequest.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceRequest.java
@@ -149,7 +149,6 @@ class ServiceRequest extends RequestMessage {
* if an IO Exception occurs.
*/
protected void writeTo(final DataOutputStream out) throws IOException {
- super.writeHeader(out, getSize());
out.writeUTF(listToString(prevRespList, ","));
out.writeUTF(serviceType.toString());
out.writeUTF(listToString(scopeList, ","));
@@ -163,7 +162,7 @@ class ServiceRequest extends RequestMessage {
* @return the length of the message.
* @see ch.ethz.iks.slp.impl.SLPMessage#getSize()
*/
- int getSize() {
+ protected int getSize() {
return getHeaderSize() + 2 + listToString(prevRespList, ",").length()
+ 2 + serviceType.toString().length() + 2
+ listToString(scopeList, ",").length() + 2
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceTypeReply.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceTypeReply.java
index aae20aef3..d0bc69ad5 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceTypeReply.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceTypeReply.java
@@ -37,7 +37,7 @@ import ch.ethz.iks.slp.ServiceLocationException;
/**
* a ServiceReply Message is sent as reaction of a ServiceRequest.
*
- * @author Jan S. Rellermeyer, ETH Zürich
+ * @author Jan S. Rellermeyer, ETH Z�rich
* @since 0.6
*/
class ServiceTypeReply extends ReplyMessage {
@@ -101,7 +101,6 @@ class ServiceTypeReply extends ReplyMessage {
* if an IO Exception occurs.
*/
protected void writeTo(final DataOutputStream out) throws IOException {
- super.writeHeader(out, getSize());
out.writeShort(errorCode);
out.writeUTF(listToString(serviceTypes, ","));
}
@@ -112,7 +111,7 @@ class ServiceTypeReply extends ReplyMessage {
* @return the length of the message.
* @see ch.ethz.iks.slp.impl.SLPMessage#getSize()
*/
- int getSize() {
+ protected int getSize() {
return getHeaderSize() + 2 + 2
+ listToString(serviceTypes, ",").length();
}
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceTypeRequest.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceTypeRequest.java
index 8882eea8e..dccfa4e4c 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceTypeRequest.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/ServiceTypeRequest.java
@@ -40,7 +40,7 @@ import ch.ethz.iks.slp.ServiceLocationException;
/**
* ServiceTypeRequest message is used to find existing service types.
*
- * @author Jan S. Rellermeyer, ETH Zürich
+ * @author Jan S. Rellermeyer, ETH Z�rich
* @since 0.6
*/
class ServiceTypeRequest extends RequestMessage {
@@ -128,7 +128,6 @@ class ServiceTypeRequest extends RequestMessage {
* if an IO Exception occurs.
*/
protected void writeTo(final DataOutputStream out) throws IOException {
- super.writeHeader(out, getSize());
out.writeUTF(listToString(prevRespList, ","));
if (namingAuthority.equals(NA_ALL)) {
out.writeShort(0xFFFF);
@@ -146,7 +145,7 @@ class ServiceTypeRequest extends RequestMessage {
* @return the length of the message.
* @see ch.ethz.iks.slp.impl.SLPMessage#getSize()
*/
- int getSize() {
+ protected int getSize() {
int len = getHeaderSize() + 2
+ listToString(prevRespList, ",").length();
if(namingAuthority.equals(NA_DEFAULT) || namingAuthority.equals(NA_ALL)) {
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/test/java/ch/ethz/iks/slp/impl/AttributeParserTest.java b/protocols/bundles/ch.ethz.iks.slp/src/test/java/ch/ethz/iks/slp/impl/AttributeParserTest.java
index 809f25c14..7633d4963 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/test/java/ch/ethz/iks/slp/impl/AttributeParserTest.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/test/java/ch/ethz/iks/slp/impl/AttributeParserTest.java
@@ -88,11 +88,11 @@ public class AttributeParserTest extends TestCase {
// just make attributeStringToList public
private class SLPTestMessage extends SLPMessage {
- int getSize() {
+ protected int getSize() {
return 0;
}
- void writeTo(DataOutputStream out) throws IOException {
+ protected void writeTo(final DataOutputStream out) throws IOException {
// no op
}

Back to the top