当前位置: 首页 > 知识库问答 >
问题:

使用Apache Camel和Restlet获得API

詹杰
2023-03-14

我正在做一个非常简单的Fuse集成应用程序,它从一个应用编程接口网站(斯托克霍姆斯斯塔德的数据门户)获取一个XML。我正在使用Apache Camel将“从”应用编程接口网址中”路由到“一个新的单词文档文件”。我这里有两个文件是Spring XMLcamel.context.xml文件和依赖项的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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">
    <camelContext id="camel-fuse-api" xmlns="http://camel.apache.org/schema/spring">
        <route id="api2fuse">
            <!-- Input from Rest API -->
            <!-- Process the XML from the Rest API -->
            <!-- Output to a text file (TESTING the route) -->
            <from id="_from1" uri="restlet:http:80://data.stockholm.se/set/Befolkning/Befforandr/?apikey=<api-key>?restletMethod=GET"/>
            <to id="_to1" uri="file://C:/<localfile>?fileName=test_new_xml.txt"/>
            <log id="_log1" message="XML was copied to the local folder in a .txt file"/>
        </route>
    </camelContext>
    <bean class="org.restlet.Component" id="RestletComponent"/>
    <bean class="org.apache.camel.component.restlet.RestletComponent" id="RestletComponentService">
        <constructor-arg index="0">
            <ref bean="RestletComponent"/>
        </constructor-arg>
    </bean>
</beans>

pom。xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.cgi.fuse</groupId>
  <artifactId>camel-spring</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>bundle</packaging>
  <name>Fuse API</name>
  <description>Fuse integration for API</description>
  <licenses>
    <license>
      <name>Apache License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  <properties>
    <camel.version>2.17.0.redhat-630187</camel.version>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <version.maven-bundle-plugin>2.1.0</version.maven-bundle-plugin>
    <jboss.fuse.bom.version>6.3.0.redhat-187</jboss.fuse.bom.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <restlet.version>2.1.7</restlet.version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jboss.fuse.bom</groupId>
        <artifactId>jboss-fuse-parent</artifactId>
        <version>${jboss.fuse.bom.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-spring</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-stream</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-test-spring</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.activemq</groupId>
      <artifactId>activemq-camel</artifactId>
      <version>5.11.0.redhat-630187</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-jms</artifactId>
      <version>2.17.0.redhat-630187</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-cxf</artifactId>
      <version>2.17.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-restlet</artifactId>
      <version>2.17.0</version>
    </dependency>
    <dependency>
      <groupId>org.restlet.jee</groupId>
      <artifactId>org.restlet.ext.spring</artifactId>
      <version>2.2.0</version>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>fuse-public-repository</id>
      <name>FuseSource Community Release Repository</name>
      <url>https://repo.fusesource.com/nexus/content/groups/public</url>
    </repository>
    <repository>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>red-hat-ga-repository</id>
      <name>Red Hat GA Repository</name>
      <url>https://maven.repository.redhat.com/ga</url>
    </repository>
    <repository>  
   <id>maven-restlet</id>  
   <name>Public online Restlet repository</name>  
   <url>http://maven.restlet.org</url>  
</repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>fuse-public-repository</id>
      <name>FuseSource Community Release Repository</name>
      <url>https://repo.fusesource.com/nexus/content/groups/public</url>
    </pluginRepository>
    <pluginRepository>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>red-hat-ga-repository</id>
      <name>Red Hat GA Repository</name>
      <url>https://maven.repository.redhat.com/ga</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <defaultGoal>install</defaultGoal>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>${version.maven-bundle-plugin}</version>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Bundle-SymbolicName>Fuse</Bundle-SymbolicName>
            <Bundle-Name>Empty Camel Spring Example [Fuse]</Bundle-Name>
          </instructions>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.1</version>
        <configuration>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-maven-plugin</artifactId>
        <version>${camel.version}</version>
        <configuration>
          <fileApplicationContextUri>src/main/resources/META-INF/spring/camel-context.xml</fileApplicationContextUri>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

我正在JBoss Developer Studio 10.1.0 GA上的“jboss-fuse-6.3.0.redhat-187”运行时服务器上运行项目。我启动了服务器,但没有创建文件。它不起作用,我认为这是代码中的一些错误语法。

共有1个答案

马坚
2023-03-14

如果要调用外部现有的REST服务,需要从计时器开始。

from timer
   to restlet
   to file

你用什么做什么

from restlet

如果您自己托管新的REST服务,则打算使用。

使用计时器,您需要了解您希望调用现有REST服务的频率。定时器有一些选项,你可以为此进行配置。

 类似资料:
  • 问题内容: 这是我的代码,用于限制分钟的请求数: 问题是没有错误,但是即使从资源请求了10个以上的请求,它也不会抛出“ Too Many Request” 问题答案: 我使用GAE项目中的配置代码以及开发服务器来使其工作。 我使用Restlet的2.3.1版本/ GAE的1.9.18版本以及以下代码作为客户端: 在第10次通话后,我遇到以下异常: 希望对您有帮助,蒂埃里

  • 我正在尝试向异步路由发送消息,但它不起作用。我刚刚在github上创建了一个项目来模拟这个问题

  • 一个用Java实现的轻量级REST框架 开放核心是一个中间件抽象层,允许子系统和应用程序直接无缝地运行在Java虚拟机上或各种J2EE应用程序服务器中。它支持所有REST概念(资源、表示、连接器、组件等),并且适合于客户机和服务器Web应用程序。它支持主要的Web标准,如HTTP、SMTP、XML、JSON、WADL和Atom。还有许多扩展可用于与Servlet、Spring、Jetty、Griz

  • 我想测试以下骆驼路线。我在网上找到的所有例子都有以文件开头的路由,在我的例子中,我有一个Springbean方法,每隔几分钟就会被调用一次,最后消息被转换并移动到jms以及审计目录。 我对这条路线的写测试毫无头绪。目前我在测试用例中所拥有的是

  • 我正在使用apache camel cxf开发一个Web服务(肥皂),我遇到了这个错误。 Java . lang . illegalargumentexception:Part { http://blue print . camel . ngt . TN/}返回的类型应为[ltn . ngt . camel . blue print . WB _ subscriptions;,而不是org . A