1 /*
2 * Copyright 2006 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 * http://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
17 package org.springframework.ws.soap.server.endpoint.mapping;
18
19 import org.springframework.beans.factory.InitializingBean;
20 import org.springframework.util.Assert;
21 import org.springframework.ws.context.MessageContext;
22 import org.springframework.ws.server.EndpointInvocationChain;
23 import org.springframework.ws.server.EndpointMapping;
24 import org.springframework.ws.soap.server.SoapEndpointInvocationChain;
25 import org.springframework.ws.soap.server.SoapEndpointMapping;
26
27 /**
28 * <code>EndpointMapping</code> implement that adds SOAP actors or roles to a delegate endpoint. Delegates to another
29 * <code>EndpointMapping</code>, set by <code>delegate</code>, and adds the actors or roles specified by
30 * <code>actorsOrRoles</code>.
31 * <p/>
32 * This endpoint mapping makes it possible to set actors/roles on a specific endpoint, without making the all endpoint
33 * mappings depend on SOAP-specific functionality. For normal use, setting an actor or role on an endpoint is not
34 * required, the default 'next' role is sufficient.
35 * <p/>
36 * It is only in a scenario when a certain endpoint act as a SOAP intermediary for another endpoint, as described in the
37 * SOAP specificication, this mapping is useful.
38 *
39 * @author Arjen Poutsma
40 * @see org.springframework.ws.soap.SoapHeader#examineMustUnderstandHeaderElements(String)
41 * @see org.springframework.ws.soap.SoapVersion#getNextActorOrRoleUri()
42 * @since 1.0.0
43 */
44 public class DelegatingSoapEndpointMapping implements InitializingBean, SoapEndpointMapping {
45
46 private EndpointMapping delegate;
47
48 private String[] actorsOrRoles;
49
50 private boolean isUltimateReceiver = true;
51
52 /** Sets the delegate <code>EndpointMapping</code> to resolve the endpoint with. */
53 public void setDelegate(EndpointMapping delegate) {
54 this.delegate = delegate;
55 }
56
57 public final void setActorOrRole(String actorOrRole) {
58 Assert.notNull(actorOrRole, "actorOrRole must not be null");
59 actorsOrRoles = new String[]{actorOrRole};
60 }
61
62 public final void setActorsOrRoles(String[] actorsOrRoles) {
63 Assert.notEmpty(actorsOrRoles, "actorsOrRoles must not be empty");
64 this.actorsOrRoles = actorsOrRoles;
65 }
66
67 public final void setUltimateReceiver(boolean ultimateReceiver) {
68 isUltimateReceiver = ultimateReceiver;
69 }
70
71 /**
72 * Creates a new <code>SoapEndpointInvocationChain</code> based on the delegate endpoint, the delegate interceptors,
73 * and set actors/roles.
74 *
75 * @see #setActorsOrRoles(String[])
76 */
77 public EndpointInvocationChain getEndpoint(MessageContext messageContext) throws Exception {
78 EndpointInvocationChain delegateChain = delegate.getEndpoint(messageContext);
79 if (delegateChain != null) {
80 return new SoapEndpointInvocationChain(delegateChain.getEndpoint(), delegateChain.getInterceptors(),
81 actorsOrRoles, isUltimateReceiver);
82 }
83 else {
84 return null;
85 }
86 }
87
88 public void afterPropertiesSet() throws Exception {
89 Assert.notNull(delegate, "delegate is required");
90 }
91 }