diff options
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 5 | ||||
-rw-r--r-- | src/org/traccar/MainModule.java | 19 | ||||
-rw-r--r-- | src/org/traccar/WebDataHandler.java | 17 | ||||
-rw-r--r-- | test/org/traccar/WebDataHandlerTest.java | 10 |
4 files changed, 21 insertions, 30 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 517b92bbf..f24841a22 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -316,10 +316,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { } if (Context.getConfig().getBoolean("forward.enable")) { - pipeline.addLast(Main.getInjector().getInstance(WebDataHandler.Factory.class).create( - Context.getConfig().getString("forward.url"), - Context.getConfig().getString("forward.header"), - Context.getConfig().getBoolean("forward.json"))); + pipeline.addLast(Main.getInjector().getInstance(WebDataHandler.class)); } addHandlers( diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java index 6c66a90b8..19cad5237 100644 --- a/src/org/traccar/MainModule.java +++ b/src/org/traccar/MainModule.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2018 - 2019 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package org.traccar; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.inject.AbstractModule; import com.google.inject.Provides; -import com.google.inject.assistedinject.FactoryModuleBuilder; import org.traccar.database.IdentityManager; import javax.ws.rs.client.Client; @@ -26,23 +25,23 @@ import javax.ws.rs.client.Client; public class MainModule extends AbstractModule { @Provides - public static ObjectMapper getObjectMapper() { + public static ObjectMapper provideObjectMapper() { return Context.getObjectMapper(); } @Provides - public static IdentityManager getIdentityManager() { - return Context.getIdentityManager(); + public static Config provideConfig() { + return Context.getConfig(); } @Provides - public static Client getClient() { - return Context.getClient(); + public static IdentityManager provideIdentityManager() { + return Context.getIdentityManager(); } - @Override - protected void configure() { - install(new FactoryModuleBuilder().build(WebDataHandler.Factory.class)); + @Provides + public static Client provideClient() { + return Context.getClient(); } } diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java index 572252a22..e29e5a075 100644 --- a/src/org/traccar/WebDataHandler.java +++ b/src/org/traccar/WebDataHandler.java @@ -17,7 +17,6 @@ package org.traccar; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.inject.assistedinject.Assisted; import org.traccar.database.IdentityManager; import org.traccar.helper.Checksum; import org.traccar.model.Device; @@ -51,21 +50,15 @@ public class WebDataHandler extends BaseDataHandler { private final String header; private final boolean json; - public interface Factory { - WebDataHandler create( - @Assisted("url") String url, @Assisted("header") String header, boolean json); - } - @Inject public WebDataHandler( - IdentityManager identityManager, ObjectMapper objectMapper, Client client, - @Assisted("url") String url, @Assisted("header") String header, @Assisted boolean json) { + Config config, IdentityManager identityManager, ObjectMapper objectMapper, Client client) { this.identityManager = identityManager; this.objectMapper = objectMapper; this.client = client; - this.url = url; - this.header = header; - this.json = json; + this.url = config.getString("forward.url"); + this.header = config.getString("forward.header"); + this.json = config.getBoolean("forward.json"); } private static String formatSentence(Position position) { @@ -187,7 +180,7 @@ public class WebDataHandler extends BaseDataHandler { return position; } - protected Map<String, Object> prepareJsonPayload(Position position) { + private Map<String, Object> prepareJsonPayload(Position position) { Map<String, Object> data = new HashMap<>(); Device device = identityManager.getById(position.getDeviceId()); diff --git a/test/org/traccar/WebDataHandlerTest.java b/test/org/traccar/WebDataHandlerTest.java index 80e0d9a7f..1cdb08440 100644 --- a/test/org/traccar/WebDataHandlerTest.java +++ b/test/org/traccar/WebDataHandlerTest.java @@ -10,14 +10,16 @@ public class WebDataHandlerTest extends ProtocolTest { @Test public void testFormatRequest() throws Exception { - Position p = position("2016-01-01 01:02:03.000", true, 20, 30); + Config config = new Config(); + config.setString("forward.url", "http://localhost/?fixTime={fixTime}&gprmc={gprmc}&name={name}"); - WebDataHandler handler = new WebDataHandler( - Context.getIdentityManager(), null, null, "http://localhost/?fixTime={fixTime}&gprmc={gprmc}&name={name}", null, false); + Position position = position("2016-01-01 01:02:03.000", true, 20, 30); + + WebDataHandler handler = new WebDataHandler(config, Context.getIdentityManager(), null, null); assertEquals( "http://localhost/?fixTime=1451610123000&gprmc=$GPRMC,010203.000,A,2000.0000,N,03000.0000,E,0.00,0.00,010116,,*05&name=test", - handler.formatRequest(p)); + handler.formatRequest(position)); } |