Skip to content

Commit 3764651

Browse files
committed
Polish
1 parent d9029ef commit 3764651

File tree

8 files changed

+71
-111
lines changed

8 files changed

+71
-111
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,9 @@ public void path() {
115115
private void resolveApplicationPath() {
116116
if (StringUtils.hasLength(this.jersey.getApplicationPath())) {
117117
this.path = parseApplicationPath(this.jersey.getApplicationPath());
118-
}
119-
else {
120-
this.path = findApplicationPath(AnnotationUtils.findAnnotation(
121-
this.config.getApplication().getClass(), ApplicationPath.class));
118+
} else {
119+
this.path = findApplicationPath(
120+
AnnotationUtils.findAnnotation(this.config.getApplication().getClass(), ApplicationPath.class));
122121
}
123122
}
124123

@@ -149,8 +148,7 @@ public FilterRegistrationBean jerseyFilterRegistration() {
149148
registration.setFilter(new ServletContainer(this.config));
150149
registration.setUrlPatterns(Arrays.asList(this.path));
151150
registration.setOrder(this.jersey.getFilter().getOrder());
152-
registration.addInitParameter(ServletProperties.FILTER_CONTEXT_PATH,
153-
stripPattern(this.path));
151+
registration.addInitParameter(ServletProperties.FILTER_CONTEXT_PATH, stripPattern(this.path));
154152
addInitParameters(registration);
155153
registration.setName("jerseyFilter");
156154
registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
@@ -168,8 +166,8 @@ private String stripPattern(String path) {
168166
@ConditionalOnMissingBean(name = "jerseyServletRegistration")
169167
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "servlet", matchIfMissing = true)
170168
public ServletRegistrationBean jerseyServletRegistration() {
171-
ServletRegistrationBean registration = new ServletRegistrationBean(
172-
new ServletContainer(this.config), this.path);
169+
ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(this.config),
170+
this.path);
173171
addInitParameters(registration);
174172
registration.setName(getServletRegistrationName());
175173
registration.setLoadOnStartup(this.jersey.getServlet().getLoadOnStartup());
@@ -204,23 +202,18 @@ private static String parseApplicationPath(String applicationPath) {
204202
@Override
205203
public void setServletContext(ServletContext servletContext) {
206204
String servletRegistrationName = getServletRegistrationName();
207-
ServletRegistration registration = servletContext
208-
.getServletRegistration(servletRegistrationName);
205+
ServletRegistration registration = servletContext.getServletRegistration(servletRegistrationName);
209206
if (registration != null) {
210207
if (logger.isInfoEnabled()) {
211-
logger.info("Configuring existing registration for Jersey servlet '"
212-
+ servletRegistrationName + "'");
208+
logger.info("Configuring existing registration for Jersey servlet '" + servletRegistrationName + "'");
213209
}
214210
registration.setInitParameters(this.jersey.getInit());
215-
registration.setInitParameter(
216-
CommonProperties.METAINF_SERVICES_LOOKUP_DISABLE,
217-
Boolean.TRUE.toString());
211+
registration.setInitParameter(CommonProperties.METAINF_SERVICES_LOOKUP_DISABLE, Boolean.TRUE.toString());
218212
}
219213
}
220214

221215
@Order(Ordered.HIGHEST_PRECEDENCE)
222-
public static final class JerseyWebApplicationInitializer
223-
implements WebApplicationInitializer {
216+
public static final class JerseyWebApplicationInitializer implements WebApplicationInitializer {
224217

225218
@Override
226219
public void onStartup(ServletContext servletContext) throws ServletException {
@@ -239,22 +232,19 @@ static class JacksonResourceConfigCustomizer {
239232
private static final String JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME = "com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector";
240233

241234
@Bean
242-
public ResourceConfigCustomizer resourceConfigCustomizer(
243-
final ObjectMapper objectMapper) {
235+
public ResourceConfigCustomizer resourceConfigCustomizer(final ObjectMapper objectMapper) {
244236
addJaxbAnnotationIntrospectorIfPresent(objectMapper);
245237
return new ResourceConfigCustomizer() {
246238
@Override
247239
public void customize(ResourceConfig config) {
248240
config.register(JacksonFeature.class);
249-
config.register(new ObjectMapperContextResolver(objectMapper),
250-
ContextResolver.class);
241+
config.register(new ObjectMapperContextResolver(objectMapper), ContextResolver.class);
251242
}
252243
};
253244
}
254245

255246
private void addJaxbAnnotationIntrospectorIfPresent(ObjectMapper objectMapper) {
256-
if (ClassUtils.isPresent(JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME,
257-
getClass().getClassLoader())) {
247+
if (ClassUtils.isPresent(JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME, getClass().getClassLoader())) {
258248
new ObjectMapperCustomizer().addJaxbAnnotationIntrospector(objectMapper);
259249
}
260250
}
@@ -265,22 +255,18 @@ private void addJaxbAnnotationIntrospector(ObjectMapper objectMapper) {
265255
JaxbAnnotationIntrospector jaxbAnnotationIntrospector = new JaxbAnnotationIntrospector(
266256
objectMapper.getTypeFactory());
267257
objectMapper.setAnnotationIntrospectors(
268-
createPair(objectMapper.getSerializationConfig(),
269-
jaxbAnnotationIntrospector),
270-
createPair(objectMapper.getDeserializationConfig(),
271-
jaxbAnnotationIntrospector));
258+
createPair(objectMapper.getSerializationConfig(), jaxbAnnotationIntrospector),
259+
createPair(objectMapper.getDeserializationConfig(), jaxbAnnotationIntrospector));
272260
}
273261

274262
private AnnotationIntrospector createPair(MapperConfig<?> config,
275263
JaxbAnnotationIntrospector jaxbAnnotationIntrospector) {
276-
return AnnotationIntrospector.pair(config.getAnnotationIntrospector(),
277-
jaxbAnnotationIntrospector);
264+
return AnnotationIntrospector.pair(config.getAnnotationIntrospector(), jaxbAnnotationIntrospector);
278265
}
279266

280267
}
281268

282-
private static final class ObjectMapperContextResolver
283-
implements ContextResolver<ObjectMapper> {
269+
private static final class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> {
284270

285271
private final ObjectMapper objectMapper;
286272

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java

Lines changed: 44 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public class KafkaProperties {
5353
* Comma-delimited list of host:port pairs to use for establishing the initial
5454
* connection to the Kafka cluster.
5555
*/
56-
private List<String> bootstrapServers = new ArrayList<String>(
57-
Collections.singletonList("localhost:9092"));
56+
private List<String> bootstrapServers = new ArrayList<String>(Collections.singletonList("localhost:9092"));
5857

5958
/**
6059
* Id to pass to the server when making requests; used for server-side logging.
@@ -123,8 +122,7 @@ public Template getTemplate() {
123122
private Map<String, Object> buildCommonProperties() {
124123
Map<String, Object> properties = new HashMap<String, Object>();
125124
if (this.bootstrapServers != null) {
126-
properties.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG,
127-
this.bootstrapServers);
125+
properties.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, this.bootstrapServers);
128126
}
129127
if (this.clientId != null) {
130128
properties.put(CommonClientConfigs.CLIENT_ID_CONFIG, this.clientId);
@@ -133,20 +131,16 @@ private Map<String, Object> buildCommonProperties() {
133131
properties.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, this.ssl.getKeyPassword());
134132
}
135133
if (this.ssl.getKeystoreLocation() != null) {
136-
properties.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG,
137-
resourceToPath(this.ssl.getKeystoreLocation()));
134+
properties.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, resourceToPath(this.ssl.getKeystoreLocation()));
138135
}
139136
if (this.ssl.getKeystorePassword() != null) {
140-
properties.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG,
141-
this.ssl.getKeystorePassword());
137+
properties.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, this.ssl.getKeystorePassword());
142138
}
143139
if (this.ssl.getTruststoreLocation() != null) {
144-
properties.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG,
145-
resourceToPath(this.ssl.getTruststoreLocation()));
140+
properties.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, resourceToPath(this.ssl.getTruststoreLocation()));
146141
}
147142
if (this.ssl.getTruststorePassword() != null) {
148-
properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG,
149-
this.ssl.getTruststorePassword());
143+
properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, this.ssl.getTruststorePassword());
150144
}
151145
if (!CollectionUtils.isEmpty(this.properties)) {
152146
properties.putAll(this.properties);
@@ -159,8 +153,9 @@ private Map<String, Object> buildCommonProperties() {
159153
* <p>
160154
* This allows you to add additional properties, if necessary, and override the
161155
* default kafkaConsumerFactory bean.
162-
* @return the consumer properties initialized with the customizations defined on this
163-
* instance
156+
*
157+
* @return the consumer properties initialized with the customizations defined
158+
* on this instance
164159
*/
165160
public Map<String, Object> buildConsumerProperties() {
166161
Map<String, Object> properties = buildCommonProperties();
@@ -173,8 +168,9 @@ public Map<String, Object> buildConsumerProperties() {
173168
* <p>
174169
* This allows you to add additional properties, if necessary, and override the
175170
* default kafkaProducerFactory bean.
176-
* @return the producer properties initialized with the customizations defined on this
177-
* instance
171+
*
172+
* @return the producer properties initialized with the customizations defined
173+
* on this instance
178174
*/
179175
public Map<String, Object> buildProducerProperties() {
180176
Map<String, Object> properties = buildCommonProperties();
@@ -185,10 +181,8 @@ public Map<String, Object> buildProducerProperties() {
185181
private static String resourceToPath(Resource resource) {
186182
try {
187183
return resource.getFile().getAbsolutePath();
188-
}
189-
catch (IOException ex) {
190-
throw new IllegalStateException(
191-
"Resource '" + resource + "' must be on a file system", ex);
184+
} catch (IOException ex) {
185+
throw new IllegalStateException("Resource '" + resource + "' must be on a file system", ex);
192186
}
193187
}
194188

@@ -197,8 +191,8 @@ public static class Consumer {
197191
private final Ssl ssl = new Ssl();
198192

199193
/**
200-
* Frequency in milliseconds that the consumer offsets are auto-committed to Kafka
201-
* if 'enable.auto.commit' true.
194+
* Frequency in milliseconds that the consumer offsets are auto-committed to
195+
* Kafka if 'enable.auto.commit' true.
202196
*/
203197
private Integer autoCommitInterval;
204198

@@ -220,7 +214,8 @@ public static class Consumer {
220214
private String clientId;
221215

222216
/**
223-
* If true the consumer's offset will be periodically committed in the background.
217+
* If true the consumer's offset will be periodically committed in the
218+
* background.
224219
*/
225220
private Boolean enableAutoCommit;
226221

@@ -364,27 +359,22 @@ public void setMaxPollRecords(Integer maxPollRecords) {
364359
public Map<String, Object> buildProperties() {
365360
Map<String, Object> properties = new HashMap<String, Object>();
366361
if (this.autoCommitInterval != null) {
367-
properties.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG,
368-
this.autoCommitInterval);
362+
properties.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, this.autoCommitInterval);
369363
}
370364
if (this.autoOffsetReset != null) {
371-
properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
372-
this.autoOffsetReset);
365+
properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, this.autoOffsetReset);
373366
}
374367
if (this.bootstrapServers != null) {
375-
properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
376-
this.bootstrapServers);
368+
properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, this.bootstrapServers);
377369
}
378370
if (this.clientId != null) {
379371
properties.put(ConsumerConfig.CLIENT_ID_CONFIG, this.clientId);
380372
}
381373
if (this.enableAutoCommit != null) {
382-
properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG,
383-
this.enableAutoCommit);
374+
properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, this.enableAutoCommit);
384375
}
385376
if (this.fetchMaxWait != null) {
386-
properties.put(ConsumerConfig.FETCH_MAX_WAIT_MS_CONFIG,
387-
this.fetchMaxWait);
377+
properties.put(ConsumerConfig.FETCH_MAX_WAIT_MS_CONFIG, this.fetchMaxWait);
388378
}
389379
if (this.fetchMinSize != null) {
390380
properties.put(ConsumerConfig.FETCH_MIN_BYTES_CONFIG, this.fetchMinSize);
@@ -393,40 +383,32 @@ public Map<String, Object> buildProperties() {
393383
properties.put(ConsumerConfig.GROUP_ID_CONFIG, this.groupId);
394384
}
395385
if (this.heartbeatInterval != null) {
396-
properties.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG,
397-
this.heartbeatInterval);
386+
properties.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, this.heartbeatInterval);
398387
}
399388
if (this.keyDeserializer != null) {
400-
properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
401-
this.keyDeserializer);
389+
properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, this.keyDeserializer);
402390
}
403391
if (this.ssl.getKeyPassword() != null) {
404-
properties.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG,
405-
this.ssl.getKeyPassword());
392+
properties.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, this.ssl.getKeyPassword());
406393
}
407394
if (this.ssl.getKeystoreLocation() != null) {
408-
properties.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG,
409-
resourceToPath(this.ssl.getKeystoreLocation()));
395+
properties.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, resourceToPath(this.ssl.getKeystoreLocation()));
410396
}
411397
if (this.ssl.getKeystorePassword() != null) {
412-
properties.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG,
413-
this.ssl.getKeystorePassword());
398+
properties.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, this.ssl.getKeystorePassword());
414399
}
415400
if (this.ssl.getTruststoreLocation() != null) {
416401
properties.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG,
417402
resourceToPath(this.ssl.getTruststoreLocation()));
418403
}
419404
if (this.ssl.getTruststorePassword() != null) {
420-
properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG,
421-
this.ssl.getTruststorePassword());
405+
properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, this.ssl.getTruststorePassword());
422406
}
423407
if (this.valueDeserializer != null) {
424-
properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
425-
this.valueDeserializer);
408+
properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, this.valueDeserializer);
426409
}
427410
if (this.maxPollRecords != null) {
428-
properties.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG,
429-
this.maxPollRecords);
411+
properties.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, this.maxPollRecords);
430412
}
431413
return properties;
432414
}
@@ -444,8 +426,9 @@ public static class Producer {
444426
private String acks;
445427

446428
/**
447-
* Default batch size in bytes. A small batch size will make batching less common
448-
* and may reduce throughput (a batch size of zero disables batching entirely).
429+
* Default batch size in bytes. A small batch size will make batching less
430+
* common and may reduce throughput (a batch size of zero disables batching
431+
* entirely).
449432
*/
450433
private Integer batchSize;
451434

@@ -456,8 +439,8 @@ public static class Producer {
456439
private List<String> bootstrapServers;
457440

458441
/**
459-
* Total bytes of memory the producer can use to buffer records waiting to be sent
460-
* to the server.
442+
* Total bytes of memory the producer can use to buffer records waiting to be
443+
* sent to the server.
461444
*/
462445
private Long bufferMemory;
463446

@@ -571,8 +554,7 @@ public Map<String, Object> buildProperties() {
571554
properties.put(ProducerConfig.BATCH_SIZE_CONFIG, this.batchSize);
572555
}
573556
if (this.bootstrapServers != null) {
574-
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
575-
this.bootstrapServers);
557+
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, this.bootstrapServers);
576558
}
577559
if (this.bufferMemory != null) {
578560
properties.put(ProducerConfig.BUFFER_MEMORY_CONFIG, this.bufferMemory);
@@ -581,39 +563,32 @@ public Map<String, Object> buildProperties() {
581563
properties.put(ProducerConfig.CLIENT_ID_CONFIG, this.clientId);
582564
}
583565
if (this.compressionType != null) {
584-
properties.put(ProducerConfig.COMPRESSION_TYPE_CONFIG,
585-
this.compressionType);
566+
properties.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, this.compressionType);
586567
}
587568
if (this.keySerializer != null) {
588-
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
589-
this.keySerializer);
569+
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, this.keySerializer);
590570
}
591571
if (this.retries != null) {
592572
properties.put(ProducerConfig.RETRIES_CONFIG, this.retries);
593573
}
594574
if (this.ssl.getKeyPassword() != null) {
595-
properties.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG,
596-
this.ssl.getKeyPassword());
575+
properties.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, this.ssl.getKeyPassword());
597576
}
598577
if (this.ssl.getKeystoreLocation() != null) {
599-
properties.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG,
600-
resourceToPath(this.ssl.getKeystoreLocation()));
578+
properties.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, resourceToPath(this.ssl.getKeystoreLocation()));
601579
}
602580
if (this.ssl.getKeystorePassword() != null) {
603-
properties.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG,
604-
this.ssl.getKeystorePassword());
581+
properties.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, this.ssl.getKeystorePassword());
605582
}
606583
if (this.ssl.getTruststoreLocation() != null) {
607584
properties.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG,
608585
resourceToPath(this.ssl.getTruststoreLocation()));
609586
}
610587
if (this.ssl.getTruststorePassword() != null) {
611-
properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG,
612-
this.ssl.getTruststorePassword());
588+
properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, this.ssl.getTruststorePassword());
613589
}
614590
if (this.valueSerializer != null) {
615-
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
616-
this.valueSerializer);
591+
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, this.valueSerializer);
617592
}
618593
return properties;
619594
}

0 commit comments

Comments
 (0)