Example usage for io.vertx.core.net SocketAddress host

List of usage examples for io.vertx.core.net SocketAddress host

Introduction

In this page you can find the example usage for io.vertx.core.net SocketAddress host.

Prototype

String host();

Source Link

Usage

From source file:io.gravitee.gateway.standalone.vertx.VertxHttpServerRequest.java

License:Apache License

@Override
public String remoteAddress() {
    SocketAddress address = httpServerRequest.remoteAddress();
    return (address != null) ? address.host() : null;
}

From source file:io.gravitee.gateway.standalone.vertx.VertxHttpServerRequest.java

License:Apache License

@Override
public String localAddress() {
    SocketAddress address = httpServerRequest.localAddress();
    return (address != null) ? address.host() : null;
}

From source file:net.sf.sgsimulator.sgsrest.vertx.controllers.PageController.java

License:Open Source License

@GET("/admin")
public synchronized String getAdmin(RoutingContext ctx) {

    SocketAddress remote = ctx.request().remoteAddress();
    JsonObject obj = new JsonObject().put("host", remote.host()).put("port", remote.port());
    // ctx.response().end(obj.encodePrettily());
    String host = obj.getString("host");
    String admincode = System.getProperties().get("sgsimulator.admincode").toString();

    /*if (!admincode.equalsIgnoreCase(code)){
       Log.error("ILLEGAL ACCESS FROM IP "+host);
       return "<H1>WARNING: illegal attempt to access admin interface from IP "+host+". Police will be notified </H1>";
    }*/// w  w  w  . j  av  a2  s.  c  o m

    if (allowedhost.isEmpty()) {
        if (System.getProperties().get("sgsimulator.adminip") != null)
            if (System.getProperties().get("sgsimulator.adminip").equals("-1")) {
                allowedhost = host;
                System.err.println("First host will be the admin");
            } else
                allowedhost = System.getProperties().get("sgsimulator.adminip").toString();
    }

    if (!host.equalsIgnoreCase(allowedhost)) {
        Log.error("ILLEGAL ACCESS FROM IP " + host);
        return "<H1>WARNING: illegal attempt to access admin interface from IP " + host
                + ". Police will be notified </H1>";
    }

    String page = "Not working. Contact the administrator";

    if (System.getProperties().get("sgsimulator.scenario") == null)
        System.getProperties().put("sgsimulator.scenario", "solarbyperson");

    String ptrans = " $.getJSON('/sg/query/transformer-names', function (data) {" + "var items = [];\n"
            + "console.log(data);\n" + "$.each(data.result, function (index, tName) {\n"
            + "    updateTransformers(tName);\n" + "});\n" + "});\n";

    page = "<!DOCTYPE html><html><head><link href=\"/sg/assets/sg.css\" />\n"
            + "<style></style><meta charset=\"utf-8\"><title>SG Charts</title></head><body>   \n"
            + " <H1>Admin panel</H1>"
            + "<script src=\"https://code.jquery.com/jquery-3.2.0.min.js\"></script>\n" + chartMetering
            + chartWeather + billing + ballance + "<H2>Assigned panels</h2>"
            + "<div id='transformer-elements' style=\"text-align: center;\"/>"
            + "<script src=\"http://canvasjs.com/assets/script/canvasjs.min.js\"></script>\n"
            + "<script src=\"/sg/assets/sg.js\"></script>\n" + "<script  type=\"text/javascript\">\n"
            + "updateCounterListener(\"bill\",\"#bill\");    \n"
            + "updateCounterListener(\"powerdump\",\"#accumpower\");\n"
            + "updateListeners(\"generation\",charts.chart1,LASTGENERATED);\n"
            + "updateListeners(\"consumption\",charts.chart1,LASTCONSUMPTION);\n"
            + "updateListeners(\"demand\",charts.chart1,LASTDEMAND);\n"
            + "updateListeners(\"wind\",charts.chart2,WIND);\n"
            + "updateListeners(\"sun\",charts.chart2,SUN);\n" + ptrans + "</script>\n" + "</body>\n"
            + "</html>\n";

    return page;

}

From source file:net.sf.sgsimulator.sgsrest.vertx.controllers.PageController.java

License:Open Source License

