Skip to content

Commit

Permalink
Add option to disable host validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstegeman committed Jan 5, 2021
1 parent af9ae9f commit ebb3b28
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 150 deletions.
25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

## [0.14.0] - 2021-01-05
### Added
- Parameter to disable host validation in server.

## [0.13.0] - 2020-09-23
### Changed
- Update author and URLs to indicate new project home.
Expand Down Expand Up @@ -37,7 +41,8 @@
### Changed
- Property, Action, and Event description now use `links` rather than `href`. - [Spec PR](https://github.com/WebThingsIO/wot/pull/119)

[Unreleased]: https://github.com/WebThingsIO/webthing-java/compare/v0.13.0...HEAD
[Unreleased]: https://github.com/WebThingsIO/webthing-java/compare/v0.14.0...HEAD
[0.14.0]: https://github.com/WebThingsIO/webthing-java/compare/v0.13.0...v0.14.0
[0.13.0]: https://github.com/WebThingsIO/webthing-java/compare/v0.12.3...v0.13.0
[0.12.3]: https://github.com/WebThingsIO/webthing-java/compare/v0.12.2...v0.12.3
[0.12.2]: https://github.com/WebThingsIO/webthing-java/compare/v0.12.1...v0.12.2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Add the following dependency to your project:
<dependency>
<groupId>io.webthings</groupId>
<artifactId>webthing</artifactId>
<version>0.13.0</version>
<version>0.14.0</version>
</dependency>
</dependencies>
```
Expand All @@ -29,7 +29,7 @@ Add the following dependency to your project:
```gradle
dependencies {
runtime(
[group: 'io.webthings', name: 'webthing', version: '0.13.0'],
[group: 'io.webthings', name: 'webthing', version: '0.14.0'],
)
}
```
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.webthings</groupId>
<artifactId>webthing</artifactId>
<version>0.13.0</version>
<version>0.14.0</version>

<name>WebThing</name>
<description>Implementation of an HTTP Web Thing.</description>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/io/webthings/webthing/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
* An Action represents an individual action on a thing.
*/
public class Action {
private String id;
private Thing thing;
private String name;
private JSONObject input;
private final String id;
private final Thing thing;
private final String name;
private final JSONObject input;
private String hrefPrefix;
private String href;
private final String href;
private String status;
private String timeRequested;
private final String timeRequested;
private String timeCompleted;

/**
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/webthings/webthing/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* @param <T> The type of the event data.
*/
public class Event<T> {
private Thing thing;
private String name;
private T data;
private String time;
private final Thing thing;
private final String name;
private final T data;
private final String time;

/**
* Initialize the object.
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/io/webthings/webthing/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONArray;
import org.json.JSONObject;

import io.webthings.webthing.errors.PropertyError;

/**
Expand All @@ -16,12 +17,12 @@
* @param <T> The type of the property value.
*/
public class Property<T> {
private Thing thing;
private String name;
private final Thing thing;
private final String name;
private String hrefPrefix;
private String href;
private JSONObject metadata;
private Value<T> value;
private final String href;
private final JSONObject metadata;
private final Value<T> value;

/**
* Initialize the object.
Expand Down
107 changes: 43 additions & 64 deletions src/main/java/io/webthings/webthing/Thing.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import io.webthings.webthing.errors.PropertyError;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -20,21 +19,23 @@
import java.util.Map;
import java.util.Set;

import io.webthings.webthing.errors.PropertyError;

/**
* A Web Thing.
*/
public class Thing {
private String id;
private String context;
private JSONArray type;
private String title;
private String description;
private Map<String, Property> properties;
private Map<String, AvailableAction> availableActions;
private Map<String, AvailableEvent> availableEvents;
private Map<String, List<Action>> actions;
private List<Event> events;
private Set<WebThingServer.ThingHandler.ThingWebSocket> subscribers;
private final String id;
private final String context;
private final JSONArray type;
private final String title;
private final String description;
private final Map<String, Property> properties;
private final Map<String, AvailableAction> availableActions;
private final Map<String, AvailableEvent> availableEvents;
private final Map<String, List<Action>> actions;
private final List<Event> events;
private final Set<WebThingServer.ThingHandler.ThingWebSocket> subscribers;
private String hrefPrefix;
private String uiHref;

Expand Down Expand Up @@ -200,15 +201,10 @@ public void setUiHref(String href) {
public void setHrefPrefix(String prefix) {
this.hrefPrefix = prefix;

this.properties.forEach((name, value) -> {
value.setHrefPrefix(prefix);
});
this.properties.forEach((name, value) -> value.setHrefPrefix(prefix));

this.actions.forEach((actionName, list) -> {
list.forEach((action) -> {
action.setHrefPrefix(prefix);
});
});
this.actions.forEach((actionName, list) -> list.forEach((action) -> action
.setHrefPrefix(prefix)));
}

/**
Expand Down Expand Up @@ -268,6 +264,7 @@ public JSONObject getPropertyDescriptions() {
try {
obj.put(name, value.asPropertyDescription());
} catch (JSONException e) {
// pass
}
});

Expand All @@ -284,15 +281,11 @@ public JSONArray getActionDescriptions(String actionName) {
JSONArray array = new JSONArray();

if (actionName == null) {
this.actions.forEach((name, list) -> {
list.forEach((action) -> {
array.put(action.asActionDescription());
});
});
this.actions.forEach((name, list) -> list.forEach((action) -> array.put(
action.asActionDescription())));
} else if (this.actions.containsKey(actionName)) {
this.actions.get(actionName).forEach((action) -> {
array.put(action.asActionDescription());
});
this.actions.get(actionName)
.forEach((action) -> array.put(action.asActionDescription()));
}

return array;
Expand All @@ -308,9 +301,7 @@ public JSONArray getEventDescriptions(String eventName) {
JSONArray array = new JSONArray();

if (eventName == null) {
this.events.forEach((event) -> {
array.put(event.asEventDescription());
});
this.events.forEach((event) -> array.put(event.asEventDescription()));
} else {
this.events.forEach((event) -> {
if (event.getName().equals(eventName)) {
Expand Down Expand Up @@ -338,9 +329,7 @@ public void addProperty(Property property) {
* @param property Property to remove.
*/
public void removeProperty(Property property) {
if (this.properties.containsKey(property.getName())) {
this.properties.remove(property.getName());
}
this.properties.remove(property.getName());
}

/**
Expand Down Expand Up @@ -380,9 +369,8 @@ public <T> T getProperty(String propertyName) {
*/
public JSONObject getProperties() {
JSONObject properties = new JSONObject();
this.properties.forEach((name, property) -> {
properties.put(name, property.getValue());
});
this.properties.forEach((name, property) -> properties.put(name,
property.getValue()));
return properties;
}

Expand Down Expand Up @@ -427,8 +415,7 @@ public Action getAction(String actionName, String actionId) {
}

List<Action> actions = this.actions.get(actionName);
for (int i = 0; i < actions.size(); ++i) {
Action action = actions.get(i);
for (Action action : actions) {
if (actionId.equals(action.getId())) {
return action;
}
Expand Down Expand Up @@ -547,13 +534,11 @@ public void addSubscriber(WebThingServer.ThingHandler.ThingWebSocket ws) {
* @param ws The websocket
*/
public void removeSubscriber(WebThingServer.ThingHandler.ThingWebSocket ws) {
if (this.subscribers.contains(ws)) {
this.subscribers.remove(ws);
}
this.subscribers.remove(ws);

this.availableEvents.forEach((name, value) -> {
this.removeEventSubscriber(name, ws);
});
this.availableEvents.forEach((name, value) -> this.removeEventSubscriber(
name,
ws));
}

/**
Expand Down Expand Up @@ -597,9 +582,7 @@ public void propertyNotify(Property property) {

String message = json.toString();

this.subscribers.forEach((subscriber) -> {
subscriber.sendMessage(message);
});
this.subscribers.forEach((subscriber) -> subscriber.sendMessage(message));
}

/**
Expand All @@ -615,9 +598,7 @@ public void actionNotify(Action action) {

String message = json.toString();

this.subscribers.forEach((subscriber) -> {
subscriber.sendMessage(message);
});
this.subscribers.forEach((subscriber) -> subscriber.sendMessage(message));
}

/**
Expand All @@ -640,17 +621,17 @@ public void eventNotify(Event event) {

this.availableEvents.get(eventName)
.getSubscribers()
.forEach((subscriber) -> {
subscriber.sendMessage(message);
});
.forEach((subscriber) -> subscriber.sendMessage(
message));
}

/**
* Class to describe an event available for subscription.
*/
private class AvailableEvent {
private JSONObject metadata;
private Set<WebThingServer.ThingHandler.ThingWebSocket> subscribers;
private static class AvailableEvent {
private final JSONObject metadata;
private final Set<WebThingServer.ThingHandler.ThingWebSocket>
subscribers;

/**
* Initialize the object.
Expand Down Expand Up @@ -686,9 +667,7 @@ public void addSubscriber(WebThingServer.ThingHandler.ThingWebSocket ws) {
* @param ws The websocket
*/
public void removeSubscriber(WebThingServer.ThingHandler.ThingWebSocket ws) {
if (this.subscribers.contains(ws)) {
this.subscribers.remove(ws);
}
this.subscribers.remove(ws);
}

/**
Expand All @@ -704,10 +683,10 @@ public Set<WebThingServer.ThingHandler.ThingWebSocket> getSubscribers() {
/**
* Class to describe an action available to be taken.
*/
private class AvailableAction {
private JSONObject metadata;
private Class cls;
private Schema schema;
private static class AvailableAction {
private final JSONObject metadata;
private final Class cls;
private final Schema schema;

/**
* Initialize the object.
Expand Down
Loading

0 comments on commit ebb3b28

Please sign in to comment.