-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added POST option to forward url #3755
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored code
Why are there two pull requests? Also, please address comment from the second thread. |
This one is the relevant PR. deleted the other one and fixed what you said, thanks. |
@@ -238,7 +238,9 @@ public ChannelPipeline getPipeline() { | |||
} | |||
|
|||
if (Context.getConfig().getBoolean("forward.enable")) { | |||
pipeline.addLast("webHandler", new WebDataHandler(Context.getConfig().getString("forward.url"))); | |||
final Boolean json = Context.getConfig().getBoolean("forward.json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can safely inline the variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its longer than 150 lines, Travis CI didn't accept it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can separate it into several lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I did
src/org/traccar/WebDataHandler.java
Outdated
@@ -29,12 +32,17 @@ | |||
import java.util.Locale; | |||
import java.util.TimeZone; | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra spaces like this.
src/org/traccar/WebDataHandler.java
Outdated
public class WebDataHandler extends BaseDataHandler { | ||
|
||
private final String url; | ||
private final Boolean json; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it a boolean class and not a primitive type?
src/org/traccar/WebDataHandler.java
Outdated
|
||
public WebDataHandler(String url) { | ||
public WebDataHandler(String url, Boolean json) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
@@ -12,7 +12,7 @@ public void testFormatRequest() throws Exception { | |||
|
|||
Position p = position("2016-01-01 01:02:03.000", true, 20, 30); | |||
|
|||
WebDataHandler handler = new WebDataHandler("http://localhost/?fixTime={fixTime}&gprmc={gprmc}&name={name}"); | |||
WebDataHandler handler = new WebDataHandler("http://localhost/?fixTime={fixTime}&gprmc={gprmc}&name={name}", false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit test for JSON as well.
src/org/traccar/WebDataHandler.java
Outdated
return position; | ||
} | ||
|
||
protected String getContentType() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a separate method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you want me to get the content type from 'JsonTypeEventForwarder' ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does JsonTypeEventForwarder
have to do with this? It has nothing to do with events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What did you mean by separate method ? maybe I dont get it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have a method with one line of code? It doesn't make sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
understood. Fixed and pushed
src/org/traccar/WebDataHandler.java
Outdated
return "application/json; charset=utf-8"; | ||
} | ||
|
||
protected void setContent(Position position, AsyncHttpClient.BoundRequestBuilder requestBuilder) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we need a separate method because I don't have Event object in WebDataHandler, so that method is edited accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what events have to do with this functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What did you mean by separate method ? maybe I dont get it.
You haven't fixed one of the comments (about removing variables). Also, why is test case called |
Thanks for the comment, Fixed the test's name to match previous syntax, plus fixed the inlined variables. |
@Abyss777, can you please take a quick look and see if you can think of any issues or problems. |
What is the reason of sending Device object with every position? |
@Abyss777 We got a request from a client that matches the data we get from the position, and maybe it will be helpful for others. Nevertheless, there is a flag to activate it or not. |
I think it makes sense so that third party app has access to device model as well, if it needs. Also, I imagine most of the time this will be used on a same machine or at least local network, so some extra traffic shouldn't be a problem. Also, it's consistent with event forwarding. |
src/org/traccar/WebDataHandler.java
Outdated
data.put(KEY_POSITION, position); | ||
} | ||
|
||
if (position.getDeviceId() != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check if not necessary and next check device for null be enough .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Abyss777, should we remove same checks from EventForwarder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Abyss777 Again, the check of the position is not necessary ? just leave the check device for null ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's safe to assume that there is a device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So remove both checks ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm...I believe yes we can remove.
Map.get(0) will return null
- "the value to which the specified key is mapped, or null if this map contains no mapping for the key"
OK. Then one small comment. |
@Abyss777 remove the checks. |
What about device? Why are we removing it? |
@NateZ7 |
@Abyss777 Got ya ! did the changes |
Merged it, thanks. |
@tananaev Please add the |
Updated. |
Hi Anton,
As we discussed, I added the forward.json to determine POST or GET in forward url.