Author: thorsten
Date: Sat Jul 20 16:21:54 2013
New Revision: 1505158
URL: http://svn.apache.org/r1505158
Log:
COCOON3-129 adding basic example
Added:
cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/java/org/apache/cocoon/rest/optional/sample/SendMailService.java
cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/COB-INF/js/mail.js
cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/properties/
cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/properties/mail.properties
Modified:
cocoon/cocoon3/trunk/cocoon-rest-optional/pom.xml
cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/COB-INF/welcome.html
cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/spring/block-application-context.xml
cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/spring/block-servlet-service.xml
Modified: cocoon/cocoon3/trunk/cocoon-rest-optional/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest-optional/pom.xml?rev=1505158&r1=1505157&r2=1505158&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest-optional/pom.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-rest-optional/pom.xml Sat Jul 20 16:21:54 2013
@@ -138,5 +138,17 @@
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
</dependencies>
</project>
Added: cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/java/org/apache/cocoon/rest/optional/sample/SendMailService.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/java/org/apache/cocoon/rest/optional/sample/SendMailService.java?rev=1505158&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/java/org/apache/cocoon/rest/optional/sample/SendMailService.java (added)
+++ cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/java/org/apache/cocoon/rest/optional/sample/SendMailService.java Sat Jul 20 16:21:54 2013
@@ -0,0 +1,89 @@
+/*
+ * 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.cocoon.rest.optional.sample;
+
+import java.util.Date;
+
+import org.apache.cocoon.rest.controller.annotation.RESTController;
+import org.apache.cocoon.rest.controller.annotation.RequestParameter;
+import org.apache.cocoon.rest.controller.method.Post;
+import org.apache.cocoon.rest.controller.response.RestResponse;
+import org.apache.cocoon.rest.controller.response.TextResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mail.MailException;
+import org.springframework.mail.MailSender;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.util.StringUtils;
+
+@RESTController
+public class SendMailService implements Post {
+ @RequestParameter
+ private String to;
+ @RequestParameter
+ private String from;
+ @RequestParameter
+ private String subject;
+ @RequestParameter
+ private String text;
+ @Autowired
+ private MailSender mailSender;
+ @Autowired
+ private SimpleMailMessage templateMessage;
+ /**
+ * Logger.
+ */
+ private static final Logger logger = LoggerFactory
+ .getLogger(SendMailService.class);
+
+ @Override
+ public RestResponse doPost() throws Exception {
+ if (sendMail()) {
+ return new TextResponse("{\"status\":" + true + " }", "application/json");
+ }
+ return new TextResponse("{\"status\":" + false + " }", "application/json");
+ }
+
+ private boolean sendMail() {
+ SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
+ if(!StringUtils.isEmpty(to)){
+ this.templateMessage.setTo(to);
+ }
+ if(!StringUtils.isEmpty(from)){
+ this.templateMessage.setFrom(from);
+ }
+ if(!StringUtils.isEmpty(subject)){
+ this.templateMessage.setSubject(subject);
+ }
+ if(!StringUtils.isEmpty(text)){
+ this.templateMessage.setText(text);
+ }
+ msg.setSentDate(new Date());
+ try {
+ this.mailSender.send(msg);
+ return true;
+ } catch (MailException ex) {
+ logger.error(String.format(
+ "Could not send Mail!\n%s", msg.toString()), ex);
+ return false;
+ }
+ }
+
+}
Added: cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/COB-INF/js/mail.js
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/COB-INF/js/mail.js?rev=1505158&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/COB-INF/js/mail.js (added)
+++ cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/COB-INF/js/mail.js Sat Jul 20 16:21:54 2013
@@ -0,0 +1,45 @@
+/*
+* 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.
+*/
+var onMailSend = function(data){
+ $("#serverResponse").html("Result: " + data.status);
+ //Emabling button
+ $("#sendMail").removeAttr('disabled');
+};
+
+$(document).ready(function(){
+ //Button click event
+ $("#sendMail").click(function(e){
+ $("#serverResponse").html("Processing request...");
+ e.preventDefault();
+ //Disabling button
+ $("#sendMail").attr('disabled', 'disabled');
+ // get the input data
+ var to = $("#mailto").val();
+ var from = $("#mailfrom").val();
+ var subject = $("#mailsubject").val();
+ var text = $("#mailtext").val();
+ //Perform POST for triggering long running sendMail
+ $.post('rest/SendMailService', {
+ from: from,
+ to: to,
+ text: text,
+ subject: subject
+ }, function(data){
+ onMailSend(data);
+ }, "json");
+ });
+});
Modified: cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/COB-INF/welcome.html
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/COB-INF/welcome.html?rev=1505158&r1=1505157&r2=1505158&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/COB-INF/welcome.html (original)
+++ cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/COB-INF/welcome.html Sat Jul 20 16:21:54 2013
@@ -1,41 +1,62 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<!--
-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.
---><!-- $Id: welcome.html 642116 2008-03-28 08:00:47Z reinhard $ -->
+<!DOCTYPE html>
+<!-- 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. --><!-- $Id: welcome.html 642116 2008-03-28 08:00:47Z reinhard $ -->
<html>
- <head>
- <title>cocoon-rest-optional show case</title>
- <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
- <script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js">
- </script>
- <script type="text/javascript" charset="utf-8" src="js/progress.js">
- </script>
- </head>
- <body>
- <h1>Progressbar based on jquery</h1>
- <div class="widget">
- <h1>Progess</h1>
- <form action="rest/ProgressService" method="post" id="ProgressServiceForm">
- <input id="operation" type="submit">
- <div id="ProgressServiceFormResult">
- <p id="header">
- </p>
- <div id="progressbar" style="width:500px">
- </div>
- </div>
- </form>
- </div>
- </body>
+ <head>
+ <title>cocoon-rest-optional show cases</title>
+ <link
+ href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css"
+ rel="stylesheet" type="text/css" />
+ <script
+ src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
+ <script type="text/javascript" charset="utf-8"
+ src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js">
+ </script>
+ <script type="text/javascript" charset="utf-8" src="js/progress.js">
+ </script>
+ <script type="text/javascript" charset="utf-8" src="js/mail.js">
+ </script>
+ </head>
+ <body>
+ <h1>show cases</h1>
+ <div id="progess">
+ <h2>show case: ProgressBar</h2>
+ <p>Shows how to write and read the state of a long running process with REST and servletContext attributes.</p>
+ <div class="widget">
+ <form action="rest/ProgressService" method="post"
+ id="ProgressServiceForm">
+ <input id="operation" type="submit" />
+ <div id="ProgressServiceFormResult">
+ <p id="header">
+ </p>
+ <div id="progressbar" style="width:500px">
+ </div>
+ </div>
+ </form>
+ </div>
+ </div>
+ <div id="mail">
+ <h2>show case: sendMail</h2>
+ <p>Show how to send a simple eMail with cocoon. Make sure you have adopted the mail.properties to your setup otherwise it will not work.</p>
+ <div id="form">
+ <form action="rest/SendMailService" method="post">
+ <input type="email" name="from" id="mailfrom" placeholder="[email protected]" />
+ <input type="email" name="to" id="mailto" placeholder="[email protected]" />
+ <input type="text" name="subject" id="mailsubject" placeholder="new show case sendMail" />
+ <textarea name="text" id="mailtext" rows="4" cols="50" placeholder="Try the new send mail demo with cocoon REST!">
+</textarea>
+ <input id="sendMail" type="submit" value="Submit" />
+ </form>
+ </div>
+ <div id="serverResponse">Here comes the response from server...</div>
+ </div>
+ </body>
</html>
Added: cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/properties/mail.properties
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/properties/mail.properties?rev=1505158&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/properties/mail.properties (added)
+++ cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/properties/mail.properties Sat Jul 20 16:21:54 2013
@@ -0,0 +1,26 @@
+# 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.
+
+email.from=noreply@{yourHost}
+email.to=to@{yourHost}
+# e.g. gmail config
+# note the email.host.username will always be the from in the email header,
+# regardless what you set above
+email.host=smtp.gmail.com
+email.host.port=587
+email.host.username={yourId}@gmail.com
+email.host.password={yourPassword}
+email.smtp.auth=true
+email.smtp.starttls.enable=true
\ No newline at end of file
Modified: cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/spring/block-application-context.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/spring/block-application-context.xml?rev=1505158&r1=1505157&r2=1505158&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/spring/block-application-context.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/spring/block-application-context.xml Sat Jul 20 16:21:54 2013
@@ -28,4 +28,26 @@
expression="org.apache.cocoon.rest.controller.annotation.RESTController" />
</context:component-scan>
<context:annotation-config />
+ <!-- MAIL -->
+ <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
+ <property name="host" value="${email.host}" />
+ <property name="username" value="${email.host.username}" />
+ <property name="password" value="${email.host.password}" />
+ <property name="javaMailProperties">
+ <props>
+ <prop key="mail.smtp.auth">${email.smtp.auth}</prop>
+ <prop key="mail.smtp.starttls.enable">${email.smtp.starttls.enable}</prop>
+ </props>
+ </property>
+ </bean>
+
+ <!-- this is a template message that we can pre-load with default state -->
+ <bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage">
+ <property name="from" value="${email.from}" />
+ <!-- you can set default values -->
+ <property name="subject" value="Testing" />
+ <property name="to" value="${email.to}" />
+ <!-- you can set default values -->
+ <property name="text" value="Testing" />
+ </bean>
</beans>
Modified: cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/spring/block-servlet-service.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/spring/block-servlet-service.xml?rev=1505158&r1=1505157&r2=1505158&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/spring/block-servlet-service.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-rest-optional/src/main/resources/META-INF/cocoon/spring/block-servlet-service.xml Sat Jul 20 16:21:54 2013
@@ -25,7 +25,7 @@
http://cocoon.apache.org/schema/servlet http://cocoon.apache.org/schema/servlet/cocoon-servlet-1.0.xsd">
<bean name="org.cocoon.rest.optional.cocoon-rest-optional.service" class="org.apache.cocoon.servlet.XMLSitemapServlet">
- <servlet:context mount-path="" context-path="jar:classpath:lib/${project.build.finalName}.jar!/COB-INF/"/>
+ <servlet:context mount-path="cocoon-rest-optional" context-path="jar:classpath:lib/${project.build.finalName}.jar!/COB-INF/"/>
</bean>
</beans>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.