//========================================================================
//$Id: IJettyService.java 474 2012-01-23 03:07:14Z janb.webtide $
//Copyright 2008 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//Licensed 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.mortbay.ijetty;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.mortbay.ijetty.deployer.AndroidContextDeployer;
import org.mortbay.ijetty.deployer.AndroidWebAppDeployer;
import org.mortbay.ijetty.handler.DefaultHandler;
import org.mortbay.ijetty.util.AndroidInfo;
import org.mortbay.ijetty.util.IJettyToast;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.http.HttpGenerator;
import org.eclipse.jetty.http.ssl.SslContextFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
import org.eclipse.jetty.server.ssl.SslSocketConnector;
import org.eclipse.jetty.util.security.Credential;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.res.Resources;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.util.Log;
/**
* IJettyService
*
* Android Service which runs the Jetty server, maintaining it in the active Notifications so that
* the user can return to the IJetty Activity to control it at any time.
*/
public class IJettyService extends Service
{
private static final String TAG = "Jetty";
private static Resources __resources;
private static final String CONTENT_RESOLVER_ATTRIBUTE = "org.mortbay.ijetty.contentResolver";
private static final String ANDROID_CONTEXT_ATTRIBUTE = "org.mortbay.ijetty.context";
public static final int __START_PROGRESS_DIALOG = 0;
public static final int __STARTED = 0;
public static final int __NOT_STARTED = 1;
public static final int __STOPPED = 2;
public static final int __NOT_STOPPED = 3;
public static final int __STARTING = 4;
public static final int __STOPPING = 5;
public static final String[] __configurationClasses =
new String[]
{
"org.mortbay.ijetty.webapp.AndroidWebInfConfiguration",
"org.eclipse.jetty.webapp.WebXmlConfiguration",
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.webapp.TagLibConfiguration"
};
private static boolean __isRunning;
private NotificationManager mNM;
private Server server;
private ContextHandlerCollection contexts;
private boolean _useNIO;
private boolean _useSSL;
private int _port;
private int _sslPort;
private String _consolePassword;
private String _keymgrPassword;
private String _keystorePassword;
private String _truststorePassword;
private String _keystoreFile;
private String _truststoreFile;
private SharedPreferences preferences;
private PackageInfo pi;
private android.os.Handler _handler;
private PowerManager.WakeLock wakeLock;
private final IBinder binder = new LocalBinder();
static
{
__isRunning = false;
}
/**
* IJettyService always runs in-process with the IJetty activity.
*/
public class LocalBinder extends Binder {
IJettyService getService() {
// Return this instance of LocalService so clients can call public methods
return IJettyService.this;
}
}
/**
* JettyStarterThread
*
*
*/
public class JettyStarterThread extends Thread
{
android.os.Handler _handler;
public JettyStarterThread(android.os.Handler handler)
{
_handler = handler;
}
public void run ()
{
try
{
sendMessage(__STARTING);
startJetty();
sendMessage(__STARTED);
Log.i(TAG, "Jetty started");
}
catch (Exception e)
{
sendMessage(__NOT_STARTED);
Log.e(TAG, "Error starting jetty", e);
}
}
public void sendMessage(int state)
{
Message msg = _handler.obtainMessage();
Bundle b = new Bundle();
b.putInt("state", state);
msg.setData(b);
_handler.sendMessage(msg);
}
}
/**
* JettyStopperThread
*
*
*/
public class JettyStopperThread extends Thread
{
android.os.Handler _handler;
public JettyStopperThread(android.os.Handler handler)
{
_handler = handler;
}
public void run ()
{
try
{
sendMessage(__STOPPING);
stopJetty();
Log.i(TAG, "Jetty stopped");
sendMessage(__STOPPED);
}
catch (Exception e)
{
sendMessage(__NOT_STOPPED);
Log.e(TAG, "Error stopping jetty", e);
}
}
public void sendMessage(int state)
{
Message msg = _handler.obtainMessage();
Bundle b = new Bundle();
b.putInt("state", state);
msg.setData(b);
_handler.sendMessage(msg);
}
}
/**
* Hack to get around bug in ResourceBundles
*
* @param id
* @return
*/
public static InputStream getStreamToRawResource(int id)
{
if (__resources != null)
return __resources.openRawResource(id);
else
return null;
}
public static boolean isRunning ()
{
return __isRunning;
}
/**
*
*/
public IJettyService()
{
super();
_handler = new android.os.Handler ()
{
public void handleMessage(Message msg) {
switch (msg.getData().getInt("state"))
{
case __STARTED:
{
IJettyToast.showServiceToast(IJettyService.this,R.string.jetty_started);
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// The PendingIntent to launch IJetty activity if the user selects this notificati
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
i-jetty安卓手机源代码 (133个子文件)
resources.ap_ 64KB
i-jetty-xs.apk 757KB
jarlist.cache 119B
proguard.cfg 1KB
IJettyService.class 13KB
IJetty.class 12KB
IJettyDownloader.class 8KB
AndroidContextDeployer.class 8KB
AndroidClassLoader.class 8KB
Installer.class 6KB
AndroidWebAppDeployer.class 6KB
IJetty$ProgressThread.class 5KB
DefaultHandler.class 4KB
R$string.class 4KB
IJettyService$1.class 3KB
IJettyDownloader$6.class 3KB
AndroidInfo.class 3KB
SdCardUnavailableActivity.class 3KB
AndroidWebInfConfiguration.class 3KB
AndroidLog.class 3KB
IJettyDownloader$1.class 2KB
IJetty$2.class 2KB
IJettyService$JettyStarterThread.class 2KB
IJettyService$JettyStopperThread.class 2KB
IJetty$3.class 2KB
IJettyDownloader$2.class 1KB
AndroidContextDeployer$1.class 1KB
IJettyToast.class 1KB
AndroidContextDeployer$ScannerListener.class 1KB
IJettyDownloader$3.class 1KB
IJettyEditor.class 1KB
IJetty$1.class 1KB
R$id.class 986B
IJetty$4.class 936B
IJettyDownloader$4.class 896B
SdCardUnavailableActivity$1.class 879B
IJettyDownloader$5.class 877B
IJetty$6.class 833B
IJetty$5.class 829B
IJetty$ConsoleScrollTask.class 742B
R.class 715B
IJettyService$LocalBinder.class 632B
R$layout.class 528B
R$color.class 523B
R$style.class 521B
R$drawable.class 506B
R$raw.class 463B
R$xml.class 445B
BuildConfig.class 345B
R$attr.class 340B
.classpath 735B
classes.dex 1.22MB
jetty-server-8.1.2.v20120308.jar 322KB
jetty-util-8.1.2.v20120308.jar 261KB
javax.servlet-3.0.0.v201112011016.jar 183KB
jetty-webapp-8.1.2.v20120308.jar 104KB
jetty-io-8.1.2.v20120308.jar 98KB
jetty-servlet-8.1.2.v20120308.jar 92KB
jetty-http-8.1.2.v20120308.jar 91KB
jetty-client-8.1.2.v20120308.jar 84KB
jetty-security-8.1.2.v20120308.jar 83KB
jetty-deploy-8.1.2.v20120308.jar 58KB
jetty-xml-8.1.2.v20120308.jar 36KB
jetty-continuation-8.1.2.v20120308.jar 20KB
IJettyService.java 23KB
IJetty.java 23KB
IJettyDownloader.java 15KB
AndroidContextDeployer.java 11KB
AndroidClassLoader.java 9KB
R.java 8KB
AndroidWebAppDeployer.java 8KB
Installer.java 8KB
DefaultHandler.java 4KB
AndroidWebInfConfiguration.java 4KB
AndroidLog.java 3KB
SdCardUnavailableActivity.java 3KB
AndroidInfo.java 3KB
IJettyEditor.java 2KB
IJettyToast.java 953B
BuildConfig.java 160B
keystore 1KB
ijetty_logo.png 12KB
ijetty_logo.png 11KB
ijetty_logo.png 9KB
ijetty_logo.png 8KB
icon.png 4KB
icon.png 4KB
icon.png 3KB
icon.png 3KB
ijetty_stat.png 2KB
microsd_warn.png 2KB
ijetty_stat.png 2KB
ijetty_stat.png 1KB
ijetty_stat.png 1KB
microsd_warn.png 1KB
org.eclipse.jdt.core.prefs 22KB
org.eclipse.m2e.core.prefs 121B
.project 1022B
project.properties 445B
realm_properties 49B
共 133 条
- 1
- 2
catoop
- 粉丝: 7469
- 资源: 106
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页