gberche / cfrouter-java

Java Client for the CloudFoundry HTTP router
1 stars 2 forks source link

parseRouteDumpIntoDtos() is broken for current GoRouter Version #1

Open stozk opened 8 years ago

stozk commented 8 years ago

Hi,

just wanted to note, that the latest GoRouter Version has some additional Info in hostPort Map, which causes an exception when it's trying to map the HostAndPort.fromString() data.

This fixes it:

public List<Route> parseRouteDumpIntoDtos(String json) throws IOException {
    List<Route> parsedRoutes = new ArrayList<Route>();
    ObjectMapper mapper = new ObjectMapper();
    Map<String,List<Map<String, String>>> routes = mapper.readValue(json, Map.class);
    for (Map.Entry<String, List<Map<String, String>>> entry : routes.entrySet()) {
        String vHost = entry.getKey();
        List<Map<String, String>> hostPorts = entry.getValue();       
        for (Map<String, String> hostPort : hostPorts) {            
            HostAndPort hp = HostAndPort.fromString(hostPort.get("address")).withDefaultPort(80);
            Route r = new Route(hp.getHostText(), hp.getPort(), new String[]{vHost});
            parsedRoutes.add(r);
        }
    }
    return parsedRoutes;
}

BR Daniel

gberche-orange commented 8 years ago

Hi Daniel,

Thanks for your note.

It worth noting that we don't internally use the gberche/cfrouter-java repo. The most recent version is rather https://github.com/Orange-OpenSource/cfrouter-java/ which has few more commits. This was used as part of https://github.com/Orange-OpenSource/elpaaso-core but which is not actively being worked on currently.

You might want to consider instead the router REST API https://github.com/cloudfoundry-incubator/routing-api#curl-examples as an alternative to the router NATS messages. See related specs at https://github.com/cloudfoundry-community/cf-docs-contrib/wiki/Design-Documents#routing

I'd be curious to learn more about your use-cases.

stozk commented 8 years ago

Thanks I'll look into that.

I'm building a platform-tool (Java) to manage docker container based services and gorouter seems suitable to do the routing and this java client seems to work great to publish the routes to the router.

For now... I have to test scalability and maybe will have to build a cutom tool at some point, but for a POC and smaller scale prototype it seems perfect.

BR Daniel