- 浏览: 2493417 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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 1618I am still keep notes my tech n ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 383Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 382Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 337Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 405VPN Server 2020(2)Docker on Cen ... -
Nginx Deal with OPTIONS in HTTP Protocol
2020-02-15 01:33 307Nginx Deal with OPTIONS in HTTP ... -
PDF to HTML 2020(1)pdftohtml Linux tool or PDFBox
2020-01-29 07:37 349PDF to HTML 2020(1)pdftohtml Li ... -
Elasticsearch Cluster 2019(2)Kibana Issue or Upgrade
2020-01-12 03:25 606Elasticsearch Cluster 2019(2)Ki ... -
Spark Streaming 2020(1)Investigation
2020-01-08 07:19 236Spark Streaming 2020(1)Investig ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 260Hadoop Docker 2019 Version 3.2. ... -
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 208MongoDB 2019(3)Security and Aut ... -
MongoDB 2019(1)Install 4.2.1 Single and Cluster
2019-11-11 05:07 255MongoDB 2019(1) Follow this ht ... -
Monitor Tool 2019(1)Monit Installation and Usage
2019-10-17 08:22 291Monitor Tool 2019(1)Monit Insta ... -
Ansible 2019(1)Introduction and Installation on Ubuntu and CentOS
2019-10-12 06:15 276Ansible 2019(1)Introduction and ... -
Timezone and Time on All Servers and Docker Containers
2019-10-10 11:18 297Timezone and Time on All Server ... -
Kafka Cluster 2019(6) 3 Nodes Cluster on CentOS7
2019-10-05 23:28 242Kafka Cluster 2019(6) 3 Nodes C ... -
K8S Helm(1)Understand YAML and Kubectl Pod and Deployment
2019-10-01 01:21 292K8S Helm(1)Understand YAML and ... -
Rancher and k8s 2019(5)Private Registry
2019-09-27 03:25 330Rancher and k8s 2019(5)Private ... -
Jenkins 2019 Cluster(1)Version 2.194
2019-09-12 02:53 409Jenkins 2019 Cluster(1)Version ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 339Redis Cluster 2019(3)Redis Clus ...
相关推荐
Java for the Web with Servlets, JSP, and EJB: A Developer's Guide to J2EE Solutions
Java for the Web with Servlets, JSP and EJB is the one book you need to master Java web programming. It covers all the technologies needed to program web applications in Java using Servlets 2.3, JSP ...
Java for the Web with Servlets, JSP and EJB is the one book you need to master Java web programming. It covers all the technologies needed to program web applications in Java using Servlets 2.3, JSP ...
Java for the Web with Servlets, JSP, and EJB, A Developer's Guide to J2EE Solutions
Springer.Web.Development.with.Java.Using.Hibernate.JSPs.and.Servlets.Oct.2007
Budi Kurniawan的经典之作,servlet/jsp程序员的圣经!
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 ...
Java-for-the-Web-with-Servlets_JSP_and-EJB.pdf
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. ...
这个jar文件包含Spring MVC框架相关的所有类。 包含国际化、标签、Theme、视图展现的FreeMarker、JasperReports、Tiles、Velocity、XSLT相关类。...该jar包含Spring MVC框架相关的所有类,如Servlets,Web MVC
包括框架的Servlets,Web MVC框架,控制器和视图支持。当然,如果你的应用使用了独立的MVC 框架,则无需这个JAR 文件里的任何类。 外部依赖spring-web, (spring-support,Tiles,iText,POI)。 spring-aspects.jar...
head first servlets&jsp;(第二版)并没有给你一大堆需要死记硬背的条条框框;它能将知识直接送入你的大脑。你会通过不寻常的方式同servlet和jsp打交道,可以学得更深入、更快捷。读完全书后,你会看到一个全新的...
You'll interact with servlets and JSPs in ways that help you learn quickly and deeply. And when you're through with the book, you can take a brand-new mock exam, created specifically to simulate the ...
Head First Servlets & JSP 完好高清中文版 part3 共6部分 Head First系列的书绝对是初学者的首选!风格生动有趣,讲解由浅入深。 发现网上流传的中文版存在有几处部分页面缺失的问题,花一个下午进行了修复。
head first servlets & JSP(3)
Java.Servlets.编程指南
深入浅出Servlets and JSP第二版(高清完整版,共三卷)卷3
Core Servlets and JavaServer Pages这本书的所有代码,知识与实践结合
JSP、Servlets与MySQL开发指南.rar