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 uri; 051 private final String originalUri; 052 private final Map<String, String> properties; 053 private final Map<String, String> lenientProperties; 054 055 public DynamicAwareEntry(String uri, String originalUri, Map<String, String> properties, Map<String, String> lenientProperties) { 056 this.uri = uri; 057 this.originalUri = originalUri; 058 this.properties = properties; 059 this.lenientProperties = lenientProperties; 060 } 061 062 public String getUri() { 063 return uri; 064 } 065 066 public String getOriginalUri() { 067 return originalUri; 068 } 069 070 public Map<String, String> getProperties() { 071 return properties; 072 } 073 074 public Map<String, String> getLenientProperties() { 075 return lenientProperties; 076 } 077 } 078 079 /** 080 * Prepares for using optimised dynamic to by parsing the uri and returning an entry of details that are 081 * used for creating the pre and post processors, and the static uri. 082 * 083 * @param exchange the exchange 084 * @param uri the resolved uri which is intended to be used 085 * @param originalUri the original uri of the endpoint before any dynamic evaluation 086 * @return prepared information about the dynamic endpoint to use 087 * @throws Exception is thrown if error parsing the uri 088 */ 089 DynamicAwareEntry prepare(Exchange exchange, String uri, String originalUri) throws Exception; 090 091 /** 092 * Resolves the static part of the uri that are used for creating a single {@link org.apache.camel.Endpoint} 093 * and {@link Producer} that will be reused for processing the optimised toD. 094 * 095 * @param exchange the exchange 096 * @param entry prepared information about the dynamic endpoint to use 097 * @return the static uri, or <tt>null</tt> to not let toD use this optimisation. 098 * @throws Exception is thrown if error resolving the static uri. 099 */ 100 String resolveStaticUri(Exchange exchange, DynamicAwareEntry entry) throws Exception; 101 102 /** 103 * Creates the pre {@link Processor} that will prepare the {@link Exchange} 104 * with dynamic details from the given recipient. 105 * 106 * @param exchange the exchange 107 * @param entry prepared information about the dynamic endpoint to use 108 * @return the processor, or <tt>null</tt> to not let toD use this optimisation. 109 * @throws Exception is thrown if error creating the pre processor. 110 */ 111 Processor createPreProcessor(Exchange exchange, DynamicAwareEntry entry) throws Exception; 112 113 /** 114 * Creates an optional post {@link Processor} that will be executed afterwards 115 * when the message has been sent dynamic. 116 * 117 * @param exchange the exchange 118 * @param entry prepared information about the dynamic endpoint to use 119 * @return the post processor, or <tt>null</tt> if no post processor is needed. 120 * @throws Exception is thrown if error creating the post processor. 121 */ 122 Processor createPostProcessor(Exchange exchange, DynamicAwareEntry entry) throws Exception; 123 124}