本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpResponse.addHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.addHeader方法的具体用法?Java HttpResponse.addHeader怎么用?Java HttpResponse.addHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.handler.codec.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.addHeader方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendPrepare
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
private HttpResponse sendPrepare(ChannelHandlerContext ctx,String body) {
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/html; charset=UTF-8");
response.addHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
StringBuilder builder = new StringBuilder();
builder.append(body);
response.setContent(ChannelBuffers.copiedBuffer(builder.toString(), CharsetUtil.UTF_8));
return response;
}
示例2: setCookies
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
private void setCookies(Renderer renderer, HttpResponse response) {
if (renderer != null) {
for (Iterator<HttpCookie> it = renderer.getApp().getCookieEncoder().iterator(); it.hasNext();) {
HttpCookie httpCookie = it.next();
CookieEncoder encoder = new CookieEncoder(false);
encoder.addCookie(httpCookie.getName(), httpCookie.getValue());
response.addHeader("Set-Cookie", httpCookie.toString()+"; path=/");
}
}
}
示例3: submitByHtml
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
/**
* @param ctx
* @param content
* @param response
* @return
*/
private HttpResponse submitByHtml(ChannelHandlerContext ctx, QueryStringDecoder content, HttpResponse response) {
String wifiname = HttpParameterHelper.getParameters(content, "wifiname");
String wifipass = HttpParameterHelper.getParameters(content, "wifipass");
LogHelper.info("get rededit user:"+wifiname+" pass:"+wifipass);
if(wifiname.contains("'") || wifiname.contains("\"")){
LogHelper.info("get rededit 不合法字符");
response = returnRegeditPage(ctx, content,"不合法字符!");
return response;
}
if(wifipass.contains("'") || wifipass.contains("\"")){
LogHelper.info("get rededit 不合法字符");
response = returnRegeditPage(ctx, content,"不合法字符!");
return response;
}
SqlSession session = null;
try{
SqlSessionFactory factory = SessionFactory.getInstance();
session = factory.openSession();
UserMapper userMapper = session.getMapper(UserMapper.class);
List<User> result = userMapper.select(wifiname);
if(result!=null && result.size()!=0){
LogHelper.info("get rededit 用户名存在");
response = returnLoginPage(ctx, content,"用户名存在!");
return response;
}
User user = new User();
user.setUsername(wifiname);
user.setPassword(wifipass);
user.setCreatetime(new Date());
userMapper.insert(user);
String redirectUrl="http://"+HttpParameterHelper.getParameters(content, "gw_address")+":"+HttpParameterHelper.getParameters(content, "gw_port")+"/wifidog/auth?"+"token="+wifiname+"&url="+HttpParameterHelper.getParameters(content, "url");
LogHelper.info("get rededit redirecturl:"+redirectUrl);
response = sendPrepare(ctx, "");
response.setStatus(HttpResponseStatus.TEMPORARY_REDIRECT);
response.addHeader(HttpHeaders.Names.LOCATION, redirectUrl);
}catch(Exception e){
LogHelper.error(ExceptionUtils.getFullStackTrace(e));
}finally{
if(session!=null){
session.close();
}
}
return response;
}
示例4: submitByApp
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
/**
* @param ctx
* @param content
* @param response
* @return
*/
private HttpResponse submitByApp(ChannelHandlerContext ctx, QueryStringDecoder content, HttpResponse response) {
String wifiname = HttpParameterHelper.getParameters(content, "wifiname");
String wifipass = HttpParameterHelper.getParameters(content, "wifipass");
LogHelper.info("get rededit user:"+wifiname+" pass:"+wifipass);
if(wifiname.contains("'") || wifiname.contains("\"")){
LogHelper.info("get rededit 不合法字符");
response = sendPrepare(ctx, "{errorcode:000001}");
return response;
}
if(wifipass.contains("'") || wifipass.contains("\"")){
LogHelper.info("get rededit 不合法字符");
response = sendPrepare(ctx, "{errorcode:000001}");
return response;
}
SqlSession session = null;
try{
SqlSessionFactory factory = SessionFactory.getInstance();
session = factory.openSession();
UserMapper userMapper = session.getMapper(UserMapper.class);
List<User> result = userMapper.select(wifiname);
if(result!=null && result.size()!=0){
LogHelper.info("get rededit 用户名存在");
response = sendPrepare(ctx, "{errorcode:000005}");
return response;
}
User user = new User();
user.setUsername(wifiname);
user.setPassword(wifipass);
user.setCreatetime(new Date());
userMapper.insert(user);
String redirectUrl="http://"+HttpParameterHelper.getParameters(content, "gw_address")+":"+HttpParameterHelper.getParameters(content, "gw_port")+"/wifidog/auth?"+"token="+wifiname+"&url="+HttpParameterHelper.getParameters(content, "url");
LogHelper.info("get rededit redirecturl:"+redirectUrl);
response = sendPrepare(ctx, "");
response.setStatus(HttpResponseStatus.TEMPORARY_REDIRECT);
response.addHeader(HttpHeaders.Names.LOCATION, redirectUrl);
}catch(Exception e){
LogHelper.error(ExceptionUtils.getFullStackTrace(e));
}finally{
if(session!=null){
session.close();
}
}
return response;
}
示例5: loginByHtml
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
/**
* @param ctx
* @param content
* @param response
* @return
*/
private HttpResponse loginByHtml(ChannelHandlerContext ctx, QueryStringDecoder content, HttpResponse response) {
String wifiname = HttpParameterHelper.getParameters(content, "wifiname");
String wifipass = HttpParameterHelper.getParameters(content, "wifipass");
LogHelper.info("get login user:"+wifiname+" pass:"+wifipass);
if(wifiname.trim().equals("") || wifipass.trim().equals("")){
LogHelper.info("get login 不合法字符");
response = returnLoginPage(ctx, content,"不合法字符!");
return response;
}
if(wifiname.contains("'") || wifiname.contains("\"")){
LogHelper.info("get login 不合法字符");
response = returnLoginPage(ctx, content,"不合法字符!");
return response;
}
SqlSessionFactory factory = SessionFactory.getInstance();
SqlSession session = null;
try{
session = factory.openSession();
UserMapper userMapper = session.getMapper(UserMapper.class);
List<User> result = userMapper.select(wifiname);
if(result==null || result.size()==0){
LogHelper.info("get login 用户名错误");
response = returnLoginPage(ctx, content,"用户名密码错误!");
return response;
}
if(!result.get(0).getPassword().equals(wifipass)){
LogHelper.info("get login 密码错误");
response = sendPrepare(ctx, "用户名密码错误!");
return response;
}
// UserLogMapper logMapper = session.getMapper(UserLogMapper.class);
// List<UserLog> log = logMapper.select(wifiname);
// if(log!=null && log.size()>0 && log.get(0).getIsonline()==1){
// LogHelper.info("用户已经登录...");
// response = returnLoginPage(ctx, content,"用户已经登录...");
// return response;
// }
String redirectUrl="http://"+HttpParameterHelper.getParameters(content, "gw_address")+":"+HttpParameterHelper.getParameters(content, "gw_port")+"/wifidog/auth?"+"token="+wifiname+"&url="+HttpParameterHelper.getParameters(content, "url");
response = sendPrepare(ctx, "");
response.setStatus(HttpResponseStatus.TEMPORARY_REDIRECT);
response.addHeader(HttpHeaders.Names.LOCATION, redirectUrl);
LogHelper.info("redirectUrl is : "+redirectUrl);
}catch(Exception e){
LogHelper.error(ExceptionUtils.getFullStackTrace(e));
}finally{
if(session!=null){
session.close();
}
}
return response;
}
示例6: loginByApp
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
private HttpResponse loginByApp(ChannelHandlerContext ctx, QueryStringDecoder content, HttpResponse response) {
String wifiname = HttpParameterHelper.getParameters(content, "wifiname");
String wifipass = HttpParameterHelper.getParameters(content, "wifipass");
LogHelper.info("get login by app user:"+wifiname+" pass:"+wifipass);
if(wifiname.trim().equals("") || wifipass.trim().equals("")){
LogHelper.info("get login 不合法字符");
response = sendPrepare(ctx, "{errorcode:000001}");
return response;
}
if(wifiname.contains("'") || wifiname.contains("\"")){
LogHelper.info("get login 不合法字符");
response = sendPrepare(ctx, "{errorcode:000001}");
return response;
}
SqlSessionFactory factory = SessionFactory.getInstance();
SqlSession session = null;
try{
session = factory.openSession();
UserMapper userMapper = session.getMapper(UserMapper.class);
List<User> result = userMapper.select(wifiname);
if(result==null || result.size()==0){
LogHelper.info("get login 用户名错误");
response = sendPrepare(ctx, "{errorcode:000002}");
return response;
}
if(!result.get(0).getPassword().equals(wifipass)){
LogHelper.info("get login 密码错误");
response = sendPrepare(ctx, "{errorcode:000003}");
return response;
}
// UserLogMapper logMapper = session.getMapper(UserLogMapper.class);
// List<UserLog> log = logMapper.select(wifiname);
// if(log!=null && log.size()>0 && log.get(0).getIsonline()==1){
// LogHelper.info("用户已经登录...");
// response = sendPrepare(ctx, "{errorcode:000004}");
// return response;
// }
String redirectUrl="http://"+HttpParameterHelper.getParameters(content, "gw_address")+":"+HttpParameterHelper.getParameters(content, "gw_port")+"/wifidog/auth?"+"token="+wifiname+"&url="+HttpParameterHelper.getParameters(content, "url");
response = sendPrepare(ctx, "");
response.setStatus(HttpResponseStatus.TEMPORARY_REDIRECT);
response.addHeader(HttpHeaders.Names.LOCATION, redirectUrl);
LogHelper.info("redirectUrl is : "+redirectUrl);
}catch(Exception e){
LogHelper.error(ExceptionUtils.getFullStackTrace(e));
}finally{
if(session!=null){
session.close();
}
}
return response;
}
示例7: movedPermanently
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void movedPermanently(String location) {
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, MOVED_PERMANENTLY);
response.addHeader("Location", location);
write(response);
}
示例8: temporaryRedirect
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void temporaryRedirect(String location) {
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, TEMPORARY_REDIRECT);
response.addHeader("Location", location);
write(response);
}