forked from apache/incubator-kie-drools
-
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.
Add config for data index url (apache#10)
- Loading branch information
1 parent
387bc35
commit 55f2af2
Showing
6 changed files
with
106 additions
and
2 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
48 changes: 48 additions & 0 deletions
48
04-kogito-travel-agency/src/main/java/org/kie/kogito/app/VertxRouter.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,48 @@ | ||
package org.kie.kogito.app; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import io.quarkus.vertx.web.Route; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.http.HttpHeaders; | ||
import io.vertx.ext.web.RoutingContext; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import static io.vertx.core.http.HttpMethod.GET; | ||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
@ApplicationScoped | ||
public class VertxRouter { | ||
|
||
@Inject | ||
@ConfigProperty(name = "kogito.dataindex.url", defaultValue = "http://localhost:8180/graphql") | ||
private String dataIndexURL; | ||
|
||
@Inject | ||
private Vertx vertx; | ||
|
||
private String resource; | ||
|
||
@PostConstruct | ||
public void init() { | ||
resource = vertx.fileSystem() | ||
.readFileBlocking("META-INF/resources/index.html") | ||
.toString(UTF_8) | ||
.replace("__GRAPHIQL_ENDPOINT__", "\"" + dataIndexURL + "\""); | ||
} | ||
|
||
@Route(path = "/", methods = GET) | ||
public void handle(RoutingContext context) { | ||
try { | ||
context.response() | ||
.putHeader(HttpHeaders.CACHE_CONTROL, "no-cache") | ||
.putHeader(HttpHeaders.CONTENT_TYPE, "text/html;charset=utf8") | ||
.end(resource); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
context.fail(500, ex); | ||
} | ||
} | ||
} |
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
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
48 changes: 48 additions & 0 deletions
48
04-kogito-visas/src/main/java/org/kie/kogito/app/VertxRouter.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,48 @@ | ||
package org.kie.kogito.app; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import io.quarkus.vertx.web.Route; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.http.HttpHeaders; | ||
import io.vertx.ext.web.RoutingContext; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import static io.vertx.core.http.HttpMethod.GET; | ||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
@ApplicationScoped | ||
public class VertxRouter { | ||
|
||
@Inject | ||
@ConfigProperty(name = "kogito.dataindex.url", defaultValue = "http://localhost:8180/graphql") | ||
private String dataIndexURL; | ||
|
||
@Inject | ||
private Vertx vertx; | ||
|
||
private String resource; | ||
|
||
@PostConstruct | ||
public void init() { | ||
resource = vertx.fileSystem() | ||
.readFileBlocking("META-INF/resources/index.html") | ||
.toString(UTF_8) | ||
.replace("__GRAPHIQL_ENDPOINT__", "\"" + dataIndexURL + "\""); | ||
} | ||
|
||
@Route(path = "/", methods = GET) | ||
public void handle(RoutingContext context) { | ||
try { | ||
context.response() | ||
.putHeader(HttpHeaders.CACHE_CONTROL, "no-cache") | ||
.putHeader(HttpHeaders.CONTENT_TYPE, "text/html;charset=utf8") | ||
.end(resource); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
context.fail(500, ex); | ||
} | ||
} | ||
} |
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