-
Notifications
You must be signed in to change notification settings - Fork 40
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
Upgrade Jackson 1.x to Jackson 2.x #22
Conversation
Travis appears to be failing because Travis has been set-up for this repository but the travis branch has yet to be merged |
This PR is awesome! We should get this out asap! I'm hving trouble because Jackson 1.x is too old and doesn't get things done well. Need Jackson 2.x! |
@@ -78,6 +81,8 @@ | |||
|
|||
public static final GenericType<List<Object>> MAP_OBJECT_TYPE = new GenericType<List<Object>>() {}; | |||
|
|||
private final ObjectMapper mapper; |
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.
Minor suggestion: since ObjectMapper is stateless, you can maintain a single ObjectMapper object as singleton across the code base.
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.
Not critical. Can push it off to next release
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.
Agreed, but since this isn't a new field, I was considering this to be out of scope; however, I did add a new constructor signature (line 188) so that the application may provide the library with its singleton ObjectMapper
@@ -76,6 +78,7 @@ public static final Soda2Producer newProducerWithRequestId(final String url, Str | |||
public Soda2Producer(HttpLowLevel httpLowLevel) | |||
{ | |||
super(httpLowLevel); | |||
factory = new JsonFactory(); |
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.
This class needs the MappingJsonFactory. You will need to either get that from ObjectMapper or explicitly create one. You can see test failures in Soda2ProducerTest if you just use the plain JsonFactory.
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.
Again, I need some help running the tests. When I try to run them, I get a whole lot of these failures in my terminal
[info] Test com.socrata.DatesTest.testFloatingDateSoql started
[error] Test com.socrata.DatesTest.testFloatingDateSoql failed: Authentication failed: Invalid username or password
[error] at com.socrata.api.HttpLowLevel.processErrors(HttpLowLevel.java:687)
[error] at com.socrata.api.HttpLowLevel.queryRaw(HttpLowLevel.java:448)
[error] at com.socrata.api.Soda2Base.query(Soda2Base.java:62)
[error] at com.socrata.api.Soda2Consumer.query(Soda2Consumer.java:111)
[error] at com.socrata.DatesTest.testFloatingDateSoql(DatesTest.java:52)
I didn't see anything in the README about how to avoid this. There are credentials in TestConfig.properties, but they don't appear to be working
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.
For Soda2ProducerTest, you can supply your own username, password and token in TestConfig.properties.
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.
OK, I guess the standard procedure is to edit this file with my credentials, but do not check those changes in
I tried this and while more tests do pass, some now report authorization problems
[info] Test com.socrata.api.SodaImporterTest.testCreatingFileDataset started
[error] Test com.socrata.api.SodaImporterTest.testCreatingFileDataset failed: You aren't allowed to create a dataset within this domain.
[error] at com.socrata.api.HttpLowLevel.processErrors(HttpLowLevel.java:689)
[error] at com.socrata.api.HttpLowLevel.postFileRaw(HttpLowLevel.java:532)
[error] at com.socrata.api.SodaImporter$4.issueRequest(SodaImporter.java:570)
[error] at com.socrata.api.SodaImporter.importNonDataFile(SodaImporter.java:590)
[error] at com.socrata.api.SodaImporterTest.testCreatingFileDataset(SodaImporterTest.java:425)
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.
Also, what version of Java does this API target?
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.
@gilday Did getting set up on sandbox unblock you? Anything more I can do to help?
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 haven't had a chance to test it yet. i'll let you know this week
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.
still having trouble with these tests. For example, the ExamplesTest#readmeProducerExamples uses a hardcoded username and password and the test fails with "Too many login attempts for that login. Account temporarily disabled."
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.
Could you push the change? I can test the change.
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.
pushed 5d70349
This is a bit of a struggle because some of the tests are also broken on master so I'm not sure what tests are broken because of my changes are which are just broken. For example, DatesTest#testDateCrud
@@ -355,16 +352,9 @@ public ClientResponse issueRequest() throws LongRunningQueryException, SodaError | |||
|
|||
try { | |||
final ClientResponse response = requester.issueRequest(); | |||
return mapper.readValue(response.getEntity(InputStream.class), AssetResponse.class); | |||
//return response.getEntity(AssetResponse.class); | |||
return response.getEntity(AssetResponse.class); |
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.
response.getEntity doesn't work with creating assets /api/assets. Keep the original mapper.readValue and error handlers.
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 cannot find any documentation for the "assets" resource of the Import API. Does response.getEntity
not work because this resource does not accept requests for application/json
so the MessageBodyReader
will not be triggered?
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.
jackson looks for json content-type in getEntity. But the actual content type returned from the server is text/plain despite that it is json. Using readValue from input stream get around this problem.
@@ -208,14 +210,15 @@ public void testDelete() throws LongRunningQueryException, SodaError, Interrupte | |||
@Test | |||
public void testParsingUpsertResults() throws IOException | |||
{ | |||
final Soda2Producer producer = new Soda2Producer(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.
Cannot be null. Need HttpLowLevel.
@@ -245,22 +248,23 @@ public void testParsingUpsertResults() throws IOException | |||
@Test | |||
public void testParsingSodaServerUpsertResults() throws IOException | |||
{ | |||
final Soda2Producer producer = new Soda2Producer(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.
Cannot be null. Need HttpLowLevel.
@@ -279,22 +283,23 @@ public void testParsingSodaServerUpsertResults() throws IOException | |||
@Test | |||
public void testParsingOldSodaServerUpsertResults() throws IOException | |||
{ | |||
final Soda2Producer producer = new Soda2Producer(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.
Cannot be null. Need HttpLowLevel.
|
||
@BeforeClass | ||
public static void setupClass() { | ||
// Make sure the ObjectMapper is setup correctly | ||
final JacksonObjectMapperProvider provider = new JacksonObjectMapperProvider(); | ||
final JacksonObjectMapperProvider provider = new JacksonObjectMapperProvider(mapper); |
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.
This mapper can be null and is null when I run TestJacksonObjectMapperProvider.
* adding missing HttpLowLevel to Soda2ProducerTest * initialize ObjectMapper for TestJacksonObjectMapperProvider * provide a Jersey client filter for replacing response headers 'Content-Type: text/plain' with 'Content-Type: application/json' for the "assets" API so that it will un-marshall the AssetResponse type correctly
Tests that fail on master
com.socrata.ExamplesTest fails because it uses hard-coded credentials. I changed it to extend TestBase and use the user provided credentials and it passes As for the other 3 tests, I do not know why they fail on both master and the gilday/21-upgrade-jackson branch |
@@ -18,7 +18,6 @@ | |||
import junit.framework.TestCase; |
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.
Change from "new File" to "Resources.file" in line #37-43
|
||
@Test | ||
public void testMapperProvider() { | ||
private static final Date base = new Date(112, 5, 20, 7, 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.
new Date is deprecated. Replace with Calendar.set
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, I moved this instantiation from elsewhere in the file as opposed to introducing it; therefore, can we consider this change out of scope?
There are a lot more instances of new Date(...)
in the source and I expect you would want to address these at the same time as part of a comprehensive upgrade of the Date / Time system used by the library. For instance, you may consider replacing Joda Time with the new Java 8 java.time package. Java 7 is very old at this point, but if that's still important, you could consider the 310 back port
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.
Fair enough
} | ||
return response; | ||
} | ||
} |
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.
Can we switch back to object mapper readValue from inputstream in SodaDdl.addAsset instead of a request filter?
} | ||
return response; | ||
} | ||
} |
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 prefer going back to object mapper readValue to adding a new AssetRequestFilter class. We can merge the PR once you make that change.
unmarshal the response from add asset instead of using a JAX-RS filter
Done |
#21 Upgrade Jackson
I was unable to run the integration tests due to problems with the API rate limiter. Is this a known issue?