1 /* 2 * Copyright 2008 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.server.endpoint.mapping; 18 19 import java.net.URI; 20 import java.net.URISyntaxException; 21 22 import org.springframework.ws.context.MessageContext; 23 import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory; 24 import org.springframework.ws.transport.WebServiceConnection; 25 import org.springframework.ws.transport.context.TransportContext; 26 import org.springframework.ws.transport.context.TransportContextHolder; 27 28 /** 29 * Implementation of the <code>EndpointMapping</code> interface to map from the full request URI to endpoint beans. 30 * Supports both mapping to bean instances and mapping to bean names: the latter is required for prototype handlers. 31 * <p/> 32 * The <code>endpointMap</code> property is suitable for populating the endpoint map with bean references, e.g. via the 33 * map element in XML bean definitions. 34 * <p/> 35 * Mappings to bean names can be set via the <code>mappings</code> property, in a form accepted by the 36 * <code>java.util.Properties</code> class, like as follows: 37 * <pre> 38 * http://example.com:8080/services/bookFlight=bookFlightEndpoint 39 * jms://exampleQueue=getFlightsEndpoint 40 * </pre> 41 * The syntax is URI=ENDPOINT_BEAN_NAME. 42 * <p/> 43 * This endpoint mapping does not read from the request message, and therefore is more suitable for message factories 44 * which directly read from the transport request (such as the {@link AxiomSoapMessageFactory} with the 45 * <code>payloadCaching</code> disabled). However, this endpoint mapping obviously is transport specific. 46 * 47 * @author Arjen Poutsma 48 * @since 1.5.0 49 */ 50 public class UriEndpointMapping extends AbstractMapBasedEndpointMapping { 51 52 protected boolean validateLookupKey(String key) { 53 try { 54 new URI(key); 55 return true; 56 } 57 catch (URISyntaxException e) { 58 return false; 59 } 60 } 61 62 protected String getLookupKeyForMessage(MessageContext messageContext) throws Exception { 63 TransportContext transportContext = TransportContextHolder.getTransportContext(); 64 if (transportContext != null) { 65 WebServiceConnection connection = transportContext.getConnection(); 66 if (connection != null) { 67 return connection.getUri().toString(); 68 } 69 } 70 return null; 71 } 72 }