2017-04-24 1 views
0

나는 API 웹 사이트 (Stockholms Stad의 데이터 포털)에서 XML을 취하는 매우 간단한 Fuse 통합 애플리케이션을 수행하고 있습니다. Apache Camel을 사용하여 "~"에서 새로운 단어 doc 파일로 "~"URL의 API URL 을 사용하고 있습니다. 내가 여기에있는 2 개 개의 파일은 봄 XML camel.context.xml 파일과 의존성에 대한 pom.xml 있습니다Apache Camel 및 Restlet을 사용하여 API 받기

<?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에 퓨즈에서 프로젝트를 실행 해요 6.3.0.redhat-187 "JBoss Developer Studio 10.1.0 GA의 런타임 서버. 서버를 시작했지만 파일이 작성되지 않았습니다. 작동하지 않고 코드에 잘못된 구문이 있다고 가정합니다.

답변

0

외부의 기존 REST 서비스를 호출하려면 타이머에서 시작해야합니다. 새 REST 서비스를 직접 호스팅하는 경우

from timer 
    to restlet 
    to file 

당신은

from restlet 

으로 무엇을위한 것입니다.

타이머를 사용하여 얼마나 자주 기존 REST 서비스를 호출할지 알아야합니다. 타이머에는이를 구성 할 수있는 옵션이 있습니다.

+0

아, 알겠습니다. 그래서 내가 이해할 수있는 것은 외부 REST 웹 서비스를 호출하는 것은 연결, 일종의 청취 또는 폴링을 시작하는 타이머가 필요하다는 것입니다. – teowey

+0

예, Camel 경로를 사용하는 경우. Java 코드에서 Camel 끝점을 호출하려면 ProducerTemplate (클라이언트 API)을 사용할 수 있습니다. 그러나 낙타 경로는 매우 자주 Camel과 함께 사용됩니다. –

+0

ProducerTemplate 설명서에는 끝점 간의 메시지 교환이 가능하다고 나와 있습니다. 나는 메시징의 개념에 익숙하지 않다. 내가 자바 코드를 작성하면 내가 호출하는 API와 로컬 호스트 끝점 사이에서 메시지 교환을 구현해야한다는 것을 의미합니까? 내가 원하는 새로운 단어 doc 파일을 생성 할 수 있도록 이것이 필요합니까? – teowey