This is an automated email from the ASF dual-hosted git repository. sblackmon pushed a commit to branch feat-3-nodeinfo in repository https://gitbox.apache.org/repos/asf/streams-activitypub.git
commit 656790867a2990068a7803b4de795d4f106a377d Author: Steve Blackmon <sblack...@apache.org> AuthorDate: Sun Feb 18 20:52:17 2024 -0600 feat: integrate with fuseki (graph database+api) #5 resolves #5 : **Add a graph module and a Webfinger implementation using jena graphdb binding** - adds a real implementation of webfinger protocol which responds only to requests for entities that exist in the configured fuseki triple-store - tests capabilities at the WebfingerApi Graph implementation level, and within the packaged webapp - apache/streams-activitypub docker image now runs streams-activitypub-webapp and jena-fuseki2-webapp Signed-off-by: Steve Blackmon <sblack...@apache.org> --- .../api/test/WebfingerApiTestImpl.scala | 15 +++++++++ streams-activitypub-dist/pom.xml | 3 +- .../activitypub/servlets/WebfingerServlet.scala | 14 ++++++-- .../util/AcctPrefixResourceToResourceURISwap.scala | 39 ++++++++++++++++++++++ streams-activitypub-webapp/pom.xml | 21 ++++++++++++ .../test/cases/WebappServerAvailableTest.scala | 7 ++-- .../webapp/test/cases/WebfingerServletTest.scala | 4 +-- 7 files changed, 95 insertions(+), 8 deletions(-) diff --git a/streams-activitypub-api/src/test/scala/org/apache/streams/activitypub/api/test/WebfingerApiTestImpl.scala b/streams-activitypub-api/src/test/scala/org/apache/streams/activitypub/api/test/WebfingerApiTestImpl.scala new file mode 100755 index 0000000..a01db5a --- /dev/null +++ b/streams-activitypub-api/src/test/scala/org/apache/streams/activitypub/api/test/WebfingerApiTestImpl.scala @@ -0,0 +1,15 @@ +package org.apache.streams.activitypub.api.test + +import org.apache.streams.activitypub.api.WebfingerApi +import org.apache.streams.activitypub.api.pojo.WebfingerQueryRequest +import org.apache.streams.activitypub.api.pojo.WebfingerQueryResponse + +class WebfingerApiTestImpl extends WebfingerApi { + + def webfingerQuery(request: WebfingerQueryRequest): WebfingerQueryResponse = { + + new WebfingerQueryResponse().withSubject(request.getResource) + + } + +} diff --git a/streams-activitypub-dist/pom.xml b/streams-activitypub-dist/pom.xml index d412a82..60fc0ec 100755 --- a/streams-activitypub-dist/pom.xml +++ b/streams-activitypub-dist/pom.xml @@ -59,11 +59,12 @@ under the License. <executions> <execution> <id>copy</id> - <phase>prepare-package</phase> + <phase>package</phase> <goals> <goal>copy</goal> </goals> <configuration> + <outputDirectory>${project.build.directory}/exploded</outputDirectory> <artifactItems> <artifactItem> <groupId>org.apache.streams.activitypub</groupId> diff --git a/streams-activitypub-servlets/src/main/scala/org/apache/streams/activitypub/servlets/WebfingerServlet.scala b/streams-activitypub-servlets/src/main/scala/org/apache/streams/activitypub/servlets/WebfingerServlet.scala index 8fec83d..08d97e5 100755 --- a/streams-activitypub-servlets/src/main/scala/org/apache/streams/activitypub/servlets/WebfingerServlet.scala +++ b/streams-activitypub-servlets/src/main/scala/org/apache/streams/activitypub/servlets/WebfingerServlet.scala @@ -4,18 +4,28 @@ import jakarta.servlet.ServletConfig import jakarta.servlet.http.HttpServletResponse import jakarta.ws.rs.core.MediaType import org.apache.juneau.html.HtmlSerializer +import org.apache.juneau.http.annotation.Query import org.apache.juneau.json.JsonSerializer import org.apache.juneau.rest.RestRequest import org.apache.juneau.rest.RestResponse import org.apache.juneau.rest.annotation.Rest import org.apache.juneau.rest.annotation.RestGet +import org.apache.juneau.rest.httppart.RequestQueryParams +import org.apache.juneau.rest.matcher.RestMatcher import org.apache.juneau.rest.servlet.BasicRestServlet -import org.apache.streams.activitypub.api.WebfingerApi +import org.apache.streams.activitypub.api.pojo.Link +import org.apache.streams.activitypub.api.pojo.Properties import org.apache.streams.activitypub.api.pojo.WebfingerQueryRequest import org.apache.streams.activitypub.api.pojo.WebfingerQueryResponse import org.apache.streams.activitypub.graph.impl.WebfingerGraphImpl import org.apache.streams.activitypub.remote.WebfingerRest -import org.apache.streams.activitypub.servlets.WebfingerServlet.webfinger +import org.apache.streams.activitypub.api.WebfingerApi + +import java.net.URI +import java.util.ArrayList +import java.util.Optional +import scala.collection.mutable.Buffer +import scala.util.Try /** * org.apache.streams.activitypub.servlets.WebfingerResource response to inquires about any URI, typically an item in one of the published feeds, or one of the diff --git a/streams-activitypub-utils/src/main/scala/org/apache/streams/activitypub/util/AcctPrefixResourceToResourceURISwap.scala b/streams-activitypub-utils/src/main/scala/org/apache/streams/activitypub/util/AcctPrefixResourceToResourceURISwap.scala new file mode 100644 index 0000000..4c30cce --- /dev/null +++ b/streams-activitypub-utils/src/main/scala/org/apache/streams/activitypub/util/AcctPrefixResourceToResourceURISwap.scala @@ -0,0 +1,39 @@ +package org.apache.streams.activitypub.util + +import org.apache.http.client.utils.URIBuilder +import org.apache.juneau.BeanSession +import org.apache.juneau.ClassMeta +import org.apache.juneau.swap.StringSwap + +import java.net.URI + +object AcctPrefixResourceToResourceURISwap { + def doSwap(uri: URI): String = { + val domain = uri.getHost + val preferredName = uri.getPath.split("/").last + s"acct:${preferredName}@${domain}" + } + def doUnswap(string: String): URI = { + val preferredName = string.split("@")(0) + val domain = string.split("@")(1) + val uriBuilder = new URIBuilder() + .setScheme("https") + .setHost(domain) + .setPath(s"/users/${preferredName}") + uriBuilder.build() + } +} + +class AcctPrefixResourceToResourceURISwap extends StringSwap[URI] { + + //@throws(classOf[Exception]) + override def swap(session: BeanSession, uri: URI) : String = { + AcctPrefixResourceToResourceURISwap.doSwap(uri) + } + + //@throws(classOf[Exception]) + override def unswap(session: BeanSession, in: String, hint: ClassMeta[Any]): URI = { + AcctPrefixResourceToResourceURISwap.doUnswap(in); + } + +} diff --git a/streams-activitypub-webapp/pom.xml b/streams-activitypub-webapp/pom.xml index e9d466d..b35228c 100755 --- a/streams-activitypub-webapp/pom.xml +++ b/streams-activitypub-webapp/pom.xml @@ -134,6 +134,27 @@ <type>jar</type> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.jena</groupId> + <artifactId>jena-fuseki-main</artifactId> + <version>${jena.version}</version> + <type>jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.jena</groupId> + <artifactId>jena-arq</artifactId> + <version>${jena.version}</version> + <type>jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.jena</groupId> + <artifactId>jena-rdfconnection</artifactId> + <version>${jena.version}</version> + <type>jar</type> + <scope>test</scope> + </dependency> </dependencies> <build> <finalName>streams-activitypub-webapp</finalName> diff --git a/streams-activitypub-webapp/src/test/scala/org/apache/streams/activitypub/webapp/test/cases/WebappServerAvailableTest.scala b/streams-activitypub-webapp/src/test/scala/org/apache/streams/activitypub/webapp/test/cases/WebappServerAvailableTest.scala index 9bc3334..1d79ca5 100755 --- a/streams-activitypub-webapp/src/test/scala/org/apache/streams/activitypub/webapp/test/cases/WebappServerAvailableTest.scala +++ b/streams-activitypub-webapp/src/test/scala/org/apache/streams/activitypub/webapp/test/cases/WebappServerAvailableTest.scala @@ -1,13 +1,14 @@ package org.apache.streams.activitypub.webapp.test.cases -import org.apache.streams.activitypub.webapp.test.ActivityPubWebappTestSuiteExtension import org.awaitility.Awaitility.await +import org.awaitility.Awaitility.waitAtMost +import org.awaitility.core.ConditionTimeoutException +import org.apache.streams.activitypub.webapp.test.ActivityPubWebappTestSuite import org.awaitility.scala.AwaitilitySupport +import org.hamcrest.MatcherAssert.assertThat import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Order import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith import org.slf4j.LoggerFactory import scala.concurrent.duration.MINUTES diff --git a/streams-activitypub-webapp/src/test/scala/org/apache/streams/activitypub/webapp/test/cases/WebfingerServletTest.scala b/streams-activitypub-webapp/src/test/scala/org/apache/streams/activitypub/webapp/test/cases/WebfingerServletTest.scala index f464264..2478ccb 100755 --- a/streams-activitypub-webapp/src/test/scala/org/apache/streams/activitypub/webapp/test/cases/WebfingerServletTest.scala +++ b/streams-activitypub-webapp/src/test/scala/org/apache/streams/activitypub/webapp/test/cases/WebfingerServletTest.scala @@ -6,9 +6,9 @@ import org.apache.http.entity.ContentType import org.apache.streams.activitypub.servlets.WebfingerServlet import org.apache.streams.activitypub.webapp.test.ActivityPubWebappTestSuiteExtension import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Order import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import org.slf4j.Logger import org.slf4j.LoggerFactory import java.nio.charset.Charset; @@ -18,7 +18,7 @@ class WebfingerServletTest(using helper: ActivityPubWebappTestSuiteExtension) { private final val LOGGER = LoggerFactory.getLogger(classOf[WebfingerServletTest]); - private val uriBuilder : URIBuilder = helper.uriBuilder + private val uriBuilder : URIBuilder = ActivityPubWebappTestSuite.helper.uriBuilder .setCharset(Charset.defaultCharset()) .setPath(WebfingerServlet.PATH)