aboutsummaryrefslogtreecommitdiff
path: root/juick-server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-09-05 14:15:46 +0300
committerGravatar Vitaly Takmazov2018-09-05 14:15:46 +0300
commit4343897867f5e70a45c015ebe516c2c5e7033346 (patch)
tree722aa931de778426da88285eb67447912deaf87f /juick-server
parent8aa3602287f7b4ebf115b82182e18f7af3a38507 (diff)
ActivityStreams: support both required content-types
Diffstat (limited to 'juick-server')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java19
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java3
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java27
3 files changed, 29 insertions, 20 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
index c3f838ee..ef55edf1 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
@@ -33,7 +33,7 @@ public class Profile {
@Value("${img_url:http://localhost:8080/i/}")
private String baseImagesUri;
- @GetMapping(value = "/u/{userName}", produces = ActivityObject.CONTENT_TYPE)
+ @GetMapping(value = "/u/{userName}", produces = { ActivityObject.LD_JSON_MEDIA_TYPE, ActivityObject.ACTIVITY_JSON_MEDIA_TYPE })
public Person getUser(@PathVariable String userName) {
User user = userService.getUserByName(userName);
if (!user.isAnonymous()) {
@@ -47,16 +47,17 @@ public class Profile {
person.setOutbox(uri.replacePath(String.format("/u/%s/blog/toc", userName)).toUriString());
person.setFollowers(uri.replacePath(String.format("/u/%s/followers/toc", userName)).toUriString());
person.setFollowing(uri.replacePath(String.format("/u/%s/following/toc", userName)).toUriString());
- uri.replacePath(String.format("/a/%d.png", user.getUid()));
+ UriComponentsBuilder image = UriComponentsBuilder.fromUriString(baseImagesUri);
+ image.path(String.format("/a/%d.png", user.getUid()));
Image avatar = new Image();
- avatar.setUrl(uri.toUriString());
+ avatar.setUrl(image.toUriString());
avatar.setMediaType("image/png");
person.setIcon(avatar);
return person;
}
throw new HttpNotFoundException();
}
- @GetMapping(value = "/u/{userName}/blog/toc", produces = ActivityObject.CONTENT_TYPE)
+ @GetMapping(value = "/u/{userName}/blog/toc", produces = { ActivityObject.LD_JSON_MEDIA_TYPE, ActivityObject.ACTIVITY_JSON_MEDIA_TYPE })
public OrderedCollection getOutbox(@PathVariable String userName) {
User user = userService.getUserByName(userName);
if (!user.isAnonymous()) {
@@ -72,7 +73,7 @@ public class Profile {
}
throw new HttpNotFoundException();
}
- @GetMapping(value = "/u/{userName}/blog", produces = ActivityObject.CONTENT_TYPE)
+ @GetMapping(value = "/u/{userName}/blog", produces = { ActivityObject.LD_JSON_MEDIA_TYPE, ActivityObject.ACTIVITY_JSON_MEDIA_TYPE })
public OrderedCollectionPage getOutboxPage(@PathVariable String userName,
@RequestParam(required = false, defaultValue = "0") int before) {
User visitor = UserUtils.getCurrentUser();
@@ -113,7 +114,7 @@ public class Profile {
}
throw new HttpNotFoundException();
}
- @GetMapping(value = "/u/{userName}/followers/toc", produces = ActivityObject.CONTENT_TYPE)
+ @GetMapping(value = "/u/{userName}/followers/toc", produces = { ActivityObject.LD_JSON_MEDIA_TYPE, ActivityObject.ACTIVITY_JSON_MEDIA_TYPE })
public OrderedCollection getFollowers(@PathVariable String userName) {
User user = userService.getUserByName(userName);
if (!user.isAnonymous()) {
@@ -129,7 +130,7 @@ public class Profile {
}
throw new HttpNotFoundException();
}
- @GetMapping(value = "/u/{userName}/followers", produces = ActivityObject.CONTENT_TYPE)
+ @GetMapping(value = "/u/{userName}/followers", produces = { ActivityObject.LD_JSON_MEDIA_TYPE, ActivityObject.ACTIVITY_JSON_MEDIA_TYPE })
public OrderedCollectionPage getFollowersPage(@PathVariable String userName,
@RequestParam(required = false, defaultValue = "0") int page) {
User user = userService.getUserByName(userName);
@@ -161,7 +162,7 @@ public class Profile {
}
throw new HttpNotFoundException();
}
- @GetMapping(value = "/u/{userName}/following/toc", produces = ActivityObject.CONTENT_TYPE)
+ @GetMapping(value = "/u/{userName}/following/toc", produces = { ActivityObject.LD_JSON_MEDIA_TYPE, ActivityObject.ACTIVITY_JSON_MEDIA_TYPE })
public OrderedCollection getFollowing(@PathVariable String userName) {
User user = userService.getUserByName(userName);
if (!user.isAnonymous()) {
@@ -177,7 +178,7 @@ public class Profile {
}
throw new HttpNotFoundException();
}
- @GetMapping(value = "/u/{userName}/following", produces = ActivityObject.CONTENT_TYPE)
+ @GetMapping(value = "/u/{userName}/following", produces = { ActivityObject.LD_JSON_MEDIA_TYPE, ActivityObject.ACTIVITY_JSON_MEDIA_TYPE })
public OrderedCollectionPage getFollowingPage(@PathVariable String userName,
@RequestParam(required = false, defaultValue = "0") int page) {
User user = userService.getUserByName(userName);
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java b/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
index c4672936..7859be86 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
@@ -28,7 +28,8 @@ public abstract class ActivityObject {
}
public final static String CONTEXT_URI = "https://www.w3.org/ns/activitystreams";
- public final static String CONTENT_TYPE = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
+ public final static String LD_JSON_MEDIA_TYPE = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
+ public final static String ACTIVITY_JSON_MEDIA_TYPE = "application/activity+json; profile=\"https://www.w3.org/ns/activitystreams\"";
public Instant getPublished() {
return published;
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index a94acc82..a7104931 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -37,6 +37,7 @@ import com.juick.util.DateFormattersHolder;
import com.juick.util.MessageUtils;
import org.apache.commons.codec.CharEncoding;
import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.IteratorUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
@@ -87,13 +88,17 @@ import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
-import java.nio.file.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
+import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -1328,24 +1333,26 @@ public class ServerTests {
mockMvc.perform(get("/.well-known/webfinger?resource=acct:ugnich@localhost"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.subject", is("acct:ugnich@localhost")))
- .andExpect(jsonPath("$.links", hasSize(2)))
+ .andExpect(jsonPath("$.links", hasSize(1)))
.andExpect(jsonPath("$.links[0].href", is("http://localhost:8080/u/ugnich")));
mockMvc.perform(get("/.well-known/webfinger?resource=acct:durov@localhost"))
.andExpect(status().isNotFound());
}
@Test
public void userProfileAndBlogShouldBeExposedAsActivityStream() throws Exception {
- mockMvc.perform(get("/u/ugnich").accept(ActivityObject.CONTENT_TYPE))
+ mockMvc.perform(get("/u/ugnich").accept(ActivityObject.LD_JSON_MEDIA_TYPE))
.andExpect(status().isOk())
.andExpect(jsonPath("$.@context", is(ActivityObject.CONTEXT_URI)))
- .andExpect(jsonPath("$.icon", is("http://localhost:8080/i/a/1.png")));
+ .andExpect(jsonPath("$.icon.url", is("http://localhost:8080/i/a/1.png")));
jdbcTemplate.execute("DELETE FROM messages");
- IntStream.rangeClosed(1, 30).forEach(i -> {
- messagesService.createMessage(ugnich.getUid(), String.format("message %d", i), null, null);
- });
- mockMvc.perform(get("/u/ugnich/blog").accept(ActivityObject.CONTENT_TYPE))
+ List<Integer> mids = IteratorUtils.toList(IntStream.rangeClosed(1, 30)
+ .mapToObj(i -> messagesService.createMessage(ugnich.getUid(),
+ String.format("message %d", i), null, null))
+ .collect(Collectors.toCollection(ArrayDeque::new)).descendingIterator());
+ List<Integer> midsPage = mids.stream().limit(20).collect(Collectors.toList());
+ mockMvc.perform(get("/u/ugnich/blog").accept(ActivityObject.ACTIVITY_JSON_MEDIA_TYPE))
.andExpect(status().isOk())
- .andExpect(jsonPath("$.first.orderedItems", hasSize(20)))
- .andExpect(jsonPath("$.first.next.href", is("http://localhost:8080/u/ugnich/blog?before=11")));
+ .andExpect(jsonPath("$.orderedItems", hasSize(20)))
+ .andExpect(jsonPath("$.next.href", is("http://localhost:8080/u/ugnich/blog?before=" + midsPage.get(midsPage.size() - 1))));
}
}