@GET("/screen")
public synchronized String getToProjectScreen(RoutingContext ctx) {
    SocketAddress remote = ctx.request().remoteAddress();
    JsonObject obj = new JsonObject().put("host", remote.host()).put("port", remote.port());
    // ctx.response().end(obj.encodePrettily());
    String host = obj.getString("host");
    if (allowedhost.isEmpty()) {
        if (System.getProperties().get("sgsimulator.adminip") != null)
            if (System.getProperties().get("sgsimulator.adminip").equals("-1")) {
                allowedhost = host;//from   w  w w  . j a v a2  s  .c  o  m
                System.err.println("First host will be the admin");
            } else
                allowedhost = System.getProperties().get("sgsimulator.adminip").toString();
    }

    if (!host.equalsIgnoreCase(allowedhost)) {
        Log.error("ILLEGAL ACCESS FROM IP " + host);
        return "<H1>WARNING: illegal attempt to access admin interface from IP " + host
                + ". Police will be notified </H1>";
    }

    String page = "Not working. Contact the administrator";

    if (System.getProperties().get("sgsimulator.scenario") == null)
        System.getProperties().put("sgsimulator.scenario", "solarbyperson");

    page = "<!DOCTYPE html><html><head><link href=\"/sg/assets/sg.css\" />\n"
            + "<style></style><meta charset=\"utf-8\"><title>SG Charts</title></head><body>   \n"
            + " <H1>Screen panel</H1>"
            + "<script src=\"https://code.jquery.com/jquery-3.2.0.min.js\"></script>\n" + chartMetering
            + chartWeather + billing + ballance
            + "<div id='transformer-elements' style=\"text-align: center;\"/>"
            + "<script src=\"http://canvasjs.com/assets/script/canvasjs.min.js\"></script>\n"
            + "<script src=\"/sg/assets/sg.js\"></script>\n" + "<script  type=\"text/javascript\">\n"
            + "updateCounterListener(\"bill\",\"#bill\");    \n"
            + "updateCounterListener(\"powerdump\",\"#accumpower\");\n"
            + "updateListeners(\"generation\",charts.chart1,LASTGENERATED);\n"
            + "updateListeners(\"consumption\",charts.chart1,LASTCONSUMPTION);\n"
            + "updateListeners(\"demand\",charts.chart1,LASTDEMAND);\n"
            + "updateListeners(\"wind\",charts.chart2,WIND);\n"
            + "updateListeners(\"sun\",charts.chart2,SUN);\n" + "</script>\n" + "</body>\n" + "</html>\n";

    return page;

}

From source file:net.sf.sgsimulator.sgsrest.vertx.controllers.PageController.java

License:Open Source License

