Class LanguageEndpoint

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
org.apache.camel.component.language.LanguageEndpoint
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

@UriEndpoint(firstVersion="2.5.0", scheme="language", title="Language", syntax="language:languageName:resourceUri", producerOnly=true, category={CORE,SCRIPT}, headersClass=LanguageConstants.class) public class LanguageEndpoint extends org.apache.camel.component.ResourceEndpoint
Execute scripts in any of the languages supported by Camel. By having a component to execute language scripts, it allows more dynamic routing capabilities. For example by using the Routing Slip or Dynamic Router EIPs you can send messages to language endpoints where the script is dynamic defined as well.
  • Field Summary

    Fields inherited from class org.apache.camel.component.ResourceEndpoint

    log

    Fields inherited from class org.apache.camel.support.service.BaseService

    BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    LanguageEndpoint(String endpointUri, org.apache.camel.Component component, org.apache.camel.spi.Language language, org.apache.camel.Expression expression, String resourceUri)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    org.apache.camel.Consumer
    createConsumer(org.apache.camel.Processor processor)
     
    protected String
     
    org.apache.camel.Producer
     
    protected void
     
    org.apache.camel.Expression
     
    org.apache.camel.spi.Language
     
     
     
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    protected String
    Resolves the script.
    void
    setBinary(boolean binary)
    Whether the script is binary content or text content.
    void
    setCacheScript(boolean cacheScript)
    Whether to cache the compiled script and reuse
    void
    setContentResolvedFromResource(boolean contentResolvedFromResource)
     
    void
    setExpression(org.apache.camel.Expression expression)
     
    void
    setLanguageName(String languageName)
    Sets the name of the language to use
    void
    setResourceUri(String resourceUri)
    Path to the resource, or a reference to lookup a bean in the Registry to use as the resource
    void
    setResultType(String resultType)
    Sets the class of the result type (type from output)
    void
    setScript(String script)
    Sets the script to execute
    void
    setTransform(boolean transform)
    Whether or not the result of the script should be used as message body.

    Methods inherited from class org.apache.camel.component.ResourceEndpoint

    getCamelId, getCamelManagementName, getResourceAsInputStream, getResourceAsInputStreamWithoutCache, getState, isAllowContextMapAll, isContentCache, isContentCacheCleared, loadResource, setAllowContextMapAll, setContentCache

    Methods inherited from class org.apache.camel.support.ProcessorEndpoint

    createPollingConsumer, createProcessor, getProcessor, onExchange, setProcessor

    Methods inherited from class org.apache.camel.support.ScheduledPollEndpoint

    configureConsumer, configureProperties, configureScheduledPollConsumerProperties, doConfigureConsumer, 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, createExchange, createExchange, 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, doStart, doStop, 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

    Methods inherited from interface org.apache.camel.Endpoint

    getEndpointBaseUri, isSingletonProducer

    Methods inherited from interface org.apache.camel.Service

    build, close, init, start, stop

    Methods inherited from interface org.apache.camel.ShutdownableService

    shutdown

    Methods inherited from interface org.apache.camel.StatefulService

    getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending

    Methods inherited from interface org.apache.camel.SuspendableService

    isSuspended, resume, suspend
  • Constructor Details

    • LanguageEndpoint

      public LanguageEndpoint()
    • LanguageEndpoint

      public LanguageEndpoint(String endpointUri, org.apache.camel.Component component, org.apache.camel.spi.Language language, org.apache.camel.Expression expression, String resourceUri)
  • Method Details

    • doInit

      protected void doInit() throws Exception
      Overrides:
      doInit in class org.apache.camel.support.DefaultEndpoint
      Throws:
      Exception
    • createProducer

      public org.apache.camel.Producer createProducer() throws Exception
      Specified by:
      createProducer in interface org.apache.camel.Endpoint
      Overrides:
      createProducer in class org.apache.camel.support.ProcessorEndpoint
      Throws:
      Exception
    • createConsumer

      public org.apache.camel.Consumer createConsumer(org.apache.camel.Processor processor) throws Exception
      Specified by:
      createConsumer in interface org.apache.camel.Endpoint
      Overrides:
      createConsumer in class org.apache.camel.support.DefaultPollingEndpoint
      Throws:
      Exception
    • resolveScript

      protected String resolveScript(String script) throws IOException
      Resolves the script.
      Parameters:
      script - script or uri for a script to load
      Returns:
      the script
      Throws:
      IOException - is thrown if error loading the script
    • createEndpointUri

      protected String createEndpointUri()
      Overrides:
      createEndpointUri in class org.apache.camel.support.DefaultEndpoint
    • getLanguage

      public org.apache.camel.spi.Language getLanguage()
    • getExpression

      public org.apache.camel.Expression getExpression()
    • setExpression

      public void setExpression(org.apache.camel.Expression expression)
    • isTransform

      public boolean isTransform()
    • setTransform

      public void setTransform(boolean transform)
      Whether or not the result of the script should be used as message body.

      This options is default true.

      Parameters:
      transform - true to use result as new message body, false to keep the existing message body
    • isBinary

      public boolean isBinary()
    • setBinary

      public void setBinary(boolean binary)
      Whether the script is binary content or text content.

      By default the script is read as text content (eg java.lang.String)

      Parameters:
      binary - true to read the script as binary, instead of text based.
    • setLanguageName

      public void setLanguageName(String languageName)
      Sets the name of the language to use
      Parameters:
      languageName - the name of the language
    • setResourceUri

      public void setResourceUri(String resourceUri)
      Path to the resource, or a reference to lookup a bean in the Registry to use as the resource
      Overrides:
      setResourceUri in class org.apache.camel.component.ResourceEndpoint
      Parameters:
      resourceUri - the resource path
    • getResourceUri

      public String getResourceUri()
      Overrides:
      getResourceUri in class org.apache.camel.component.ResourceEndpoint
    • setScript

      public void setScript(String script)
      Sets the script to execute
      Parameters:
      script - the script
    • getScript

      public String getScript()
    • isContentResolvedFromResource

      public boolean isContentResolvedFromResource()
    • setContentResolvedFromResource

      public void setContentResolvedFromResource(boolean contentResolvedFromResource)
    • isCacheScript

      public boolean isCacheScript()
    • setCacheScript

      public void setCacheScript(boolean cacheScript)
      Whether to cache the compiled script and reuse

      Notice reusing the script can cause side effects from processing one Camel Exchange to the next Exchange.

    • getResultType

      public String getResultType()
    • setResultType

      public void setResultType(String resultType)
      Sets the class of the result type (type from output)
    • clearContentCache

      public void clearContentCache()
      Specified by:
      clearContentCache in interface org.apache.camel.api.management.mbean.ManagedResourceEndpointMBean
      Overrides:
      clearContentCache in class org.apache.camel.component.ResourceEndpoint