Skip to content

Commit 5ab3374

Browse files
bclozelsnicoll
authored andcommitted
Use operation name and namespace
1 parent e18d1f6 commit 5ab3374

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/mapping/AbstractMethodEndpointMapping.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
*/
5454
public abstract class AbstractMethodEndpointMapping<T> extends AbstractEndpointMapping {
5555

56+
/**
57+
* {@link MessageContext#getProperty(String) Property name} for the endpoint mapping
58+
* lookup key.
59+
*/
60+
public static final String LOOKUP_KEY_PROPERTY = AbstractMethodEndpointMapping.class.getName() + ".lookupKey";
61+
5662
private final Map<T, MethodEndpoint> endpointMap = new HashMap<>();
5763

5864
/**
@@ -70,6 +76,7 @@ public abstract class AbstractMethodEndpointMapping<T> extends AbstractEndpointM
7076
if (this.logger.isDebugEnabled()) {
7177
this.logger.debug("Looking up endpoint for [" + key + "]");
7278
}
79+
messageContext.setProperty(LOOKUP_KEY_PROPERTY, key);
7380
return lookupEndpoint(key);
7481
}
7582

spring-ws-core/src/main/java/org/springframework/ws/transport/support/WebServiceMessageReceiverObjectSupport.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.net.URISyntaxException;
2020

21+
import javax.xml.namespace.QName;
22+
2123
import io.micrometer.observation.Observation;
2224
import io.micrometer.observation.Observation.Scope;
2325
import io.micrometer.observation.ObservationRegistry;
@@ -32,6 +34,7 @@
3234
import org.springframework.ws.WebServiceMessageFactory;
3335
import org.springframework.ws.context.DefaultMessageContext;
3436
import org.springframework.ws.context.MessageContext;
37+
import org.springframework.ws.server.endpoint.mapping.AbstractMethodEndpointMapping;
3538
import org.springframework.ws.transport.EndpointAwareWebServiceConnection;
3639
import org.springframework.ws.transport.FaultAwareWebServiceConnection;
3740
import org.springframework.ws.transport.WebServiceConnection;
@@ -117,6 +120,11 @@ protected final void handleConnection(WebServiceConnection connection, WebServic
117120
MessageContext messageContext = new DefaultMessageContext(request, getMessageFactory());
118121
observationContext.setAsCurrent(messageContext);
119122
receiver.receive(messageContext);
123+
Object lookupKey = messageContext.getProperty(AbstractMethodEndpointMapping.LOOKUP_KEY_PROPERTY);
124+
if (lookupKey instanceof QName qName) {
125+
observationContext.setNamespace(qName.getNamespaceURI());
126+
observationContext.setOperationName(qName.getLocalPart());
127+
}
120128
if (messageContext.hasResponse()) {
121129
WebServiceMessage response = messageContext.getResponse();
122130
if (response instanceof FaultAwareWebServiceMessage faultResponse

spring-ws-core/src/test/java/org/springframework/ws/transport/observation/DefaultSoapServerObservationConventionTests.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2005-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ws.transport.observation;
218

319
import java.net.URI;
@@ -77,9 +93,9 @@ void protocol() throws Exception {
7793

7894
@Test
7995
void namespace() {
80-
this.context.setNamespace("CountriesPort");
96+
this.context.setNamespace("https://spring.io/guides/gs-producing-web-service");
8197
assertThat(this.convention.getLowCardinalityKeyValues(this.context))
82-
.contains(KeyValue.of("namespace", "CountriesPort"));
98+
.contains(KeyValue.of("namespace", "https://spring.io/guides/gs-producing-web-service"));
8399
}
84100

85101
@Test

spring-ws-core/src/test/java/org/springframework/ws/transport/support/MessageReceiverObservationTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
1+
/*
2+
* Copyright 2005-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ws.transport.support;
218

19+
import java.util.Objects;
20+
21+
import javax.xml.namespace.QName;
22+
323
import io.micrometer.observation.tck.TestObservationRegistry;
424
import org.junit.jupiter.api.BeforeEach;
525
import org.junit.jupiter.api.Test;
626

727
import org.springframework.ws.MockWebServiceMessage;
828
import org.springframework.ws.MockWebServiceMessageFactory;
929
import org.springframework.ws.NoEndpointFoundException;
30+
import org.springframework.ws.server.endpoint.mapping.AbstractMethodEndpointMapping;
1031
import org.springframework.ws.transport.FaultAwareWebServiceConnection;
1132
import org.springframework.ws.transport.WebServiceMessageReceiver;
1233
import org.springframework.ws.transport.observation.SoapServerObservationContext;
@@ -84,6 +105,24 @@ void shouldRecordNoEndpointFoundExceptions() throws Exception {
84105
.isInstanceOf(NoEndpointFoundException.class);
85106
}
86107

108+
@Test
109+
void shouldSetQNameInObservationContext() throws Exception {
110+
QName qName = QName.valueOf("{https://spring.io/guides/gs-producing-web-service}getCountryRequest");
111+
WebServiceMessageReceiver receiver = messageContext -> messageContext
112+
.setProperty(AbstractMethodEndpointMapping.LOOKUP_KEY_PROPERTY, qName);
113+
this.receiver.handleConnection(this.connectionMock, receiver);
114+
assertThat(this.observationRegistry).hasObservationWithNameEqualTo("soap.server.requests")
115+
.that()
116+
.matches(context -> {
117+
if (context instanceof SoapServerObservationContext observationContext) {
118+
return Objects.equals(observationContext.getNamespace(),
119+
"https://spring.io/guides/gs-producing-web-service")
120+
&& Objects.equals(observationContext.getOperationName(), "getCountryRequest");
121+
}
122+
return false;
123+
});
124+
}
125+
87126
static class ObservationMessageReceiver extends WebServiceMessageReceiverObjectSupport {
88127

89128
}

0 commit comments

Comments
 (0)