I have an application which is composed of 5 services deployed into minishift (for test puprose) using Kubernetes and Docker.
I use Infinispan as the cluster manager but i have no obligation about that (if the problem come from infinispan i can use another one).
public class ServerService extends AbstractVerticle {
Logger LOG = LoggerFactory.getLogger(ServerService.class);
@Override
public void start() {
Router router = Router.router(vertx);
Set<String> allowedHeaders = new HashSet<>();
allowedHeaders.add("x-requested-with");
allowedHeaders.add("Access-Control-Allow-Origin");
allowedHeaders.add("origin");
allowedHeaders.add("Content-Type");
allowedHeaders.add("accept");
allowedHeaders.add("X-PINGARUNER");
Set<HttpMethod> allowedMethods = new HashSet<>();
allowedMethods.add(HttpMethod.GET);
allowedMethods.add(HttpMethod.POST);
allowedMethods.add(HttpMethod.OPTIONS);
/*
* these methods aren't necessary for this sample,
* but you may need them for your projects
*/
allowedMethods.add(HttpMethod.DELETE);
allowedMethods.add(HttpMethod.PATCH);
allowedMethods.add(HttpMethod.PUT);
router.route().handler(CorsHandler.create("*").allowedHeaders(allowedHeaders));
router.route().handler(BodyHandler.create());
router.get("/").handler(this::invokeMySecondMicroService);
router.post("/investigation").handler(this::troubleshootingTreeHandler);
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}
private void troubleshootingTreeHandler(RoutingContext rc) {
// The body has now been fully read, so retrieve the form attributes
MultiMap formAttributes = rc.request().formAttributes();
Gson gson = new Gson();
JsonObject metadata = new JsonObject();
for (Map.Entry<String, String> entry : formAttributes.getDelegate().entries()) {
LOG.info(entry.getValue());
metadata.add(entry.getKey(), gson.fromJson(entry.getValue(), JsonElement.class));