• Stars
    star
    3,626
  • Rank 12,214 (Top 0.3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🍒 Web server and web framework of Android platform.

AndServer

Logo

AndServer is an HTTP and reverse proxy server.

Web server and Web framework of Android platform. It provides annotations like SpringMVC, and if you are familiar with SpringMVC, you can master it very quickly.

  • Static html website deployment.
  • Dynamic http api deployment.
  • Reverse proxy server.

Web Server

Deploy a web server:

Server server = AndServer.webServer(context)
    .port(8080)
    .timeout(10, TimeUnit.SECONDS)
    .build();

// startup the server.
server.startup();

...

// shutdown the server.
server.shutdown();

It also has some features, such as inetAddress(InetAddress), serverSocketFactory(ServerSocketFactory) and sslContext(SSLContext), depending on what you want to achieve.

@RestController
@RequestMapping(path = "/user")
public class UserController {

    @PostMapping("/login")
    public String login(@RequestParam("account") String account,
                        @RequestParam("password") String password) {

        ...
        return "Successful.";
    }

    @GetMapping(path = "/{userId}")
    public User info(@PathVariable("userId") String userId,
                     @QueryParam("fields") String fields) {

        User user = findUserById(userId, fields);
        ...

        return user;
    }

    @PutMapping(path = "/{userId}")
    public void modify(@PathVariable("userId") String userId
                       @RequestParam("age") int age) {
        ...
    }
}

The above code will generate the following two http apis:

POST http://.../user/login
GET http://.../user/uid_001?fields=id,name,age
PUT http://.../user/uid_001

Get connection information with the client:

@GetMapping(path = "/connection")
void getConnection(HttpRequest request, ...) {
    request.getLocalAddr();   // HostAddress
    request.getLocalName();   // HostName
    request.getLocalPort();   // server's port

    request.getRemoteAddr();  // HostAddress
    request.getRemoteHost();  // Especially HostName, second HostAddress
    request.getRemotePort();  // client's port

    ...
}

For documentation and additional information see the website.

Reverse Proxy Server

Deploy a reverse proxy server:

Server server = AndServer.proxyServer()
    .addProxy("www.example1.com", "http://192.167.1.11:8080")
    .addProxy("example2.com", "https://192.167.1.12:9090")
    .addProxy("55.66.11.11", "http://www.google.com")
    .addProxy("192.168.1.11", "https://github.com:6666")
    .port(80)
    .timeout(10, TimeUnit.SECONDS)
    .build();

// startup the server.
server.startup();

...

// shutdown the server.
server.shutdown();

Note: It is just a reverse proxy and does not have the ability to take care of loading balance.

Download

Add the plugin to your project build script :

buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.yanzhenjie.andserver:plugin:2.1.12'
        ...
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
...

And then add AndServer dependency to your module:

apply plugin: 'com.yanzhenjie.andserver'

...

dependencies {
    implementation 'com.yanzhenjie.andserver:api:2.1.12'
    annotationProcessor 'com.yanzhenjie.andserver:processor:2.1.12'
    ...
}

If you are using Kotlin, replace annotationProcessor with kapt.

Contributing

Before submitting pull requests, contributors must abide by the agreement .

License

Copyright Zhenjie Yan

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.

More Repositories

1

AndPermission

🍓 Permissions manager for Android platform.
Java
6,616
star
2

SwipeRecyclerView

🍈 RecyclerView侧滑菜单,Item拖拽,滑动删除Item,自动加载更多,HeaderView,FooterView,Item分组黏贴。
Java
5,570
star
3

NoHttp

🍋 Android实现Http标准协议框架,支持多种缓存模式,底层可动态切换OkHttp、URLConnection。
Java
3,705
star
4

Album

🍉 Album and Gallery for Android platform.
Java
2,501
star
5

Sofia

Android沉浸式效果的实现,状态栏和导航栏均支持设置颜色、渐变色、图片、透明度、内容入侵和状态栏深色字体;兼容竖屏、横屏,当屏幕旋转时会自动适配。
Java
1,230
star
6

Kalle

🍎 Http client for Android platform.
Java
586
star
7

CircleTextProgressbar

自定义圆形进度条 自定义倒计时进度条。继承自Textview,可以顺序旋转,可以倒叙旋转,可以设置进度条颜色,填充颜色,可以设置进度条宽度,可以设置填充颜色点击效果,文字点击效果。
Java
304
star
8

NoFragment

Fragment的封装,启动Fragment只需要调用startFragment(XXFragment.class);
Java
171
star
9

AddressChecker

✔️ MD风格的地址选择器,MD风格的城市选择器,Android就不要按照iOS风格来设计啦!
Java
109
star
10

GradleToMaven

简化发布Java、Android项目发布到MavenCentral。
44
star
11

mvp-sample

一个简单的MVP示例,和传统不一样的是,我们把Activity/Fragment作为Presenter,把View单独提出来,扩展了Presenter的能力。
Java
40
star
12

MediaScanner

MediaScannerConnection and MediaScannerConnectionClient.
Java
28
star
13

CompatAlertDialog

Java
27
star
14

LoadMore

ListView,GridView加载更多,GridView添加HeaderView和FooterView。
Java
19
star
15

Loading

LoadingView and LoadingDialog.
Java
16
star
16

yanzhenjie.github.io

Profile page of Zhenjie Yan.
HTML
15
star
17

FormatStringToJava

Any string formatted into a java String or a StringBuffer.
Java
14
star
18

HttpImpl

Java
11
star
19

AndroidWheel

Android Wheel View. I just fork it and continue to maintain it, this is not my credit, I pay tribute to the predecessors.
Java
7
star
20

Years

Just select the year and month view on Android.
Java
6
star
21

KalleServer

A simple http test api server.
Java
6
star
22

Icons-for-macOS-Big-Sur

App and folder icons that fit macOS Big Sur style.
JavaScript
3
star