forked from eclipse-edc/Connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,053 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
plugins { | ||
`java-library` | ||
} | ||
|
||
repositories { | ||
jcenter() | ||
} | ||
|
||
val jetBrainsAnnotationsVersion: String by project | ||
val jacksonVersion: String by project | ||
|
||
subprojects { | ||
repositories { | ||
jcenter() | ||
maven { | ||
url = uri("https://maven.iais.fraunhofer.de/artifactory/eis-ids-public/") | ||
} | ||
} | ||
} | ||
|
||
allprojects { | ||
pluginManager.withPlugin("java-library") { | ||
dependencies { | ||
api("org.jetbrains:annotations:${jetBrainsAnnotationsVersion}") | ||
api("com.fasterxml.jackson.core:jackson-core:${jacksonVersion}") | ||
api("com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}") | ||
api("com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}") | ||
api("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonVersion}") | ||
|
||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.2") | ||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2") | ||
} | ||
|
||
} | ||
} | ||
|
||
val test by tasks.getting(Test::class) { | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
val infoModelVersion: String by project | ||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
api(project(":spi")) | ||
} | ||
|
63 changes: 63 additions & 0 deletions
63
core/src/main/java/com/microsoft/dagx/monitor/ConsoleMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.microsoft.dagx.monitor; | ||
|
||
import com.microsoft.dagx.spi.monitor.Monitor; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Default monitor implementation. | ||
*/ | ||
public class ConsoleMonitor implements Monitor { | ||
private Level level; | ||
|
||
public enum Level { | ||
SEVERE(2), INFO(1), DEBUG(0); | ||
|
||
int value; | ||
|
||
Level(int value) { | ||
this.value = value; | ||
} | ||
} | ||
|
||
public ConsoleMonitor() { | ||
level = Level.DEBUG; | ||
} | ||
|
||
public ConsoleMonitor(@Nullable String runtimeName, Level level) { | ||
this.level = level; | ||
} | ||
|
||
public void severe(Supplier<String> supplier, Throwable... errors) { | ||
output("SEVERE", supplier); | ||
} | ||
|
||
public void info(Supplier<String> supplier, Throwable... errors) { | ||
if (Level.INFO.value < level.value) { | ||
return; | ||
} | ||
output("INFO", supplier); | ||
} | ||
|
||
public void debug(Supplier<String> supplier, Throwable... errors) { | ||
if (Level.DEBUG.value < level.value) { | ||
return; | ||
} | ||
output("DEBUG", supplier); | ||
} | ||
|
||
private void output(String level, Supplier<String> supplier, Throwable... errors) { | ||
String time = ZonedDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); | ||
System.out.println(level + " " + time + " " + supplier.get()); | ||
if (errors != null) { | ||
for (Throwable error : errors) { | ||
if (error != null) { | ||
error.printStackTrace(System.out); | ||
} | ||
} | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
core/src/main/java/com/microsoft/dagx/system/DefaultServiceExtensionContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.microsoft.dagx.system; | ||
|
||
import com.microsoft.dagx.spi.monitor.Monitor; | ||
import com.microsoft.dagx.spi.system.ServiceExtensionContext; | ||
import com.microsoft.dagx.spi.types.TypeManager; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Base service extension context. | ||
*/ | ||
public class DefaultServiceExtensionContext implements ServiceExtensionContext { | ||
private Monitor monitor; | ||
private TypeManager typeManager; | ||
private Map<Class<?>, Object> services = new HashMap<>(); | ||
|
||
public DefaultServiceExtensionContext(TypeManager typeManager, Monitor monitor) { | ||
this.monitor = monitor; | ||
} | ||
|
||
@Override | ||
public Monitor getMonitor() { | ||
return monitor; | ||
} | ||
|
||
@Override | ||
public TypeManager getTypeManager() { | ||
return typeManager; | ||
} | ||
|
||
@Override | ||
public <T> T getSetting(String setting, T defaultValue) { | ||
return defaultValue; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <T> T getService(Class<T> type) { | ||
return (T) services.get(type); | ||
} | ||
|
||
@Override | ||
public <T> void registerService(Class<T> type, T service) { | ||
services.put(type, service); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
val infoModelVersion: String by project | ||
val servletApi: String by project | ||
val rsApi: String by project | ||
val jettyVersion: String by project | ||
val jerseyVersion: String by project | ||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
api(project(":spi")) | ||
|
||
implementation("javax.ws.rs:javax.ws.rs-api:${rsApi}"); | ||
|
||
implementation("org.eclipse.jetty:jetty-webapp:${jettyVersion}") { | ||
exclude("jetty-xml") | ||
} | ||
implementation("org.glassfish.jersey.core:jersey-server:${jerseyVersion}") | ||
implementation("org.glassfish.jersey.containers:jersey-container-servlet-core:${jerseyVersion}") | ||
implementation("org.glassfish.jersey.core:jersey-common:${jerseyVersion}") | ||
implementation("org.glassfish.jersey.media:jersey-media-json-jackson:${jerseyVersion}") | ||
implementation("org.glassfish.jersey.inject:jersey-hk2:${jerseyVersion}") | ||
implementation("org.glassfish.jersey.containers:jersey-container-servlet:${jerseyVersion}") | ||
|
||
} | ||
|
||
|
42 changes: 42 additions & 0 deletions
42
extensions/protocol/web/src/main/java/com/microsoft/dagx/web/WebServiceExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.microsoft.dagx.web; | ||
|
||
import com.microsoft.dagx.spi.monitor.Monitor; | ||
import com.microsoft.dagx.spi.system.ServiceExtension; | ||
import com.microsoft.dagx.spi.system.ServiceExtensionContext; | ||
import com.microsoft.dagx.web.rest.JerseyRestService; | ||
import com.microsoft.dagx.web.transport.JettyService; | ||
|
||
/** | ||
* Provides HTTP transport and REST binding services. | ||
* | ||
* TODO create keystore to support HTTPS | ||
*/ | ||
public class WebServiceExtension implements ServiceExtension { | ||
private Monitor monitor; | ||
private JettyService jettyService; | ||
private JerseyRestService jerseyRestService; | ||
|
||
@Override | ||
public void initialize(ServiceExtensionContext context) { | ||
monitor = context.getMonitor(); | ||
jettyService = new JettyService(context::getSetting, monitor); | ||
jerseyRestService = new JerseyRestService(jettyService, monitor); | ||
monitor.info("Initialized web extension"); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
jerseyRestService.start(); | ||
jettyService.start(); | ||
monitor.info("Started web extension"); | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
if (jettyService != null) { | ||
jettyService.shutdown(); | ||
} | ||
monitor.info("Shutdown web extension"); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
extensions/protocol/web/src/main/java/com/microsoft/dagx/web/rest/JerseyRestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.microsoft.dagx.web.rest; | ||
|
||
import com.microsoft.dagx.spi.DagxException; | ||
import com.microsoft.dagx.spi.monitor.Monitor; | ||
import com.microsoft.dagx.web.transport.JettyService; | ||
import jakarta.ws.rs.core.Configuration; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class JerseyRestService { | ||
private JettyService jettyService; | ||
private Monitor monitor; | ||
|
||
public JerseyRestService(JettyService jettyService, Monitor monitor) { | ||
this.jettyService = jettyService; | ||
this.monitor = monitor; | ||
} | ||
|
||
public void start() { | ||
|
||
try { | ||
Configuration dooo; | ||
ResourceConfig l; | ||
|
||
Set<Object> controllers = new HashSet<>(); | ||
// ExtendedConfig foo; | ||
// Create a Jersey JAX-RS Application | ||
// ResourceConfig resourceConfig = new ResourceConfig(); | ||
// resourceConfig.registerInstances(controllers); | ||
// | ||
// ServletContainer servletContainer = new ServletContainer(resourceConfig); | ||
// jettyService.registerServlet("/api/*", servletContainer); | ||
monitor.info("Registered Web API context"); | ||
} catch (Exception e) { | ||
throw new DagxException(e); | ||
} | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...sions/protocol/web/src/main/java/com/microsoft/dagx/web/transport/JettyConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.microsoft.dagx.web.transport; | ||
|
||
/** | ||
* Provides config values to the Jetty service. | ||
*/ | ||
@FunctionalInterface | ||
public interface JettyConfiguration { | ||
|
||
<T> T getSetting(String setting, T defaultValue); | ||
} |
18 changes: 18 additions & 0 deletions
18
...nsions/protocol/web/src/main/java/com/microsoft/dagx/web/transport/JettyErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.microsoft.dagx.web.transport; | ||
|
||
import org.eclipse.jetty.server.handler.ErrorHandler; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
|
||
/** | ||
* Writes errors as JSON. | ||
*/ | ||
class JettyErrorHandler extends ErrorHandler { | ||
|
||
@Override | ||
protected void handleErrorPage(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message) throws IOException { | ||
writer.write("{ error: '" + code + "'}"); | ||
} | ||
|
||
} |
Oops, something went wrong.