@@ -0,0 +1,4216 @@
+/*%0A * Copyright (c) 2010-2017. Axon Framework%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.axonframework.springcloud.commandhandling;%0A%0Aimport java.net.URI;%0Aimport java.util.Optional;%0Aimport java.util.function.Predicate;%0A%0Aimport org.axonframework.commandhandling.CommandMessage;%0Aimport org.axonframework.commandhandling.distributed.Member;%0Aimport org.axonframework.serialization.Serializer;%0Aimport org.axonframework.serialization.xml.XStreamSerializer;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.http.HttpEntity;%0Aimport org.springframework.http.HttpMethod;%0Aimport org.springframework.web.bind.annotation.GetMapping;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.RestController;%0Aimport org.springframework.web.client.RestTemplate;%0Aimport org.springframework.web.util.UriComponentsBuilder;%0A%0A/**%0A * A Spring Http implementation of the %7B@link org.axonframework.springcloud.commandhandling.MembershipService%7D, which%0A * uses Spring Web annotations to turn this class into a controller and a %7B@link org.springframework.web.client.RestTemplate%7D%0A * to request %7B@link org.axonframework.springcloud.commandhandling.MembershipInformation%7D from other members.%0A */%0A@RestController%0A@RequestMapping(SpringHttpMembershipService.MEMBERSHIP_INFORMATION_PATH)%0Apublic class SpringHttpMembershipService implements MembershipService %7B%0A%0A    private static final Logger logger = LoggerFactory.getLogger(SpringHttpMembershipService.class);%0A%0A    static final String MEMBERSHIP_INFORMATION_PATH = %22/membership-information%22;%0A%0A    private final RestTemplate restTemplate;%0A    private final Serializer serializer = new XStreamSerializer();%0A%0A    private MembershipInformation membershipInformation;%0A%0A    public SpringHttpMembershipService(RestTemplate restTemplate) %7B%0A        this.restTemplate = restTemplate;%0A    %7D%0A%0A    @Override%0A    public void updateMembership(int loadFactor, Predicate%3C? super CommandMessage%3C?%3E%3E commandFilter) %7B%0A        membershipInformation = new MembershipInformation(loadFactor, commandFilter, serializer);%0A    %7D%0A%0A    @GetMapping%0A    @Override%0A    public MembershipInformation getLocalMembershipInformation() %7B%0A        return membershipInformation;%0A    %7D%0A%0A    @Override%0A    public MembershipInformation getRemoteMembershipInformation(Member remoteMember) %7B%0A        Optional%3CURI%3E optionalEndpoint = remoteMember.getConnectionEndpoint(URI.class);%0A        if (optionalEndpoint.isPresent()) %7B%0A            URI endpointUri = optionalEndpoint.get();%0A            URI destinationUri = buildURIForPath(endpointUri, MEMBERSHIP_INFORMATION_PATH);%0A%0A            return restTemplate.exchange(destinationUri,%0A                                         HttpMethod.GET,%0A                                         new HttpEntity%3C%3E(null),%0A                                         MembershipInformation.class)%0A                               .getBody();%0A        %7D else %7B%0A            String errorMessage = String.format(%22No Connection Endpoint found in Member %5B%25s%5D for protocol %5B%25s%5D %22 +%0A                                                        %22to send a MembershipInformation request to%22,%0A                                                remoteMember,%0A                                                URI.class);%0A            logger.error(errorMessage);%0A            throw new IllegalArgumentException(errorMessage);%0A        %7D%0A    %7D%0A%0A    private static URI buildURIForPath(URI uri, String appendToPath) %7B%0A        return UriComponentsBuilder.fromUri(uri)%0A                                   .path(uri.getPath() + appendToPath)%0A                                   .build()%0A                                   .toUri();%0A    %7D%0A%0A%7D%0A

Introduce a SpringHttp MembershipService implementation