Package org.apache.camel.component
Class ResourceEndpoint
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.DefaultEndpoint
-
- org.apache.camel.support.ScheduledPollEndpoint
-
- org.apache.camel.support.DefaultPollingEndpoint
-
- org.apache.camel.support.ProcessorEndpoint
-
- org.apache.camel.component.ResourceEndpoint
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
,org.apache.camel.CamelContextAware
,org.apache.camel.Endpoint
,org.apache.camel.IsSingleton
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.HasId
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
@ManagedResource(description="Managed ResourceEndpoint") public abstract class ResourceEndpoint extends ProcessorEndpoint implements org.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
A useful base class for endpoints which depend on a resource such as things like Velocity or XQuery based components.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Logger
log
-
Constructor Summary
Constructors Constructor Description ResourceEndpoint()
ResourceEndpoint(String endpointUri, org.apache.camel.Component component, String resourceUri)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearContentCache()
String
getCamelId()
String
getCamelManagementName()
InputStream
getResourceAsInputStream()
Gets the resource as an input stream considering the cache flag as well.protected InputStream
getResourceAsInputStreamWithoutCache()
String
getResourceUri()
String
getState()
boolean
isAllowContextMapAll()
boolean
isContentCache()
boolean
isContentCacheCleared()
protected InputStream
loadResource(String uri)
Loads the given resource.void
setAllowContextMapAll(boolean allowContextMapAll)
Sets whether the context map should allow access to all details.void
setContentCache(boolean contentCache)
Sets whether to use resource content cache or not.void
setResourceUri(String resourceUri)
Path to the resource.-
Methods inherited from class org.apache.camel.support.ProcessorEndpoint
createPollingConsumer, createProcessor, createProducer, getProcessor, onExchange, setProcessor
-
Methods inherited from class org.apache.camel.support.DefaultPollingEndpoint
createConsumer
-
Methods inherited from class org.apache.camel.support.ScheduledPollEndpoint
configureConsumer, configureProperties, configureScheduledPollConsumerProperties, doConfigureConsumer, doStart, doStop, getBackoffErrorThreshold, getBackoffIdleThreshold, getBackoffMultiplier, getDefaultDelay, getDelay, getInitialDelay, getPollStrategy, getRepeatCount, getRunLoggingLevel, getScheduledExecutorService, getScheduler, getSchedulerProperties, getTimeUnit, isGreedy, isSendEmptyMessageWhenIdle, isStartScheduler, isUseFixedDelay, setBackoffErrorThreshold, setBackoffIdleThreshold, setBackoffMultiplier, setDelay, setGreedy, setInitialDelay, setPollStrategy, setRepeatCount, setRunLoggingLevel, setScheduledExecutorService, setScheduler, setSchedulerProperties, setSendEmptyMessageWhenIdle, setStartScheduler, setTimeUnit, setUseFixedDelay
-
Methods inherited from class org.apache.camel.support.DefaultEndpoint
configureExchange, configurePollingConsumer, createAsyncProducer, createEndpointUri, createExchange, createExchange, doInit, equals, getCamelContext, getComponent, getEndpointKey, getEndpointUri, getExceptionHandler, getExchangePattern, getId, getPollingConsumerBlockTimeout, getPollingConsumerQueueSize, hashCode, isAutowiredEnabled, isBridgeErrorHandler, isLazyStartProducer, isLenientProperties, isPollingConsumerBlockWhenFull, isPollingConsumerCopy, isSingleton, setAutowiredEnabled, setBridgeErrorHandler, setCamelContext, setComponent, setEndpointUri, setEndpointUriIfNotSpecified, setExceptionHandler, setExchangePattern, setLazyStartProducer, setPollingConsumerBlockTimeout, setPollingConsumerBlockWhenFull, setPollingConsumerCopy, setPollingConsumerQueueSize, setProperties, toString
-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
getResourceAsInputStream
public InputStream getResourceAsInputStream() throws IOException
Gets the resource as an input stream considering the cache flag as well. If cache is enabled then the resource content is cached in an internal buffer and this content is returned to avoid loading the resource over and over again.- Returns:
- the input stream
- Throws:
IOException
- is thrown if error loading the content of the resource to the local cache buffer
-
getResourceAsInputStreamWithoutCache
protected InputStream getResourceAsInputStreamWithoutCache() throws IOException
- Throws:
IOException
-
loadResource
protected InputStream loadResource(String uri) throws IOException
Loads the given resource.- Parameters:
uri
- uri of the resource.- Returns:
- the loaded resource
- Throws:
IOException
- is thrown if resource is not found or cannot be loaded
-
isContentCache
@ManagedAttribute(description="Whether the resource is cached") public boolean isContentCache()
- Specified by:
isContentCache
in interfaceorg.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
-
clearContentCache
@ManagedOperation(description="Clears the cached resource, forcing to re-load the resource on next request") public void clearContentCache()
- Specified by:
clearContentCache
in interfaceorg.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
-
isContentCacheCleared
public boolean isContentCacheCleared()
-
isAllowContextMapAll
@ManagedAttribute(description="Whether the context map is limited to only include the message body and headers") public boolean isAllowContextMapAll()
-
setAllowContextMapAll
public void setAllowContextMapAll(boolean allowContextMapAll)
Sets whether the context map should allow access to all details. By default only the message body and headers can be accessed. This option can be enabled for full access to the current Exchange and CamelContext. Doing so impose a potential security risk as this opens access to the full power of CamelContext API.
-
getCamelId
@ManagedAttribute(description="Camel context ID") public String getCamelId()
- Specified by:
getCamelId
in interfaceorg.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
-
getCamelManagementName
@ManagedAttribute(description="Camel ManagementName") public String getCamelManagementName()
- Specified by:
getCamelManagementName
in interfaceorg.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
-
getState
@ManagedAttribute(description="Endpoint service state") public String getState()
- Specified by:
getState
in interfaceorg.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
-
setContentCache
public void setContentCache(boolean contentCache)
Sets whether to use resource content cache or not.- Specified by:
setContentCache
in interfaceorg.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
-
getResourceUri
public String getResourceUri()
-
setResourceUri
public void setResourceUri(String resourceUri)
Path to the resource. You can prefix with: classpath, file, http, ref, or bean. classpath, file and http loads the resource using these protocols (classpath is default). ref will lookup the resource in the registry. bean will call a method on a bean to be used as the resource. For bean you can specify the method name after dot, eg bean:myBean.myMethod- Parameters:
resourceUri
- the resource path
-
-