本文整理汇总了Java中org.jboss.netty.handler.codec.http.QueryStringDecoder类的典型用法代码示例。如果您正苦于以下问题:Java QueryStringDecoder类的具体用法?Java QueryStringDecoder怎么用?Java QueryStringDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryStringDecoder类属于org.jboss.netty.handler.codec.http包,在下文中一共展示了QueryStringDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
HttpRequest request = (HttpRequest) msg;
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, decoder.getParameters().get("UserName").get(0));
if (deviceSession == null) {
return null;
}
Parser parser = new Parser(PATTERN, decoder.getParameters().get("LOC").get(0));
if (!parser.matches()) {
return null;
}
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setValid(true);
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
if (channel != null) {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
return position;
}
示例2: doPost
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
private void doPost(ChannelHandlerContext ctx, MessageEvent e, HttpRequest req)
throws IOException {
final QueryStringDecoder decoded = new QueryStringDecoder(req.getUri());
if (!decoded.getPath().equalsIgnoreCase("/write")) {
writeResponseAndClose(e,
new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND));
return;
}
try {
metricParser.parse(req);
} catch (IllegalArgumentException iae) {
logger.warn("Metric parser failed: " + iae.getMessage());
}
HttpResponse response = new DefaultHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setContent(ChannelBuffers.copiedBuffer(
("Seen events").getBytes()
));
writeResponseAndClose(e, response);
}
示例3: messageReceived
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
@Override
public final void messageReceived(ChannelHandlerContext context, MessageEvent event) throws Exception {
if (!(event.getMessage() instanceof HttpRequest)) {
context.sendUpstream(event);
return;
}
HttpRequest request = (HttpRequest)event.getMessage();
//if (BuiltInServer.LOG.isDebugEnabled()) {
//BuiltInServer.LOG.debug(request.toString());
//}
if (!process(context, request, new QueryStringDecoder(request.getUri()))) {
Responses.sendStatus(request, context, NOT_FOUND);
}
}
示例4: returnRegeditPage
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
/**
* return login page,if user & password is error.return error tips!
* */
private HttpResponse returnRegeditPage(ChannelHandlerContext ctx, QueryStringDecoder content,String tips) {
HttpResponse response;
String responseContent = ReadAll.readAll("web/regedit.html", "utf-8");
responseContent = responseContent.replaceAll("<<param.gw_address>>",HttpParameterHelper.getParameters(content, "gw_address"));
responseContent = responseContent.replaceAll("<<param.gw_port>>",HttpParameterHelper.getParameters(content, "gw_port"));
responseContent = responseContent.replaceAll("<<param.gw_id>>",HttpParameterHelper.getParameters(content, "gw_id"));
responseContent = responseContent.replaceAll("<<param.url>>",HttpParameterHelper.getParameters(content, "url"));
if(tips==null){
responseContent = responseContent.replaceAll("<<showtips>>","");
}else{
responseContent = responseContent.replaceAll("<<showtips>>","<input type='button' onclick='return;' class='get_btn' value='"+tips+"'>");
}
response = sendPrepare(ctx, responseContent);
return response;
}
示例5: returnLoginPage
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
/**
* return login page,if user & password is error.return error tips!
* */
private HttpResponse returnLoginPage(ChannelHandlerContext ctx, QueryStringDecoder content,String tips) {
HttpResponse response;
String responseContent = ReadAll.readAll("web/login.html", "utf-8");
responseContent = responseContent.replaceAll("<<param.gw_address>>",HttpParameterHelper.getParameters(content, "gw_address"));
responseContent = responseContent.replaceAll("<<param.gw_port>>",HttpParameterHelper.getParameters(content, "gw_port"));
responseContent = responseContent.replaceAll("<<param.gw_id>>",HttpParameterHelper.getParameters(content, "gw_id"));
responseContent = responseContent.replaceAll("<<param.url>>",HttpParameterHelper.getParameters(content, "url"));
if(tips==null){
responseContent = responseContent.replaceAll("<<showtips>>","");
}else{
responseContent = responseContent.replaceAll("<<showtips>>","<input type='button' onclick='return;' class='get_btn' value='"+tips+"'>");
}
response = sendPrepare(ctx, responseContent);
return response;
}
示例6: getParameters
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
/**
* get Parameter from URI
* */
public static String getParameters(QueryStringDecoder content,String query){
List<String> list = content.getParameters().get(query);
if(list==null){
return "";
}
StringBuilder respone = new StringBuilder();
for(int i=0;i<list.size();i++){
if(i==list.size()-1){
respone.append(list.get(i));
}else{
respone.append(list.get(i)+",");
}
}
return respone.toString();
}
示例7: parseQueryParameters
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
private QueryParams parseQueryParameters(QueryStringDecoder decoded) {
final Map<String, List<String>> parameters = decoded.getParameters();
return new QueryParams(
safeOneValue(parameters, "type"),
safeOneValue(parameters, "key"),
Long.parseLong(safeOneValue(parameters, "from")),
Long.parseLong(safeOneValue(parameters, "to"))
);
}
示例8: traversalDecoder
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
private void traversalDecoder(QueryStringDecoder decoder) {
try {
for (Map.Entry<String, List<String>> entry : decoder.getParameters().entrySet()) {
params.put(entry.getKey(), entry.getValue().get(0));
}
} catch (JSONException e) {
throw NaviUtil.transferToNaviSysException(e);
}
}
示例9: getPath
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
private static String getPath(QueryStringDecoder decoder)
throws FileNotFoundException {
String path = decoder.getPath();
if (path.startsWith("/webhdfs/v1/")) {
return path.substring(11);
} else {
throw new FileNotFoundException("Path: " + path + " should " +
"start with \"/webhdfs/v1/\"");
}
}
示例10: apply
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
public Future<HttpResponse> apply(HttpRequest req) {
// Parse URL parameters
String bannerSize = null;
String opt = null;
QueryStringDecoder decoder = new QueryStringDecoder(req.getUri());
Map <String, List<String>> params = decoder.getParameters();
if (params.containsKey("bsize")) {
bannerSize = params.get("bsize").get(0);
opt = params.get("opt").get(0);
}
// Parse cookie
Cookie cookie = null;
String value = req.getHeader("Cookie");
if (value != null) {
Set<Cookie> cookies = new CookieDecoder().decode(value);
for (Cookie c : cookies) {
if (c.getName().equals(COOKIE_NAME)) {
cookie = c;
}
}
}
String vizid = null;
if (cookie != null) {
vizid = cookie.getValue();
} else {
vizid = UUID.randomUUID().toString();
// TODO Skip cache access
}
// Get data from redis cache
Future<scala.collection.immutable.Set<ChannelBuffer>> udResponse = redisCache.sMembers(vizid);
Future<HttpResponse> response = udResponse.flatMap(new ProcessResponse(req, vizid,
bannerSize, opt, redisCache));
System.out.println("[CookieServer] Returning response Future");
return response;
}
示例11: testCreateHashFetchURL
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
@Test
public void testCreateHashFetchURL() throws Exception {
QueryId q1 = TestTajoIds.createQueryId(1315890136000l, 2);
String hostName = "tajo1";
int port = 1234;
ExecutionBlockId sid = new ExecutionBlockId(q1, 2);
int partitionId = 2;
List<QueryUnit.IntermediateEntry> intermediateEntries = TUtil.newList();
for (int i = 0; i < 1000; i++) {
intermediateEntries.add(new QueryUnit.IntermediateEntry(i, 0, partitionId, hostName, port));
}
Collection<URI> uris = Repartitioner.
createHashFetchURL(hostName + ":" + port, sid, partitionId,
TajoWorkerProtocol.ShuffleType.HASH_SHUFFLE, intermediateEntries);
List<String> taList = TUtil.newList();
for (URI uri : uris) {
final Map<String, List<String>> params =
new QueryStringDecoder(uri).getParameters();
taList.addAll(splitMaps(params.get("ta")));
}
int checkTaskId = 0;
for (String ta : taList) {
assertEquals(checkTaskId++, Integer.parseInt(ta.split("_")[0]));
}
}
示例12: handle
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
public ComposableFuture<Map<String, String>> handle(final HttpRequest request) {
final QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
final Map<String,List<String>> params = queryStringDecoder.getParameters();
final Map<String, String> res = new HashMap<>();
for (final String key: params.keySet()) {
res.put(key, params.get(key).get(0));
}
return ComposableFutures.fromValue(res);
}
示例13: process
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
@Override
protected boolean process(ChannelHandlerContext context, HttpRequest request, QueryStringDecoder urlDecoder) throws IOException, ImageWriteException {
HttpRequestHandler connectedHandler = (HttpRequestHandler)context.getAttachment();
if (connectedHandler != null) {
if (connectedHandler.isSupported(request) && connectedHandler.process(urlDecoder, request, context)) {
return true;
}
// prev cached connectedHandler is not suitable for this request, so, let's find it again
context.setAttachment(null);
}
if (urlDecoder.getPath().equals("/favicon.ico")) {
Icon icon = IconLoader.findIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
if (icon != null) {
BufferedImage image = UIUtil.createImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(null, image.getGraphics(), 0, 0);
byte[] icoBytes = Sanselan.writeImageToBytes(image, ImageFormat.IMAGE_FORMAT_ICO, null);
Responses.send(icoBytes, FileResponses.createResponse(urlDecoder.getPath()), request, context);
return true;
}
}
for (HttpRequestHandler handler : BuiltInServerManager.EP_NAME.getExtensions()) {
try {
if (handler.isSupported(request) && handler.process(urlDecoder, request, context)) {
if (context.getAttachment() == null) {
context.setAttachment(handler);
}
return true;
}
}
catch (Throwable e) {
BuiltInServer.LOG.error(e);
}
}
return false;
}
示例14: parseGet
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
private void parseGet(ChannelHandlerContext ctx, MessageEvent e, HttpRequest request) {
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
String path = decoder.getPath();
HttpResponse response = null;;
LogHelper.info("got get request "+path);
if(path.equals("/ewifi/ping/")){
response = parsePing(ctx, decoder);
}else if(path.equals("/ewifi/auth/")){
response = parseAuth(ctx, decoder);
}else if(path.equals("/ewifi/login/")){
response = parseLogin(ctx, decoder);
}else if(path.equals("/ewifi/portal/")){
response = parsePortal(ctx, decoder);
}else if(path.equals("/ewifi/regedit/")){
response = parseRegedit(ctx, decoder);
}else if(path.equals("/ewifi/querymac/")){
response = parseQuery(ctx, decoder);
}else{
response = parseStatic(ctx, decoder);
}
Channel ch = e.getChannel();
if (ch.isConnected()) {
ch.write(response).addListener(ChannelFutureListener.CLOSE);
}
}
示例15: parsePortal
import org.jboss.netty.handler.codec.http.QueryStringDecoder; //导入依赖的package包/类
private HttpResponse parsePortal(ChannelHandlerContext ctx, QueryStringDecoder content) {
HttpResponse response = null;
String html = ReadAll.readAll("web/portal/"+HttpParameterHelper.getParameters(content, "gw_id")+".html", "utf-8");
if(html!=null && !html.isEmpty()){
response = sendPrepare(ctx,html);
}else{
response = sendPrepare(ctx,"欢迎你连接"+HttpParameterHelper.getParameters(content, "gw_id")+",你现在可以正常上网了!");
}
return response;
}