Skip to content

Commit

Permalink
XML handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Apr 12, 2017
1 parent d610a17 commit 8362b50
Show file tree
Hide file tree
Showing 23 changed files with 961 additions and 426 deletions.
2 changes: 1 addition & 1 deletion conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<logger name="io.netty" level="ERROR" />
<logger name="io.netty.handler" level="ERROR" />

<logger name="com.wurrly.server.swagger" level="INFO" />
<logger name="com.wurrly.server.swagger" level="DEBUG" />

<logger name="com.relayrides" level="ERROR" />
<logger name="org.apache.activemq" level="ERROR" />
Expand Down
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
<groupId>org.msgpack</groupId>
<artifactId>jackson-dataformat-msgpack</artifactId>
<version>0.8.12</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>[2.8.8,)</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
Expand Down Expand Up @@ -236,5 +241,11 @@
<artifactId>graphql-java</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>io.github.lukehutch</groupId>
<artifactId>fast-classpath-scanner</artifactId>
<version>LATEST</version>
</dependency>

</dependencies>
</project>
7 changes: 6 additions & 1 deletion src/main/java/com/wurrly/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.wurrly.server.endpoints.EndpointInfo;
import com.wurrly.server.handlers.HandlerGenerator;
import com.wurrly.server.handlers.benchmark.BenchmarkHandlers;
import com.wurrly.services.AssetsService;
import com.wurrly.services.SwaggerService;

import io.undertow.Undertow;
Expand Down Expand Up @@ -93,7 +94,9 @@ public void start()



Set<Service> services = registeredServices.stream().map( sc -> injector.getInstance(sc)).collect(Collectors.toSet());
Set<Service> services = registeredServices.stream()
.map( sc -> injector.getInstance(sc))
.collect(Collectors.toSet());

this.serviceManager = new ServiceManager(services);

Expand Down Expand Up @@ -214,6 +217,8 @@ public static void main(String[] args)

app.useService(SwaggerService.class);

app.useService(AssetsService.class);

app.useController(Users.class);

app.start();
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/wurrly/controllers/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
Expand Down Expand Up @@ -179,10 +181,11 @@ public ServerResponse createUser( final ServerRequest serverRequest, @QueryPara

@PUT
@Path("/username")
@Consumes(("application/json"))
@Consumes("application/json,application/xml")
@Produces("application/json,application/xml")
// @ApiImplicitParams({ @ApiImplicitParam(dataType = "com.wurrly.models.User", name = "user", paramType = "body", required = false, allowMultiple = false) })
@ApiOperation(value = "Update a user's name", httpMethod = "PUT", response = User.class)
public ServerResponse updateUsername(@ApiParam(hidden=true)final ServerRequest serverRequest, @QueryParam("context") Optional<String> context, final User user )
public CompletableFuture<ServerResponse> updateUsername(@ApiParam(hidden=true)final ServerRequest serverRequest, @QueryParam("context") Optional<String> context, final User user )
{
//
log.debug("esIndexName: " + esIndexName);
Expand All @@ -191,7 +194,7 @@ public ServerResponse updateUsername(@ApiParam(hidden=true)final ServerRequest s
log.debug("file: " + user);


return response().entity(Any.wrap(user));
return CompletableFuture.completedFuture(response().entity(user));

}

Expand Down
20 changes: 7 additions & 13 deletions src/main/java/com/wurrly/modules/RoutingModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
Expand All @@ -21,7 +22,7 @@

import io.undertow.predicate.TruePredicate;
import io.undertow.server.DefaultResponseListener;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.HttpHandler;
import io.undertow.server.RoutingHandler;
import io.undertow.server.handlers.resource.FileResourceManager;
import io.undertow.server.handlers.resource.ResourceHandler;
Expand Down Expand Up @@ -57,24 +58,15 @@ protected void configure()

RoutingHandler router = new RoutingHandler()
.setFallbackHandler(BaseHandlers::notFoundHandler);

final String assetsPath = config.getString("assets.path");
final String assetsDirectoryName = config.getString("assets.dir") ;
final Integer assetsCacheTime = config.getInt("assets.cache.time");

final FileResourceManager fileResourceManager = new FileResourceManager(Paths.get(assetsDirectoryName).toFile());


this.bind(XmlMapper.class).toInstance(new XmlMapper());

router.add(Methods.GET, assetsPath + "/*", io.undertow.Handlers.rewrite("regex['" + assetsPath + "/(.*)']", "/$1", getClass().getClassLoader(), new ResourceHandler(fileResourceManager)
.setCachable(TruePredicate.instance())
.setCacheTime(assetsCacheTime)
));


this.bind(RoutingHandler.class).toInstance(router);

this.bind(RoutingModule.class).toInstance(this);


try
{
String defaultResponseListenerClassName = config.getString("application.defaultResponseListener");
Expand All @@ -84,6 +76,8 @@ protected void configure()
{
log.error(e.getMessage(),e);
}



this.bind(new TypeLiteral<Set<Class<?>>>() {}).annotatedWith(Names.named("registeredControllers")).toInstance(registeredControllers);
this.bind(new TypeLiteral<Set<EndpointInfo>>() {}).annotatedWith(Names.named("registeredEndpoints")).toInstance(registeredEndpoints);
Expand Down
Loading

0 comments on commit 8362b50

Please sign in to comment.