@GET("/panel")
public synchronized String getPanel(RoutingContext ctx) {
    SocketAddress remote = ctx.request().remoteAddress();
    JsonObject obj = new JsonObject().put("host", remote.host()).put("port", remote.port());
    // ctx.response().end(obj.encodePrettily());
    String host = obj.getString("host");

    if (panelPerKey.containsKey(host))
        return panelPerKey.get(host);
    counter = counter + 1;/*w  w  w.j a  v  a  2  s.c o  m*/
    String page = "Not working. Contact the administrator";

    if (System.getProperties().get("sgsimulator.scenario") == null)
        System.getProperties().put("sgsimulator.scenario", "solarbyperson");

    switch (System.getProperties().get("sgsimulator.scenario").toString().toLowerCase()) {
    case "fulloperational":

        String ptrans = " $.getJSON('/sg/query/transformer-names', function (data) {" + "var items = [];\n"
                + "console.log(data);\n" + "$.each(data.result, function (index, tName) {\n"
                + "    updateTransformers(tName);\n" + "});\n" + "});\n";

        /*{
        int id = 0;
        for (String transformer : gL.getTransformerNames()) {
           ptrans = ptrans + "<h1>" + transformer + "</h1>\n";
           for (ElementEMS generator : gL.getGeneratorsByTransformer(transformer)) {
              ptrans = ptrans + generateButtonCode(generator.getName(), generator.getMaxPower(), id);
              id = id + 1;
           }
           ;
        }
        }*/

        page = "<!DOCTYPE html><html><head><link href=\"/sg/assets/sg.css\" />\n"
                + "<style></style><meta charset=\"utf-8\"><title>SG Charts</title></head><body>   \n"
                + "<script src=\"https://code.jquery.com/jquery-3.2.0.min.js\"></script>\n" + chartMetering
                + chartWeather + ballance + "<H2>Assigned panels</h2>"
                + "<div id='transformer-elements' style=\"text-align: center;\"/>"
                + "<script src=\"http://canvasjs.com/assets/script/canvasjs.min.js\"></script>\n"
                + "<script src=\"/sg/assets/sg.js\"></script>\n" + "<script  type=\"text/javascript\">\n"
                + "updateCounterListener(\"bill\",\"#bill\");    \n"
                + "updateCounterListener(\"powerdump\",\"#accumpower\");\n"
                + "updateListeners(\"generation\",charts.chart1,LASTGENERATED);\n"
                + "updateListeners(\"consumption\",charts.chart1,LASTCONSUMPTION);\n"
                + "updateListeners(\"demand\",charts.chart1,LASTDEMAND);\n"
                + "updateListeners(\"wind\",charts.chart2,WIND);\n"
                + "updateListeners(\"sun\",charts.chart2,SUN);\n" + ptrans + "</script>\n" + "</body>\n"
                + "</html>\n";
        id = id + 1;

        break;
    case "centralized":
        // one 1 weather + 1 solar panel per person except the controller
        // controller has weather+metering+billing+ballance
        if (remaining.isEmpty()) {
            int id = 0;
            Vector<String> panels = new Vector<String>();
            remaining.put("panel", panels);
            for (String transformer : gL.getTransformerNames()) {
                for (ElementEMS generator : gL.getGeneratorsByTransformer(transformer)) {
                    panels.add(generator.getName());
                }
                ;
            }
            ;
            Vector<String> centrals = new Vector<String>();
            centrals.add("firstandonly");
            remaining.put("central", centrals);
            shake(panels); // make vector randomly organized
            shake(centrals); // make vector randomly organized
        }

        if (remaining.get("panel").size() == 0 && remaining.get("central").size() == 0) {
            page = "<h1>No more panels, sorry. Wait for the microgrid to be restarted</h1>";
        } else {
            if (remaining.get("panel").size() > 0) {
                String panel = remaining.get("panel").remove(0);
                int id = 0;
                String button = generateButtonCode("transformer-elements", panel,
                        Math.abs(this.gL.getElementByName(panel).getMaxPower() / 1000), id);
                page = "<!DOCTYPE html><html><head><link href=\"/sg/assets/sg.css\" />\n"
                        + "<style></style><meta charset=\"utf-8\"><title>SG Charts</title></head><body>   \n"
                        + "<H1>Solar Panel node :" + panel + " </H1>"
                        + "<script src=\"https://code.jquery.com/jquery-3.2.0.min.js\"></script>\n"
                        + chartWeather + "<div id='transformer-elements' style=\"text-align: center;\"/>"
                        + "<script src=\"http://canvasjs.com/assets/script/canvasjs.min.js\"></script>\n"
                        + "<script src=\"/sg/assets/sg.js\"></script>\n"
                        + "<script  type=\"text/javascript\">\n"
                        + "updateListeners(\"wind\",charts.chart2,WIND);\n"
                        + "updateListeners(\"sun\",charts.chart2,SUN);\n" + button + "</script>\n" + "</body>\n"
                        + "</html>\n";
            } else if (remaining.get("central").size() > 0) {
                page = "<!DOCTYPE html><html><head><link href=\"/sg/assets/sg.css\" />\n"
                        + "<style></style><meta charset=\"utf-8\"><title>SG Charts</title></head><body>   \n"
                        + "<H1>SCADA central node</H1>"
                        + "<script src=\"https://code.jquery.com/jquery-3.2.0.min.js\"></script>\n"
                        + chartMetering + chartWeather + ballance + billing
                        + "<script src=\"http://canvasjs.com/assets/script/canvasjs.min.js\"></script>\n"
                        + "<script src=\"/sg/assets/sg.js\"></script>\n"
                        + "<script  type=\"text/javascript\">\n"
                        + "updateCounterListener(\"bill\",\"#bill\");    \n"
                        + "updateCounterListener(\"powerdump\",\"#accumpower\");\n"
                        + "updateListeners(\"generation\",charts.chart1,LASTGENERATED);\n"
                        + "updateListeners(\"consumption\",charts.chart1,LASTCONSUMPTION);\n"
                        + "updateListeners(\"demand\",charts.chart1,LASTDEMAND);\n"
                        + "updateListeners(\"wind\",charts.chart2,WIND);\n"
                        + "updateListeners(\"sun\",charts.chart2,SUN);\n" + "</script>\n" + "</body>\n"
                        + "</html>\n";
                remaining.get("central").remove(0);
            }

        }
        break;

    case "fullsolarbyperson":
    default:
        if (available.isEmpty()) {
            for (String transformer : gL.getTransformerNames()) {
                for (ElementEMS generator : gL.getGeneratorsByTransformer(transformer)) {
                    available.put(generator.getName(), true);
                }
                ;
            }
        }
        if (available.values().contains(true)) {
            String found = "";
            for (String key : available.keySet()) {
                if (available.get(key)) {
                    found = key;
                }
            }
            if (found != "") {
                ptrans = generateButtonCode("transformer-elements", found,
                        this.gL.getElementByName(found).getMaxPower(), id);
                page = "<!DOCTYPE html><html><head><link href=\"/sg/assets/sg.css\" />\n"
                        + "<style></style><meta charset=\"utf-8\"><title>SG Charts</title></head><body>   \n"
                        + "<script src=\"https://code.jquery.com/jquery-3.2.0.min.js\"></script>\n"

                        + chartMetering + chartWeather + ballance + "<H1>Assigned panels</h1>"
                        + "<div id='transformer-elements'/>"
                        + "<script src=\"http://canvasjs.com/assets/script/canvasjs.min.js\"></script>\n"
                        + "<script src=\"/sg/assets/sg.js\"></script>\n"
                        + "<script  type=\"text/javascript\">\n"
                        + "updateCounterListener(\"bill\",\"#bill\");    \n"
                        + "updateCounterListener(\"powerdump\",\"#accumpower\");\n"
                        + "updateListeners(\"generation\",charts.chart1,LASTGENERATED);\n"
                        + "updateListeners(\"consumption\",charts.chart1,LASTCONSUMPTION);\n"
                        + "updateListeners(\"demand\",charts.chart1,LASTDEMAND);\n"
                        + "updateListeners(\"wind\",charts.chart2,WIND);\n"
                        + "updateListeners(\"sun\",charts.chart2,SUN);\n" + ptrans + "</script>\n" + "</body>\n"
                        + "</html>\n";
                id = id + 1;
            } else
                page = "All elements have been assigned. Try again later";
        }

    }
    panelPerKey.put(host, page);
    return page;

}

