Wednesday, December 7, 2011

svn commit: r1211485 - in /labs/magnet/core: ./ src/main/java/org/apache/labs/magnet/bbs/ src/main/java/org/apache/labs/magnet/service/ src/main/resources/META-INF/spring/ src/test/java/org/apache/labs/magnet/core/

Author: hadrian
Date: Wed Dec 7 15:57:30 2011
New Revision: 1211485

URL: http://svn.apache.org/viewvc?rev=1211485&view=rev
Log:
Added cxf rest service

Added:
labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/
labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/Bulletin.java
labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinBoard.java
labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinList.java
labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinProcessor.java
labs/magnet/core/src/main/java/org/apache/labs/magnet/service/
labs/magnet/core/src/main/java/org/apache/labs/magnet/service/BulletinBoardService.java
Modified:
labs/magnet/core/pom.xml
labs/magnet/core/src/main/resources/META-INF/spring/beans.xml
labs/magnet/core/src/test/java/org/apache/labs/magnet/core/RouteTest.java

Modified: labs/magnet/core/pom.xml
URL: http://svn.apache.org/viewvc/labs/magnet/core/pom.xml?rev=1211485&r1=1211484&r2=1211485&view=diff
==============================================================================
--- labs/magnet/core/pom.xml (original)
+++ labs/magnet/core/pom.xml Wed Dec 7 15:57:30 2011
@@ -58,6 +58,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-jetty</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
</dependency>
<dependency>
@@ -126,6 +130,12 @@
<version>${cxf.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${httpclient4.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>

<build>

Added: labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/Bulletin.java
URL: http://svn.apache.org/viewvc/labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/Bulletin.java?rev=1211485&view=auto
==============================================================================
--- labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/Bulletin.java (added)
+++ labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/Bulletin.java Wed Dec 7 15:57:30 2011
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.labs.magnet.bbs;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+@XmlRootElement(namespace = "http://labs.apache.org/magnet", name = "bulletin")
+@XmlType
+public class Bulletin {
+
+ private String id;
+ private String ref;
+ private String text;
+ private String summary;
+ private String description;
+
+ public Bulletin() {
+ this(null);
+ }
+
+ public Bulletin(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String toString() {
+ return "Bulletin [id=" + id + ", ref=" + ref + "]";
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getRef() {
+ return ref;
+ }
+
+ public void setRef(String ref) {
+ this.ref = ref;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getSummary() {
+ return summary;
+ }
+
+ public void setSummary(String summary) {
+ this.summary = summary;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}

Added: labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinBoard.java
URL: http://svn.apache.org/viewvc/labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinBoard.java?rev=1211485&view=auto
==============================================================================
--- labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinBoard.java (added)
+++ labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinBoard.java Wed Dec 7 15:57:30 2011
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.labs.magnet.bbs;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+import org.apache.cxf.jaxrs.ext.Oneway;
+
+
+@Path("/")
+@Produces({"text/xml", "application/xml"})
+@Consumes({"text/xml", "application/xml"})
+public interface BulletinBoard {
+
+ @GET
+ @Path("{id}")
+ Bulletin getBulletin(@PathParam("id") String id);
+
+ @POST
+ @Oneway
+ void addBulletin(Bulletin bulletin) throws Exception;
+
+ @GET
+ BulletinList listBulletins();
+}

Added: labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinList.java
URL: http://svn.apache.org/viewvc/labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinList.java?rev=1211485&view=auto
==============================================================================
--- labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinList.java (added)
+++ labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinList.java Wed Dec 7 15:57:30 2011
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.labs.magnet.bbs;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement(namespace = "http://labs.apache.org/magnet", name = "bulletin-list")
+@XmlType
+public class BulletinList {
+
+ Bulletin[] bulletin;
+
+ public Bulletin[] getBulletin() {
+ return bulletin;
+ }
+
+ public void setBulletin(Bulletin[] bulletin) {
+ this.bulletin = bulletin;
+ }
+}

Added: labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinProcessor.java
URL: http://svn.apache.org/viewvc/labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinProcessor.java?rev=1211485&view=auto
==============================================================================
--- labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinProcessor.java (added)
+++ labs/magnet/core/src/main/java/org/apache/labs/magnet/bbs/BulletinProcessor.java Wed Dec 7 15:57:30 2011
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.labs.magnet.bbs;
+
+
+public interface BulletinProcessor {
+
+ void process(Bulletin bulletin);
+}

Added: labs/magnet/core/src/main/java/org/apache/labs/magnet/service/BulletinBoardService.java
URL: http://svn.apache.org/viewvc/labs/magnet/core/src/main/java/org/apache/labs/magnet/service/BulletinBoardService.java?rev=1211485&view=auto
==============================================================================
--- labs/magnet/core/src/main/java/org/apache/labs/magnet/service/BulletinBoardService.java (added)
+++ labs/magnet/core/src/main/java/org/apache/labs/magnet/service/BulletinBoardService.java Wed Dec 7 15:57:30 2011
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.labs.magnet.service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.labs.magnet.bbs.Bulletin;
+import org.apache.labs.magnet.bbs.BulletinBoard;
+import org.apache.labs.magnet.bbs.BulletinList;
+import org.apache.labs.magnet.bbs.BulletinProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BulletinBoardService implements BulletinBoard {
+ private static final Logger LOG = LoggerFactory.getLogger(BulletinBoardService.class);
+
+ private BulletinProcessor processor;
+ private Map<String, Bulletin> store = new HashMap<String, Bulletin>();
+
+ public BulletinBoardService() {
+ }
+
+ @Override
+ public Bulletin getBulletin(String id) {
+ return store.get(id);
+ }
+
+ @Override
+ public void addBulletin(Bulletin bulletin) throws Exception {
+ String id = bulletin.getId();
+ LOG.info("Add message id=\"{}\"", id);
+ store.put(id, bulletin);
+ }
+
+ @Override
+ public BulletinList listBulletins() {
+ LOG.info("Currently holding {} messages.", store.size());
+ BulletinList answer = new BulletinList();
+ answer.setBulletin((Bulletin[])store.values().toArray(new Bulletin[]{}));
+ return answer;
+ }
+
+ public void setMessageListener(BulletinProcessor processor) {
+ this.processor = processor;
+ }
+}

Modified: labs/magnet/core/src/main/resources/META-INF/spring/beans.xml
URL: http://svn.apache.org/viewvc/labs/magnet/core/src/main/resources/META-INF/spring/beans.xml?rev=1211485&r1=1211484&r2=1211485&view=diff
==============================================================================
--- labs/magnet/core/src/main/resources/META-INF/spring/beans.xml (original)
+++ labs/magnet/core/src/main/resources/META-INF/spring/beans.xml Wed Dec 7 15:57:30 2011
@@ -63,12 +63,12 @@


<!-- Web Services -->
- <jaxrs:server address="camel://direct:shoutout" id="http-server">
- <jaxrs:serviceBeans><ref bean="shoutout" /></jaxrs:serviceBeans>
+ <jaxrs:server address="camel://direct:bbs" id="bbs-server">
+ <jaxrs:serviceBeans><ref bean="bbs-service" /></jaxrs:serviceBeans>
<jaxrs:inInterceptors><bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" /></jaxrs:inInterceptors>
</jaxrs:server>

- <bean id="shoutout" class="org.apache.labs.magnet.service.ShoutoutService" />
+ <bean id="bbs-service" class="org.apache.labs.magnet.service.BulletinBoardService" />

<!-- Camel configuration -->
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
@@ -82,6 +82,12 @@
<from uri="{{schedule.task}}" />
<to uri="log:task" />
</route>
+
+ <route id="bbs">
+ <from uri="jetty:http://0.0.0.0:9100/bbs?matchOnUriPrefix=true" />
+ <to uri="direct://bbs" />
+ </route>
+
</camelContext>

</beans>

Modified: labs/magnet/core/src/test/java/org/apache/labs/magnet/core/RouteTest.java
URL: http://svn.apache.org/viewvc/labs/magnet/core/src/test/java/org/apache/labs/magnet/core/RouteTest.java?rev=1211485&r1=1211484&r2=1211485&view=diff
==============================================================================
--- labs/magnet/core/src/test/java/org/apache/labs/magnet/core/RouteTest.java (original)
+++ labs/magnet/core/src/test/java/org/apache/labs/magnet/core/RouteTest.java Wed Dec 7 15:57:30 2011
@@ -17,6 +17,12 @@
package org.apache.labs.magnet.core;

import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

@@ -29,5 +35,19 @@ public class RouteTest extends CamelSpri

@Test
public void testRoute() throws Exception {
+ HttpPost post = new HttpPost("http://localhost:9100/bbs");
+ StringEntity entity = new StringEntity("<bulletin xmlns=\"http://labs.apache.org/magnet\"><id>CAMEL-1234</id><ref>http://camel.apache.org</ref></bulletin>", "UTF-8");
+ entity.setContentType("text/xml; charset=UTF-8");
+ post.setEntity(entity);
+ HttpClient httpclient = new DefaultHttpClient();
+
+ try {
+ HttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals("", EntityUtils.toString(response.getEntity()));
+ } finally {
+ httpclient.getConnectionManager().shutdown();
+ }
+ // Thread.sleep(5000);
}
}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org

No comments:

Post a Comment