title: Bind aws sqs region camel
body: <p>So I'm trying to access to the simple queue service with apache camel. </p>
  
  <p>Java DSL approach works fine, but I try to work with xml configuration. </p>
  
  <pre><code>private AmazonSQS sqs;
  sqs = new AmazonSQSClient(credentials);
  Region sqsRegion = Region.getRegion(Regions.US_WEST_2);
  sqs.setRegion(sqsRegion);
  </code></pre>
  
  <p>The code above works fine, but i decided to build bean.</p>
  
  <pre><code>&lt;context:property-placeholder  location="classpath:/default.properties" /&gt;
      &lt;bean name="sqsClient" class="com.amazonaws.services.sqs.AmazonSQSClient"&gt;
          &lt;constructor-arg&gt;
              &lt;bean class="com.amazonaws.auth.BasicAWSCredentials"&gt;
                  &lt;constructor-arg value="${access.key}"/&gt;
                  &lt;constructor-arg value="${secret.key}"/&gt;
              &lt;/bean&gt;
          &lt;/constructor-arg&gt;
          &lt;property name="region" value="com.amazonaws.regions.Region"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>And I got an error </p>
  
  <blockquote>
    <p>Failed to convert property value of type [java.lang.String] to
    required type [com.amazonaws.regions.Region] for property 'region';
    nested exception is java.lang.IllegalStateException: Cannot convert
    value of type [java.lang.String] to required type
    [com.amazonaws.regions.Region] for property 'region': no matching
    editors or conversion strategy found</p>
  </blockquote>
  
  <p>I haven't found anything about configuration sqs via Spring xml. And sometimes I think that apache camel is outdated or nobody uses it with sqs. 
  Moreover the next step is to connect Extended SQS library that works fine in Java DSL implementation, but I have no idea how to configure queue via xml.</p>
  
  <p><strong>UPD:</strong></p>
  
  <p>Thanks to @jbird, I solved the problem in this way:</p>
  
  <pre><code>&lt;context:property-placeholder  location="classpath:/default.properties" /&gt;
      &lt;bean id="awsRegion" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt;
          &lt;property name="targetClass" value="com.amazonaws.regions.RegionUtils"/&gt;
          &lt;property name="targetMethod" value="getRegion"/&gt;
          &lt;property name="arguments"&gt;
              &lt;list&gt;
                  &lt;value&gt;${aws.region}&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean name="sqsClient" class="com.amazonaws.services.sqs.AmazonSQSClient"&gt;
          &lt;constructor-arg&gt;
              &lt;bean class="com.amazonaws.auth.BasicAWSCredentials"&gt;
                  &lt;constructor-arg value="${access.key}"/&gt;
                  &lt;constructor-arg value="${secret.key}"/&gt;
              &lt;/bean&gt;
          &lt;/constructor-arg&gt;
          &lt;property name="region" ref="awsRegion"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>So, I just parsed my <code>default.properties</code> file that contains aws.key, aws.secret and region settings.</p>
  
  <p>And I got the next problem. Apache camel stop running after loading routers and so on. </p>
  
  <pre><code>[                          main] SpringCamelContext             INFO  Route: route1 started and consuming from: Endpoint[aws-sqs://queue?amazonSQSClient=%23sqsClient]
  [                          main] SpringCamelContext             INFO  Total 1 routes, of which 1 are started.
  [                          main] SpringCamelContext             INFO  Apache Camel 2.17.2 (CamelContext: camel-1) started in 6.105 seconds
  
  Process finished with exit code 0
  </code></pre>
  
  <p>Router: </p>
  
  <pre><code>import org.apache.camel.builder.RouteBuilder;
  import org.springframework.stereotype.Component;
  
  @Component
  public class MyRouteBuilder extends RouteBuilder {
  
      public void configure() {
          from("aws-sqs://queue?amazonSQSClient=#sqsClient")
                  .log("We have a message! ${body}")
                  .to("file:target/output?fileName=login-message-${date:now:MMDDyy-HHmmss}.json");
      }
  }
  </code></pre>
  
  <p>And the camel-context.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
             http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
         "&gt;
  
      &lt;context:property-placeholder  location="classpath:/default.properties" /&gt;
  
      &lt;bean id="awsRegion" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt;
          &lt;property name="targetClass" value="com.amazonaws.regions.RegionUtils"/&gt;
          &lt;property name="targetMethod" value="getRegion"/&gt;
          &lt;property name="arguments"&gt;
              &lt;list&gt;
                  &lt;value&gt;${aws.region}&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean name="sqsClient" class="com.amazonaws.services.sqs.AmazonSQSClient"&gt;
          &lt;constructor-arg&gt;
              &lt;bean class="com.amazonaws.auth.BasicAWSCredentials"&gt;
                  &lt;constructor-arg value="${access.key}"/&gt;
                  &lt;constructor-arg value="${secret.key}"/&gt;
              &lt;/bean&gt;
          &lt;/constructor-arg&gt;
          &lt;property name="region" ref="awsRegion"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- enable Spring @Component scan --&gt;
      &lt;context:component-scan base-package="com.test.router"/&gt;
  
      &lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
  
          &lt;contextScan/&gt;
      &lt;/camelContext&gt;
  
  &lt;/beans&gt;
  </code></pre>