Class 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 Detail

      • log

        protected final org.slf4j.Logger log
    • Constructor Detail

      • ResourceEndpoint

        public ResourceEndpoint()
      • ResourceEndpoint

        public ResourceEndpoint​(String endpointUri,
                                org.apache.camel.Component component,
                                String resourceUri)
    • 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
      • 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 interface org.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 interface org.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 interface org.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
      • getCamelManagementName

        @ManagedAttribute(description="Camel ManagementName")
        public String getCamelManagementName()
        Specified by:
        getCamelManagementName in interface org.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
      • getState

        @ManagedAttribute(description="Endpoint service state")
        public String getState()
        Specified by:
        getState in interface org.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 interface org.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