From source file:org.apache.servicecomb.transport.rest.vertx.accesslog.element.impl.LocalHostItem.java

License:Apache License

public static String getLocalAddress(AccessLogParam<RoutingContext> accessLogParam) {
    HttpServerRequest request = accessLogParam.getContextData().request();
    if (null == request) {
        return EMPTY_RESULT;
    }//from  w  w  w .j a va2 s  .  c  om

    SocketAddress localAddress = request.localAddress();
    if (null == localAddress) {
        return EMPTY_RESULT;
    }

    String localHost = localAddress.host();
    if (StringUtils.isEmpty(localHost)) {
        return EMPTY_RESULT;
    }
    return localHost;
}

From source file:org.apache.servicecomb.transport.rest.vertx.accesslog.element.impl.RemoteHostItem.java

License:Apache License

@Override
public String getFormattedItem(AccessLogParam<RoutingContext> accessLogParam) {
    HttpServerRequest request = accessLogParam.getContextData().request();
    if (null == request) {
        return EMPTY_RESULT;
    }/*from www  .  j av  a  2 s.  c  o  m*/

    SocketAddress remoteAddress = request.remoteAddress();
    if (null == remoteAddress) {
        return EMPTY_RESULT;
    }

    String remoteHost = remoteAddress.host();
    if (StringUtils.isEmpty(remoteHost)) {
        return EMPTY_RESULT;
    }
    return remoteHost;
}

From source file:org.wisdom.framework.vertx.RequestFromVertx.java

License:Apache License

/**
 * The request host./*from w  w  w  .j  a v a  2  s .  c  om*/
 */
@Override
public String host() {
    SocketAddress remote = request.remoteAddress();
    return remote.host();
}