- 浏览: 2543705 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Spring3 with Servlets
Actually, it is not Servlets. It is simple servlet. It is org.springframework.web.HttpRequestHandler.
The sample project is easyoauthprovider. I will put some core codes and configuration here.
Spring configuration files:
servlet-context.xml
<bean id="RequestTokenServlet" class="com.sillycat.easyoauthprovider.servlets.RequestTokenHttpRequestHandler" >
<property name="oauthProvider" ref="oauthProvider" />
<property name="oauthValidator" ref="oauthValidator" />
</bean>
The related oauthProvider and oauthValidator is configured in spring bean xml files.
The web configuration file web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:main-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>RequestTokenServlet</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RequestTokenServlet</servlet-name>
<url-pattern>/request_token</url-pattern>
</servlet-mapping>
The JAVA class RequestTokenHttpRequestHandler.java is as follow:
package com.sillycat.easyoauthprovider.servlets;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.oauth.OAuth;
import net.oauth.OAuthAccessor;
import net.oauth.OAuthConsumer;
import net.oauth.OAuthMessage;
import net.oauth.OAuthValidator;
import net.oauth.server.OAuthServlet;
import org.springframework.web.HttpRequestHandler;
import com.sillycat.easyoauthprovider.plugins.oauth.OAuthProvider;
public class RequestTokenHttpRequestHandler implements HttpRequestHandler {
private OAuthProvider oauthProvider;
private OAuthValidator oauthValidator;
public void setOauthProvider(OAuthProvider oauthProvider) {
this.oauthProvider = oauthProvider;
}
public void setOauthValidator(OAuthValidator oauthValidator) {
this.oauthValidator = oauthValidator;
}
public void handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
public void processRequest(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
try {
OAuthMessage requestMessage = OAuthServlet
.getMessage(request, null);
OAuthConsumer consumer = oauthProvider.getConsumer(requestMessage);
OAuthAccessor accessor = new OAuthAccessor(consumer);
oauthValidator.validateMessage(requestMessage, accessor);
{
// Support the 'Variable ACCESSOR Secret' extension
// described in http://oauth.pbwiki.com/AccessorSecret
String secret = requestMessage
.getParameter("oauth_accessor_secret");
if (secret != null) {
accessor.setProperty(OAuthConsumer.ACCESSOR_SECRET, secret);
}
}
// generate request_token and secret
oauthProvider.generateRequestToken(accessor);
response.setContentType("text/plain");
OutputStream out = response.getOutputStream();
OAuth.formEncode(OAuth.newList("oauth_token",
accessor.requestToken, "oauth_token_secret",
accessor.tokenSecret), out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Frankly speaking, it is part of the oauth sample project. I am still working on this.
references:
http://andykayley.blogspot.com/2007/11/how-to-inject-spring-beans-into.html
http://andykayley.blogspot.com/2008/06/how-to-inject-spring-beans-into.html
Actually, it is not Servlets. It is simple servlet. It is org.springframework.web.HttpRequestHandler.
The sample project is easyoauthprovider. I will put some core codes and configuration here.
Spring configuration files:
servlet-context.xml
<bean id="RequestTokenServlet" class="com.sillycat.easyoauthprovider.servlets.RequestTokenHttpRequestHandler" >
<property name="oauthProvider" ref="oauthProvider" />
<property name="oauthValidator" ref="oauthValidator" />
</bean>
The related oauthProvider and oauthValidator is configured in spring bean xml files.
The web configuration file web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:main-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>RequestTokenServlet</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RequestTokenServlet</servlet-name>
<url-pattern>/request_token</url-pattern>
</servlet-mapping>
The JAVA class RequestTokenHttpRequestHandler.java is as follow:
package com.sillycat.easyoauthprovider.servlets;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.oauth.OAuth;
import net.oauth.OAuthAccessor;
import net.oauth.OAuthConsumer;
import net.oauth.OAuthMessage;
import net.oauth.OAuthValidator;
import net.oauth.server.OAuthServlet;
import org.springframework.web.HttpRequestHandler;
import com.sillycat.easyoauthprovider.plugins.oauth.OAuthProvider;
public class RequestTokenHttpRequestHandler implements HttpRequestHandler {
private OAuthProvider oauthProvider;
private OAuthValidator oauthValidator;
public void setOauthProvider(OAuthProvider oauthProvider) {
this.oauthProvider = oauthProvider;
}
public void setOauthValidator(OAuthValidator oauthValidator) {
this.oauthValidator = oauthValidator;
}
public void handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
public void processRequest(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
try {
OAuthMessage requestMessage = OAuthServlet
.getMessage(request, null);
OAuthConsumer consumer = oauthProvider.getConsumer(requestMessage);
OAuthAccessor accessor = new OAuthAccessor(consumer);
oauthValidator.validateMessage(requestMessage, accessor);
{
// Support the 'Variable ACCESSOR Secret' extension
// described in http://oauth.pbwiki.com/AccessorSecret
String secret = requestMessage
.getParameter("oauth_accessor_secret");
if (secret != null) {
accessor.setProperty(OAuthConsumer.ACCESSOR_SECRET, secret);
}
}
// generate request_token and secret
oauthProvider.generateRequestToken(accessor);
response.setContentType("text/plain");
OutputStream out = response.getOutputStream();
OAuth.formEncode(OAuth.newList("oauth_token",
accessor.requestToken, "oauth_token_secret",
accessor.tokenSecret), out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Frankly speaking, it is part of the oauth sample project. I am still working on this.
references:
http://andykayley.blogspot.com/2007/11/how-to-inject-spring-beans-into.html
http://andykayley.blogspot.com/2008/06/how-to-inject-spring-beans-into.html
发表评论
-
Update Site will come soon
2021-06-02 04:10 1672I am still keep notes my tech n ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 424Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 430Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 367Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 445VPN Server 2020(2)Docker on Cen ... -
Nginx Deal with OPTIONS in HTTP Protocol
2020-02-15 01:33 348Nginx Deal with OPTIONS in HTTP ... -
PDF to HTML 2020(1)pdftohtml Linux tool or PDFBox
2020-01-29 07:37 400PDF to HTML 2020(1)pdftohtml Li ... -
Elasticsearch Cluster 2019(2)Kibana Issue or Upgrade
2020-01-12 03:25 713Elasticsearch Cluster 2019(2)Ki ... -
Spark Streaming 2020(1)Investigation
2020-01-08 07:19 293Spark Streaming 2020(1)Investig ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 289Hadoop Docker 2019 Version 3.2. ... -
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 237MongoDB 2019(3)Security and Aut ... -
MongoDB 2019(1)Install 4.2.1 Single and Cluster
2019-11-11 05:07 289MongoDB 2019(1) Follow this ht ... -
Monitor Tool 2019(1)Monit Installation and Usage
2019-10-17 08:22 321Monitor Tool 2019(1)Monit Insta ... -
Ansible 2019(1)Introduction and Installation on Ubuntu and CentOS
2019-10-12 06:15 308Ansible 2019(1)Introduction and ... -
Timezone and Time on All Servers and Docker Containers
2019-10-10 11:18 329Timezone and Time on All Server ... -
Kafka Cluster 2019(6) 3 Nodes Cluster on CentOS7
2019-10-05 23:28 276Kafka Cluster 2019(6) 3 Nodes C ... -
K8S Helm(1)Understand YAML and Kubectl Pod and Deployment
2019-10-01 01:21 318K8S Helm(1)Understand YAML and ... -
Rancher and k8s 2019(5)Private Registry
2019-09-27 03:25 355Rancher and k8s 2019(5)Private ... -
Jenkins 2019 Cluster(1)Version 2.194
2019-09-12 02:53 440Jenkins 2019 Cluster(1)Version ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 367Redis Cluster 2019(3)Redis Clus ...
相关推荐
4. Working with Spring Boot 5. Learning about Spring Boot Features 6. Moving to Production 7. Advanced Topics II. Getting Started 8. Introducing Spring Boot 9. System Requirements 9.1. Servlet ...
14.1.2. Using JSR-250’s @RolesAllowed with Spring Security 14.2. Using expressions for method-level security 14.2.1. Expressing method access rules 14.2.2. Filtering method inputs and outputs 14.3. ...
例如,Java EE (现称Jakarta EE)逐渐转向更加轻量级、模块化的框架,如Spring Boot,同时保留了其核心优势,为企业级应用提供了更为灵活的选择。 #### 六、总结 《使用J2EE平台设计企业应用》第二版是一本全面介绍...
4. **常用技术和框架**:重点介绍了在Java EE开发中常用的多种技术和框架,如Servlets、JSP、EJB、Spring、Hibernate等。 5. **最佳实践**:分享了一些开发Java EE应用程序的最佳实践和技术建议,帮助开发者提高开发...
学习Spring的基本概念及其主要模块(如Spring MVC、Spring Security等)是很有价值的。 - **Struts2**:虽然不如以前那么流行,但Struts2仍然是一种强大的Web框架,特别是在大型企业项目中。 ##### 3.6 测试与调试 ...
18. Forms Processing with Servlets(Servlet表单处理) 19. Servlets Life Cycle (Servlet生命周期) 20. Resources Accessing(Servlet资源获取) 21. Persistent States in HttpServlets(Servlet状态持久...
Equinox是所有Eclipse系统的基础,从嵌入式航空自助登机亭、滑雪场闸门到丰富的客户端应用、集成开发环境(IDE),甚至高性能应用服务器如WebSphere和Spring dm server等,都有它的身影。 2. **创建第一个Bundle**...
这一章节介绍Java Servlet技术,探讨它们在UML中的模型表示,以及如何在案例研究中实际应用UML和Servlets。Servlets非常适合基于请求-响应的Web应用模式。 ### 第十一章:JavaServer Pages (JSP) 本章深入讲解JSP...
Turning to technology, Aleksa has been involved with the Spring Framework since early days, becoming an expert in enterprise Java development with Spring, along with other open-source technologies....
His areas of interest include a wide range of Java-related technologies (Servlets, JSP, JAXB, JAXP, JMS, JMX, JAX-RS, JAX-WS, Hibernate, Spring Framework, Liferay Portal, and Eclipse RCP), cloud ...
2. **Spring Framework (SSM)**: Spring forms the core of the 'S' in SSM, which stands for Spring, Servlets, and MyBatis. Spring is a comprehensive framework for building enterprise-level applications, ...
4. **框架与库**:Java Web开发中有许多优秀的框架和库,如Spring、Struts等,它们为开发者提供了丰富的功能和便利性,帮助开发者快速构建复杂的应用程序。 #### 四、Java Web开发的最佳实践 1. **代码组织**:...
- **Integration with Frameworks**: Examples of integrating XDoclet with popular web frameworks like Struts and Spring. #### Chapter 5: XDoclet and Web Frameworks Building on the previous chapter, ...
这个过程可以通过Servlets或者现代的Web框架如Spring MVC来实现。 1. **文件上传**: - **Servlets**:在传统的Java Web开发中,Servlets可以处理HTTP请求,包括文件上传。使用`HttpServletRequest`对象的`getPart...
对于不熟悉这些内容的读者,作者也推荐了其他书籍作为参考,比如《Java for the Web with Servlets, JSP, and EJB》。 对于那些希望深入理解servlet容器工作原理的Java技术开发人员、Tomcat用户以及有志于参与...