Skip to content

Commit e18d1f6

Browse files
committed
Harmonize
1 parent 332c19e commit e18d1f6

File tree

11 files changed

+172
-153
lines changed

11 files changed

+172
-153
lines changed

spring-ws-core/src/main/java/org/springframework/ws/client/core/observation/DefaultSoapClientObservationConvention.java

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717
package org.springframework.ws.client.core.observation;
1818

1919
import java.net.URI;
20+
import java.util.Objects;
21+
22+
import javax.xml.namespace.QName;
2023

2124
import io.micrometer.common.KeyValue;
2225
import io.micrometer.common.KeyValues;
23-
import org.jspecify.annotations.Nullable;
2426

27+
import org.springframework.ws.FaultAwareWebServiceMessage;
28+
import org.springframework.ws.WebServiceMessage;
2529
import org.springframework.ws.client.core.observation.SoapClientObservationDocumentation.HighCardinalityKeyNames;
2630
import org.springframework.ws.client.core.observation.SoapClientObservationDocumentation.LowCardinalityKeyNames;
2731

2832
/**
29-
* Default implementation for a {@link SoapClientObservationConvention}, extracting
30-
* information from the {@link SoapClientObservationConvention}.
33+
* Default {@link SoapClientObservationConvention} implementation.
3134
*
3235
* @author Stephane Nicoll
3336
* @since 5.1.0
@@ -54,31 +57,47 @@ public DefaultSoapClientObservationConvention(String name) {
5457
}
5558

5659
@Override
57-
public @Nullable String getName() {
60+
public String getName() {
5861
return this.name;
5962
}
6063

64+
@Override
65+
public String getContextualName(SoapClientObservationContext context) {
66+
if (context.getOperationName() != null) {
67+
return "soap " + context.getOperationName();
68+
}
69+
return "soap";
70+
}
71+
6172
@Override
6273
public KeyValues getLowCardinalityKeyValues(SoapClientObservationContext context) {
6374
return KeyValues.of(faultCode(context), namespace(context), operationName(context), protocol(context));
6475
}
6576

66-
protected KeyValue faultCode(SoapClientObservationContext context) {
67-
// FIXME
77+
private KeyValue faultCode(SoapClientObservationContext context) {
78+
WebServiceMessage response = context.getResponse();
79+
if (response instanceof FaultAwareWebServiceMessage faultResponse) {
80+
QName faultCode = faultResponse.getFaultCode();
81+
if (faultCode != null) {
82+
return KeyValue.of(LowCardinalityKeyNames.FAULT_CODE, faultCode.toString());
83+
}
84+
}
6885
return KeyValue.of(LowCardinalityKeyNames.FAULT_CODE, KeyValue.NONE_VALUE);
6986
}
7087

71-
protected KeyValue namespace(SoapClientObservationContext context) {
72-
// FIXME
73-
return KeyValue.of(LowCardinalityKeyNames.NAMESPACE, KeyValue.NONE_VALUE);
88+
private KeyValue namespace(SoapClientObservationContext context) {
89+
return KeyValue.of(LowCardinalityKeyNames.NAMESPACE,
90+
Objects.requireNonNullElse(context.getNamespace(), KeyValue.NONE_VALUE));
7491
}
7592

76-
protected KeyValue operationName(SoapClientObservationContext context) {
77-
// FIXME
93+
private KeyValue operationName(SoapClientObservationContext context) {
94+
if (context.getOperationName() != null) {
95+
return KeyValue.of(LowCardinalityKeyNames.OPERATION_NAME, context.getOperationName());
96+
}
7897
return KeyValue.of(LowCardinalityKeyNames.OPERATION_NAME, KeyValue.NONE_VALUE);
7998
}
8099

81-
protected KeyValue protocol(SoapClientObservationContext context) {
100+
private KeyValue protocol(SoapClientObservationContext context) {
82101
URI uri = context.getUri();
83102
String protocol = (uri != null) ? uri.getScheme() : KeyValue.NONE_VALUE;
84103
return KeyValue.of(LowCardinalityKeyNames.PROTOCOL, protocol);
@@ -89,15 +108,21 @@ public KeyValues getHighCardinalityKeyValues(SoapClientObservationContext contex
89108
return KeyValues.of(faultReason(context), uri(context));
90109
}
91110

92-
protected KeyValue faultReason(SoapClientObservationContext context) {
93-
// FIXME
111+
private KeyValue faultReason(SoapClientObservationContext context) {
112+
WebServiceMessage response = context.getResponse();
113+
if (response instanceof FaultAwareWebServiceMessage faultResponse) {
114+
String faultReason = faultResponse.getFaultReason();
115+
if (faultReason != null) {
116+
return KeyValue.of(HighCardinalityKeyNames.FAULT_REASON, faultReason);
117+
}
118+
}
94119
return KeyValue.of(HighCardinalityKeyNames.FAULT_REASON, KeyValue.NONE_VALUE);
95120
}
96121

97-
protected KeyValue uri(SoapClientObservationContext context) {
122+
private KeyValue uri(SoapClientObservationContext context) {
98123
URI uri = context.getUri();
99124
String value = (uri != null) ? uri.toString() : KeyValue.NONE_VALUE;
100-
return KeyValue.of(HighCardinalityKeyNames.URL, value);
125+
return KeyValue.of(HighCardinalityKeyNames.URI, value);
101126
}
102127

103128
}

spring-ws-core/src/main/java/org/springframework/ws/client/core/observation/SoapClientObservationContext.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
* Context that holds information for metadata collection during the
3636
* {@link SoapClientObservationDocumentation#SOAP_CLIENT_REQUESTS SOAP client}
3737
* observations.
38+
* <p>
39+
* This context also extends {@link RequestReplySenderContext} for propagating tracing
40+
* information over supported transports.
3841
*
3942
* @author Stephane Nicoll
4043
* @since 5.1.0
@@ -52,6 +55,10 @@ public class SoapClientObservationContext extends RequestReplySenderContext<WebS
5255

5356
private final MessageContext messageContext;
5457

58+
private @Nullable String namespace;
59+
60+
private @Nullable String operationName;
61+
5562
public SoapClientObservationContext(MessageContext messageContext, WebServiceConnection connection) {
5663
super(SETTER);
5764
this.messageContext = messageContext;
@@ -80,18 +87,35 @@ public MessageContext getMessageContext() {
8087
}
8188

8289
@Override
83-
public WebServiceMessage getResponse() {
84-
return this.messageContext.getResponse();
90+
public @Nullable WebServiceMessage getResponse() {
91+
if (this.messageContext.hasResponse()) {
92+
return this.messageContext.getResponse();
93+
}
94+
return null;
95+
}
96+
97+
public @Nullable String getNamespace() {
98+
return this.namespace;
99+
}
100+
101+
public void setNamespace(@Nullable String namespace) {
102+
this.namespace = namespace;
103+
}
104+
105+
public @Nullable String getOperationName() {
106+
return this.operationName;
107+
}
108+
109+
public void setOperationName(@Nullable String operationName) {
110+
this.operationName = operationName;
85111
}
86112

87113
public @Nullable URI getUri() {
88-
if (getCarrier() != null) {
89-
try {
90-
return getCarrier().getUri();
91-
}
92-
catch (URISyntaxException ex) {
93-
// ignore
94-
}
114+
try {
115+
return getConnection().getUri();
116+
}
117+
catch (URISyntaxException ex) {
118+
// ignore
95119
}
96120
return null;
97121
}

spring-ws-core/src/main/java/org/springframework/ws/client/core/observation/SoapClientObservationDocumentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public enum SoapClientObservationDocumentation implements ObservationDocumentati
3838
SOAP_CLIENT_REQUESTS {
3939
@Override
4040
public Class<? extends ObservationConvention<? extends Context>> getDefaultConvention() {
41-
return DefaultSoapClientObservationConvention.class;
41+
return SoapClientObservationConvention.class;
4242
}
4343

4444
@Override
@@ -113,7 +113,7 @@ public String asString() {
113113
/**
114114
* Target URI.
115115
*/
116-
URL {
116+
URI {
117117
@Override
118118
public String asString() {
119119
return "url";

spring-ws-core/src/main/java/org/springframework/ws/transport/observation/DefaultSoapServerObservationConvention.java

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,27 @@
1717
package org.springframework.ws.transport.observation;
1818

1919
import java.net.URI;
20-
import java.net.URISyntaxException;
20+
import java.util.Objects;
2121

2222
import javax.xml.namespace.QName;
2323

2424
import io.micrometer.common.KeyValue;
2525
import io.micrometer.common.KeyValues;
26-
import org.jspecify.annotations.Nullable;
2726

2827
import org.springframework.ws.FaultAwareWebServiceMessage;
2928
import org.springframework.ws.WebServiceMessage;
3029
import org.springframework.ws.transport.observation.SoapServerObservationDocumentation.HighCardinalityKeyNames;
3130
import org.springframework.ws.transport.observation.SoapServerObservationDocumentation.LowCardinalityKeyNames;
3231

3332
/**
34-
* Default {@link SoapServerObservationConvention}.
33+
* Default {@link SoapServerObservationConvention} implementation.
3534
*
3635
* @author Brian Clozel
3736
* @since 5.1.0
3837
*/
39-
public class DefaultSoapServerObservationConvention extends SoapServerObservationConvention {
38+
public class DefaultSoapServerObservationConvention implements SoapServerObservationConvention {
4039

41-
private static final String DEFAULT_NAME = "soap.server.duration";
40+
private static final String DEFAULT_NAME = "soap.server.requests";
4241

4342
private final String name;
4443

@@ -64,15 +63,15 @@ public String getName() {
6463

6564
@Override
6665
public String getContextualName(SoapServerObservationContext context) {
67-
if (context.getMethodName() != null) {
68-
return "soap " + context.getMethodName();
66+
if (context.getOperationName() != null) {
67+
return "soap " + context.getOperationName();
6968
}
7069
return "soap";
7170
}
7271

7372
@Override
7473
public KeyValues getLowCardinalityKeyValues(SoapServerObservationContext context) {
75-
return KeyValues.of(faultCode(context), method(context), address(context), protocol(context), service(context));
74+
return KeyValues.of(faultCode(context), namespace(context), operationName(context), protocol(context));
7675
}
7776

7877
private KeyValue faultCode(SoapServerObservationContext context) {
@@ -86,59 +85,29 @@ private KeyValue faultCode(SoapServerObservationContext context) {
8685
return KeyValue.of(LowCardinalityKeyNames.FAULT_CODE, KeyValue.NONE_VALUE);
8786
}
8887

89-
private KeyValue method(SoapServerObservationContext context) {
90-
if (context.getMethodName() != null) {
91-
return KeyValue.of(LowCardinalityKeyNames.METHOD, context.getMethodName());
92-
}
93-
return KeyValue.of(LowCardinalityKeyNames.METHOD, KeyValue.NONE_VALUE);
88+
private KeyValue namespace(SoapServerObservationContext context) {
89+
return KeyValue.of(LowCardinalityKeyNames.NAMESPACE,
90+
Objects.requireNonNullElse(context.getNamespace(), KeyValue.NONE_VALUE));
9491
}
9592

96-
private KeyValue address(SoapServerObservationContext context) {
97-
URI uri = getConnectionURI(context);
98-
if (uri != null) {
99-
return KeyValue.of(LowCardinalityKeyNames.ADDRESS, uri.getHost());
93+
private KeyValue operationName(SoapServerObservationContext context) {
94+
if (context.getOperationName() != null) {
95+
return KeyValue.of(LowCardinalityKeyNames.OPERATION_NAME, context.getOperationName());
10096
}
101-
return KeyValue.of(LowCardinalityKeyNames.ADDRESS, KeyValue.NONE_VALUE);
97+
return KeyValue.of(LowCardinalityKeyNames.OPERATION_NAME, KeyValue.NONE_VALUE);
10298
}
10399

104100
private KeyValue protocol(SoapServerObservationContext context) {
105-
URI uri = getConnectionURI(context);
106-
if (uri != null) {
107-
return KeyValue.of(LowCardinalityKeyNames.PROTOCOL, uri.getScheme());
108-
}
109-
return KeyValue.of(LowCardinalityKeyNames.PROTOCOL, KeyValue.NONE_VALUE);
110-
}
111-
112-
private KeyValue service(SoapServerObservationContext context) {
113-
String serviceName = context.getServiceName();
114-
if (serviceName != null) {
115-
return KeyValue.of(LowCardinalityKeyNames.SERVICE, serviceName);
116-
}
117-
return KeyValue.of(LowCardinalityKeyNames.SERVICE, KeyValue.NONE_VALUE);
118-
}
119-
120-
private @Nullable URI getConnectionURI(SoapServerObservationContext context) {
121-
try {
122-
return context.getConnection().getUri();
123-
}
124-
catch (URISyntaxException exc) {
125-
return null;
126-
}
101+
URI uri = context.getUri();
102+
String protocol = (uri != null) ? uri.getScheme() : KeyValue.NONE_VALUE;
103+
return KeyValue.of(LowCardinalityKeyNames.PROTOCOL, protocol);
127104
}
128105

129106
@Override
130107
public KeyValues getHighCardinalityKeyValues(SoapServerObservationContext context) {
131108
return KeyValues.of(faultReason(context), uri(context));
132109
}
133110

134-
private KeyValue uri(SoapServerObservationContext context) {
135-
URI uri = getConnectionURI(context);
136-
if (uri != null) {
137-
return KeyValue.of(HighCardinalityKeyNames.URL, uri.toString());
138-
}
139-
return KeyValue.of(HighCardinalityKeyNames.URL, KeyValue.NONE_VALUE);
140-
}
141-
142111
private KeyValue faultReason(SoapServerObservationContext context) {
143112
WebServiceMessage response = context.getResponse();
144113
if (response instanceof FaultAwareWebServiceMessage faultResponse) {
@@ -150,4 +119,10 @@ private KeyValue faultReason(SoapServerObservationContext context) {
150119
return KeyValue.of(HighCardinalityKeyNames.FAULT_REASON, KeyValue.NONE_VALUE);
151120
}
152121

122+
private KeyValue uri(SoapServerObservationContext context) {
123+
URI uri = context.getUri();
124+
String value = (uri != null) ? uri.toString() : KeyValue.NONE_VALUE;
125+
return KeyValue.of(HighCardinalityKeyNames.URI, value);
126+
}
127+
153128
}

0 commit comments

Comments
 (0)