Skip to content

Commit 583d4c9

Browse files
committed
Fixed servial bugs.
1 parent d373913 commit 583d4c9

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

client/edge/src/main/java/com/thefirstlineofcode/sand/client/edge/AbstractEdgeThing.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ public StandardStreamConfig getStreamConfig() {
134134
@Override
135135
public void setStreamConfig(StandardStreamConfig streamConfig) {
136136
this.streamConfig = streamConfig;
137+
Map<String, String> attributes = loadThingAttributes();
138+
attributes.put(ATTRIBUTE_NAME_STREAM_CONFIG, getStreamConfigString());
139+
140+
saveAttributes(attributes);
137141
}
138142

139143
@Override
@@ -314,7 +318,7 @@ public void connect() {
314318
logger.info("The thing tries to connect to server.");
315319

316320
try {
317-
chatClient.connect(new UsernamePasswordToken(registeredThing.getThingName().toString(),
321+
chatClient.connect(new UsernamePasswordToken(registeredThing.getThingName(),
318322
registeredThing.getCredentials()));
319323

320324
if (isConnected()) {
@@ -613,7 +617,7 @@ protected RegisteredThing getRegisteredThing(Map<String, String> attributes) {
613617
RegisteredThing registeredThing = new RegisteredThing();
614618
registeredThing.setThingName(st.nextToken().trim());
615619
registeredThing.setCredentials(st.nextToken().trim());
616-
registeredThing.setCredentials(st.nextToken().trim());
620+
registeredThing.setSecurityKey(BinaryUtils.decodeFromBase64(st.nextToken().trim()));
617621

618622
return registeredThing;
619623
}

demo/protocols/src/main/java/com/thefirstlineofcode/sand/demo/protocols/Sl01ModelDescriptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.thefirstlineofcode.sand.demo.protocols;
22

3+
import java.util.HashMap;
34
import java.util.Map;
45

56
import com.thefirstlineofcode.basalt.xmpp.core.Protocol;
@@ -19,7 +20,7 @@ public Sl01ModelDescriptor() {
1920

2021
@Override
2122
public Map<Protocol, Class<?>> getSupportedActions() {
22-
Map<Protocol, Class<?>> supportedActions = super.getSupportedActions();
23+
Map<Protocol, Class<?>> supportedActions = new HashMap<>(super.getSupportedActions());
2324

2425
supportedActions.put(Flash.PROTOCOL, Flash.class);
2526
supportedActions.put(TurnOn.PROTOCOL, TurnOn.class);

server/lite/things/src/main/java/com/thefirstlineofcode/sand/server/lite/things/ThingManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,13 @@ public Class<?> getFollowedEventType(String model, Protocol protocol) {
449449

450450
@Override
451451
public boolean isUnregisteredThing(String thingId, String registrationCode) {
452-
if (isRegistered(thingId)) {
453-
throw new ProtocolException(new Conflict());
454-
}
455-
456-
if (registrationCustomizer != null)
452+
if (registrationCustomizer != null) {
457453
return registrationCustomizer.isUnregisteredThing(thingId, registrationCode);
454+
} else {
455+
if (isRegistered(thingId)) {
456+
throw new ProtocolException(new Conflict());
457+
}
458+
}
458459

459460
return isValid(thingId);
460461
}

server/lite/things/src/main/resources/META-INF/data/RegisteredThingMapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
</select>
2020

2121
<select id="selectCountByThingName" resultType="int">
22-
SELECT count(*) FROM THING_IDENTITIES WHERE thing_name = #{0}
22+
SELECT count(*) FROM REGISTERED_THINGS WHERE thing_name = #{0}
2323
</select>
2424
</mapper>

server/lite/things/src/main/resources/META-INF/data/ThingAuthorizationMapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</insert>
88

99
<update id="updateCanceled">
10-
UPDATE THING_IDENTITIES SET canceled = #{1} WHERE thing_id = #{0}
10+
UPDATE REGISTERED_THINGS SET canceled = #{1} WHERE thing_id = #{0}
1111
</update>
1212

1313
<select id="selectByThingId" resultMap="thingAuthorizationResultMap">

server/lite/things/src/main/resources/META-INF/data/ThingMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</select>
1616

1717
<select id="selectByThingName" resultType="com.thefirstlineofcode.sand.server.lite.things.D_Thing">
18-
SELECT things.* FROM THINGS AS things LEFT JOIN THING_IDENTITIES as thing_identities ON things.thing_id = thing_identities.thing_id WHERE thing_identities.thing_name=#{0}
18+
SELECT things.* FROM THINGS AS things LEFT JOIN REGISTERED_THINGS as registered_things ON things.thing_id = registered_things.thing_id WHERE registered_things.thing_name=#{0}
1919
</select>
2020

2121
<resultMap id="thingResultMap" type="Thing">
@@ -31,6 +31,6 @@
3131
</select>
3232

3333
<select id="selectCountByThingName" resultType="int">
34-
SELECT count(*) FROM THINGS AS things LEFT JOIN THING_IDENTITIES as thing_identities ON things.thing_id = thing_identities.thing_id WHERE thing_identities.thing_name=#{0}
34+
SELECT count(*) FROM THINGS AS things LEFT JOIN REGISTERED_THINGS as registered_things ON things.thing_id = registered_things.thing_id WHERE registered_things.thing_name=#{0}
3535
</select>
3636
</mapper>

server/things/src/main/java/com/thefirstlineofcode/sand/server/things/AbstractThingRegistrationCustomizer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.Random;
44

5+
import com.thefirstlineofcode.basalt.xmpp.core.ProtocolException;
6+
import com.thefirstlineofcode.basalt.xmpp.core.stanza.error.BadRequest;
7+
import com.thefirstlineofcode.basalt.xmpp.core.stanza.error.Conflict;
58
import com.thefirstlineofcode.sand.protocols.thing.IThingModelDescriptor;
69

710
public abstract class AbstractThingRegistrationCustomizer implements IThingRegistrationCustomizer {
@@ -10,7 +13,10 @@ public abstract class AbstractThingRegistrationCustomizer implements IThingRegis
1013
@Override
1114
public boolean isUnregisteredThing(String thingId, String registrationKey) {
1215
if (thingId == null || thingId.length() == 0)
13-
return false;
16+
throw new ProtocolException(new BadRequest("Null thing ID."));
17+
18+
if (thingManager.isRegistered(thingId))
19+
throw new ProtocolException(new Conflict());
1420

1521
IThingModelDescriptor[] modelDescriptors = thingManager.getModelDescriptors();
1622
for (IThingModelDescriptor modelDescriptor : modelDescriptors) {

0 commit comments

Comments
 (0)