21
21
import java .util .Calendar ;
22
22
import java .util .Map ;
23
23
import java .util .Map .Entry ;
24
- import java .util .Optional ;
25
24
import java .util .Set ;
26
25
import java .util .Timer ;
27
26
import java .util .TimerTask ;
49
48
import org .springframework .amqp .rabbit .core .DeclareExchangeConnectionListener ;
50
49
import org .springframework .amqp .rabbit .core .RabbitAdmin ;
51
50
import org .springframework .amqp .rabbit .core .RabbitTemplate ;
51
+ import org .springframework .amqp .utils .JavaUtils ;
52
52
import org .springframework .core .io .Resource ;
53
53
import org .springframework .core .io .support .PathMatchingResourcePatternResolver ;
54
54
import org .springframework .util .StringUtils ;
64
64
import com .rabbitmq .client .ConnectionFactory ;
65
65
66
66
/**
67
- * A Lockback appender that publishes logging events to an AMQP Exchange.
67
+ * A Logback appender that publishes logging events to an AMQP Exchange.
68
68
* <p>
69
69
* A fully-configured AmqpAppender, with every option set to their defaults, would look like this:
70
70
*
@@ -272,6 +272,8 @@ public class AmqpAppender extends AppenderBase<ILoggingEvent> {
272
272
*/
273
273
private String trustStoreType = "JKS" ;
274
274
275
+ private boolean verifyHostname = true ;
276
+
275
277
/**
276
278
* Default content-type of log messages.
277
279
*/
@@ -381,6 +383,25 @@ public void setUseSsl(boolean ssl) {
381
383
this .useSsl = ssl ;
382
384
}
383
385
386
+ /**
387
+ * Enable server hostname verification for TLS connections.
388
+ * @param enable false to disable.
389
+ * @since 2.1.6
390
+ * @see RabbitConnectionFactoryBean#setEnableHostnameVerification(boolean)
391
+ */
392
+ public void setVerifyHostname (boolean enable ) {
393
+ this .verifyHostname = enable ;
394
+ }
395
+
396
+ /**
397
+ * Return true (default) if TLS hostname verification is enabled.
398
+ * @return true (default) if TLS hostname verification is enabled.
399
+ * @since 2.1.6
400
+ */
401
+ public boolean isVerifyHostname () {
402
+ return this .verifyHostname ;
403
+ }
404
+
384
405
public String getSslAlgorithm () {
385
406
return this .sslAlgorithm ;
386
407
}
@@ -589,7 +610,6 @@ public void setConnectionName(String connectionName) {
589
610
/**
590
611
* Set additional client connection properties to be added to the rabbit connection,
591
612
* with the form {@code key:value[,key:value]...}.
592
- *
593
613
* @param clientConnectionProperties the properties.
594
614
* @since 1.5.6
595
615
*/
@@ -620,7 +640,7 @@ public void start() {
620
640
if (rabbitConnectionFactory != null ) {
621
641
super .start ();
622
642
this .routingKeyLayout .setPattern (this .routingKeyLayout .getPattern ()
623
- .replaceAll ("%property\\ {applicationId\\ }" , this .applicationId ));
643
+ .replaceAll ("%property\\ {applicationId}" , this .applicationId ));
624
644
this .routingKeyLayout .setContext (getContext ());
625
645
this .routingKeyLayout .start ();
626
646
this .locationLayout .setContext (getContext ());
@@ -645,7 +665,6 @@ public void start() {
645
665
646
666
/**
647
667
* Create the {@link ConnectionFactory}.
648
- *
649
668
* @return a {@link ConnectionFactory}.
650
669
*/
651
670
protected ConnectionFactory createRabbitConnectionFactory () {
@@ -664,21 +683,21 @@ protected ConnectionFactory createRabbitConnectionFactory() {
664
683
/**
665
684
* Configure the {@link RabbitConnectionFactoryBean}. Sub-classes may override to
666
685
* customize the configuration of the bean.
667
- *
668
686
* @param factoryBean the {@link RabbitConnectionFactoryBean}.
669
687
*/
670
688
protected void configureRabbitConnectionFactory (RabbitConnectionFactoryBean factoryBean ) {
671
-
672
- Optional . ofNullable (this .host ). ifPresent ( factoryBean ::setHost );
673
- Optional . ofNullable (this .port ). ifPresent ( factoryBean ::setPort );
674
- Optional . ofNullable (this .username ). ifPresent ( factoryBean ::setUsername );
675
- Optional . ofNullable (this .password ). ifPresent ( factoryBean ::setPassword );
676
- Optional . ofNullable (this .virtualHost ). ifPresent ( factoryBean ::setVirtualHost );
677
- // overrides all preceding items when set
678
- Optional . ofNullable (this .uri ). ifPresent ( factoryBean ::setUri );
689
+ JavaUtils . INSTANCE
690
+ . acceptIfNotNull (this .host , factoryBean ::setHost )
691
+ . acceptIfNotNull (this .port , factoryBean ::setPort )
692
+ . acceptIfNotNull (this .username , factoryBean ::setUsername )
693
+ . acceptIfNotNull (this .password , factoryBean ::setPassword )
694
+ . acceptIfNotNull (this .virtualHost , factoryBean ::setVirtualHost )
695
+ // overrides all preceding items when set
696
+ . acceptIfNotNull (this .uri , factoryBean ::setUri );
679
697
680
698
if (this .useSsl ) {
681
699
factoryBean .setUseSSL (true );
700
+ factoryBean .setEnableHostnameVerification (this .verifyHostname );
682
701
if (this .sslAlgorithm != null ) {
683
702
factoryBean .setSslAlgorithm (this .sslAlgorithm );
684
703
}
@@ -708,7 +727,6 @@ protected void configureRabbitConnectionFactory(RabbitConnectionFactoryBean fact
708
727
/**
709
728
* Subclasses can override this method to add properties to the connection client
710
729
* properties.
711
- *
712
730
* @param clientProperties the client properties.
713
731
* @since 1.5.6
714
732
*/
@@ -717,7 +735,6 @@ protected void updateConnectionClientProperties(Map<String, Object> clientProper
717
735
718
736
/**
719
737
* Subclasses can override this method to inject a custom queue implementation.
720
- *
721
738
* @return the queue to use for queueing logging events before processing them.
722
739
* @since 2.0.1
723
740
*/
@@ -773,7 +790,6 @@ else if ("headers".equals(this.exchangeType)) {
773
790
774
791
/**
775
792
* Subclasses may modify the final message before sending.
776
- *
777
793
* @param message The message.
778
794
* @param event The event.
779
795
* @return The modified message.
@@ -920,6 +936,7 @@ private byte[] encodeMessage(ILoggingEvent logEvent) {
920
936
return msgBody .getBytes (); //NOSONAR (default charset)
921
937
}
922
938
}
939
+
923
940
}
924
941
925
942
/**
0 commit comments