Skip to content
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

Merged
merged 11 commits into from
Feb 7, 2018
Merged

added POST option to forward url #3755

merged 11 commits into from
Feb 7, 2018

Conversation

NateZ7
Copy link
Contributor

@NateZ7 NateZ7 commented Feb 4, 2018

Hi Anton,

As we discussed, I added the forward.json to determine POST or GET in forward url.

Copy link
Contributor Author

@NateZ7 NateZ7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored code

@tananaev
Copy link
Member

tananaev commented Feb 4, 2018

Why are there two pull requests? Also, please address comment from the second thread.

@NateZ7
Copy link
Contributor Author

NateZ7 commented Feb 5, 2018

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");
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

@@ -29,12 +32,17 @@
import java.util.Locale;
import java.util.TimeZone;


Copy link
Member

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.

public class WebDataHandler extends BaseDataHandler {

private final String url;
private final Boolean json;
Copy link
Member

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?


public WebDataHandler(String url) {
public WebDataHandler(String url, Boolean json) {
Copy link
Member

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);
Copy link
Member

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.

return position;
}

protected String getContentType() {
Copy link
Member

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?

Copy link
Contributor Author

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' ??

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood. Fixed and pushed

return "application/json; charset=utf-8";
}

protected void setContent(Position position, AsyncHttpClient.BoundRequestBuilder requestBuilder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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.

@tananaev
Copy link
Member

tananaev commented Feb 6, 2018

You haven't fixed one of the comments (about removing variables). Also, why is test case called testBuilderRequest?

@NateZ7
Copy link
Contributor Author

NateZ7 commented Feb 7, 2018

Thanks for the comment, Fixed the test's name to match previous syntax, plus fixed the inlined variables.

@tananaev
Copy link
Member

tananaev commented Feb 7, 2018

@Abyss777, can you please take a quick look and see if you can think of any issues or problems.

@Abyss777
Copy link
Collaborator

Abyss777 commented Feb 7, 2018

What is the reason of sending Device object with every position?

@NateZ7
Copy link
Contributor Author

NateZ7 commented Feb 7, 2018

@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.

@tananaev
Copy link
Member

tananaev commented Feb 7, 2018

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.

data.put(KEY_POSITION, position);
}

if (position.getDeviceId() != 0) {
Copy link
Collaborator

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 .

Copy link
Member

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?

Copy link
Contributor Author

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 ?

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So remove both checks ?

Copy link
Collaborator

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"

@Abyss777
Copy link
Collaborator

Abyss777 commented Feb 7, 2018

OK. Then one small comment.

@NateZ7
Copy link
Contributor Author

NateZ7 commented Feb 7, 2018

@Abyss777 remove the checks.

@tananaev
Copy link
Member

tananaev commented Feb 7, 2018

What about device? Why are we removing it?

@Abyss777
Copy link
Collaborator

Abyss777 commented Feb 7, 2018

@NateZ7
You need remove checks id for 0, but leave checks objects for null

@NateZ7
Copy link
Contributor Author

NateZ7 commented Feb 7, 2018

@Abyss777 Got ya ! did the changes

@tananaev tananaev merged commit 96e45b5 into traccar:master Feb 7, 2018
@tananaev
Copy link
Member

tananaev commented Feb 7, 2018

Merged it, thanks.

@slobglob
Copy link

slobglob commented Apr 7, 2018

@tananaev Please add the forward.json option to https://www.traccar.org/configuration-file/
Thank you.

@tananaev
Copy link
Member

tananaev commented Apr 7, 2018

Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants