Skip to content

Commit d51b37c

Browse files
committed
Remove QueryResource's ObjectMapper::copy() in favor of using the injected ObjectMapper directly
* Workaround for FasterXML/jackson-databind#696
1 parent c5e99bf commit d51b37c

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

server/src/main/java/io/druid/server/QueryResource.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package io.druid.server;
1919

20-
import com.fasterxml.jackson.core.JsonGenerator;
2120
import com.fasterxml.jackson.databind.ObjectMapper;
2221
import com.fasterxml.jackson.databind.ObjectWriter;
2322
import com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes;
@@ -89,12 +88,8 @@ public QueryResource(
8988
)
9089
{
9190
this.config = config;
92-
this.jsonMapper = jsonMapper.copy();
93-
this.jsonMapper.getFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
94-
95-
this.smileMapper = smileMapper.copy();
96-
this.smileMapper.getFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
97-
91+
this.jsonMapper = jsonMapper;
92+
this.smileMapper = smileMapper;
9893
this.texasRanger = texasRanger;
9994
this.emitter = emitter;
10095
this.requestLogger = requestLogger;
@@ -125,7 +120,8 @@ public Response doPost(
125120
String queryId = null;
126121

127122
final String reqContentType = req.getContentType();
128-
final boolean isSmile = SmileMediaTypes.APPLICATION_JACKSON_SMILE.equals(reqContentType) || APPLICATION_SMILE.equals(reqContentType);
123+
final boolean isSmile = SmileMediaTypes.APPLICATION_JACKSON_SMILE.equals(reqContentType)
124+
|| APPLICATION_SMILE.equals(reqContentType);
129125
final String contentType = isSmile ? SmileMediaTypes.APPLICATION_JACKSON_SMILE : MediaType.APPLICATION_JSON;
130126

131127
ObjectMapper objectMapper = isSmile ? smileMapper : jsonMapper;
@@ -210,7 +206,7 @@ public void write(OutputStream outputStream) throws IOException, WebApplicationE
210206
}
211207
},
212208
contentType
213-
)
209+
)
214210
.header("X-Druid-Query-Id", queryId)
215211
.header("X-Druid-Response-Context", jsonMapper.writeValueAsString(responseContext))
216212
.build();

server/src/test/java/io/druid/server/QueryResourceTest.java

+25-7
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@
5050
public class QueryResourceTest
5151
{
5252
private static final ObjectMapper jsonMapper = new DefaultObjectMapper();
53-
public static final ServerConfig serverConfig = new ServerConfig(){
53+
public static final ServerConfig serverConfig = new ServerConfig()
54+
{
5455
@Override
55-
public int getNumThreads(){
56+
public int getNumThreads()
57+
{
5658
return 1;
5759
}
60+
5861
@Override
59-
public Period getMaxIdleTime(){
62+
public Period getMaxIdleTime()
63+
{
6064
return Period.seconds(1);
6165
}
6266
};
@@ -90,17 +94,21 @@ public <T> QueryRunner<T> getQueryRunnerForSegments(
9094
};
9195

9296
private static final ServiceEmitter noopServiceEmitter = new NoopServiceEmitter();
97+
9398
@BeforeClass
94-
public static void staticSetup(){
99+
public static void staticSetup()
100+
{
95101
com.metamx.emitter.EmittingLogger.registerEmitter(noopServiceEmitter);
96102
}
103+
97104
@Before
98105
public void setup()
99106
{
100107
EasyMock.expect(testServletRequest.getContentType()).andReturn(MediaType.APPLICATION_JSON);
101108
EasyMock.expect(testServletRequest.getRemoteAddr()).andReturn("localhost").anyTimes();
102109
EasyMock.replay(testServletRequest);
103110
}
111+
104112
private static final String simpleTimeSeriesQuery = "{\n"
105113
+ " \"queryType\": \"timeseries\",\n"
106114
+ " \"dataSource\": \"mmx_metrics\",\n"
@@ -115,6 +123,7 @@ public void setup()
115123
+ " }\n"
116124
+ " ]\n"
117125
+ "}";
126+
118127
@Test
119128
public void testGoodQuery() throws IOException
120129
{
@@ -126,10 +135,15 @@ public void testGoodQuery() throws IOException
126135
new NoopServiceEmitter(),
127136
new NoopRequestLogger(),
128137
new QueryManager()
129-
);
130-
Response respone = queryResource.doPost(new ByteArrayInputStream(simpleTimeSeriesQuery.getBytes("UTF-8")), null /*pretty*/, testServletRequest);
138+
);
139+
Response respone = queryResource.doPost(
140+
new ByteArrayInputStream(simpleTimeSeriesQuery.getBytes("UTF-8")),
141+
null /*pretty*/,
142+
testServletRequest
143+
);
131144
Assert.assertNotNull(respone);
132145
}
146+
133147
@Test
134148
public void testBadQuery() throws IOException
135149
{
@@ -143,7 +157,11 @@ public void testBadQuery() throws IOException
143157
new NoopRequestLogger(),
144158
new QueryManager()
145159
);
146-
Response respone = queryResource.doPost(new ByteArrayInputStream("Meka Leka Hi Meka Hiney Ho".getBytes("UTF-8")), null /*pretty*/, testServletRequest);
160+
Response respone = queryResource.doPost(
161+
new ByteArrayInputStream("Meka Leka Hi Meka Hiney Ho".getBytes("UTF-8")),
162+
null /*pretty*/,
163+
testServletRequest
164+
);
147165
Assert.assertNotNull(respone);
148166
Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), respone.getStatus());
149167
}

0 commit comments

Comments
 (0)