001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.spi; 018 019import java.util.Map; 020 021import org.apache.camel.Exchange; 022import org.apache.camel.Processor; 023import org.apache.camel.Producer; 024 025/** 026 * Used for components that can optimise the usage of {@link org.apache.camel.processor.SendDynamicProcessor} (toD) 027 * to reuse a static {@link org.apache.camel.Endpoint} and {@link Producer} that supports 028 * using headers to provide the dynamic parts. For example many of the HTTP components supports this. 029 */ 030public interface SendDynamicAware { 031 032 /** 033 * Sets the component name. 034 * 035 * @param scheme name of the component 036 */ 037 void setScheme(String scheme); 038 039 /** 040 * Gets the component name 041 */ 042 String getScheme(); 043 044 /** 045 * An entry of detailed information from the recipient uri, which allows the {@link SendDynamicAware} 046 * implementation to prepare pre- and post- processor and the static uri to be used for the optimised dynamic to. 047 */ 048 class DynamicAwareEntry { 049 050 private final String originalUri; 051 private final Map<String, String> properties; 052 private final Map<String, String> lenientProperties; 053 054 public DynamicAwareEntry(String originalUri, Map<String, String> properties, Map<String, String> lenientProperties) { 055 this.originalUri = originalUri; 056 this.properties = properties; 057 this.lenientProperties = lenientProperties; 058 } 059 060 public String getOriginalUri() { 061 return originalUri; 062 } 063 064 public Map<String, String> getProperties() { 065 return properties; 066 } 067 068 public Map<String, String> getLenientProperties() { 069 return lenientProperties; 070 } 071 } 072 073 /** 074 * Prepares for using optimised dynamic to by parsing the uri and returning an entry of details that are 075 * used for creating the pre and post processors, and the static uri. 076 * 077 * @param exchange the exchange 078 * @param uri the original uri 079 * @return prepared information about the dynamic endpoint to use 080 * @throws Exception is thrown if error parsing the uri 081 */ 082 DynamicAwareEntry prepare(Exchange exchange, String uri) throws Exception; 083 084 /** 085 * Resolves the static part of the uri that are used for creating a single {@link org.apache.camel.Endpoint} 086 * and {@link Producer} that will be reused for processing the optimised toD. 087 * 088 * @param exchange the exchange 089 * @param entry prepared information about the dynamic endpoint to use 090 * @return the static uri, or <tt>null</tt> to not let toD use this optimisation. 091 * @throws Exception is thrown if error resolving the static uri. 092 */ 093 String resolveStaticUri(Exchange exchange, DynamicAwareEntry entry) throws Exception; 094 095 /** 096 * Creates the pre {@link Processor} that will prepare the {@link Exchange} 097 * with dynamic details from the given recipient. 098 * 099 * @param exchange the exchange 100 * @param entry prepared information about the dynamic endpoint to use 101 * @return the processor, or <tt>null</tt> to not let toD use this optimisation. 102 * @throws Exception is thrown if error creating the pre processor. 103 */ 104 Processor createPreProcessor(Exchange exchange, DynamicAwareEntry entry) throws Exception; 105 106 /** 107 * Creates an optional post {@link Processor} that will be executed afterwards 108 * when the message has been sent dynamic. 109 * 110 * @param exchange the exchange 111 * @param entry prepared information about the dynamic endpoint to use 112 * @return the post processor, or <tt>null</tt> if no post processor is needed. 113 * @throws Exception is thrown if error creating the post processor. 114 */ 115 Processor createPostProcessor(Exchange exchange, DynamicAwareEntry entry) throws Exception; 116 117}