kandi background
Explore Kits

nanohttpd | Tiny, easily embeddable HTTP server in Java.

 by   NanoHttpd Java Version: nanohttpd-project-2.3.1 License: BSD-3-Clause

 by   NanoHttpd Java Version: nanohttpd-project-2.3.1 License: BSD-3-Clause

Download this library from

kandi X-RAY | nanohttpd Summary

nanohttpd is a Java library typically used in Embedded System applications. nanohttpd has no bugs, it has build file available, it has a Permissive License and it has high support. However nanohttpd has 1 vulnerabilities. You can download it from GitHub, Maven.
NanoHTTPD is a light-weight HTTP server designed for embedding in other applications, released under a Modified BSD licence.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • nanohttpd has a highly active ecosystem.
  • It has 5941 star(s) with 1575 fork(s). There are 365 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 137 open issues and 261 have been closed. On average issues are closed in 78 days. There are 30 open pull requests and 0 closed requests.
  • It has a positive sentiment in the developer community.
  • The latest version of nanohttpd is nanohttpd-project-2.3.1
nanohttpd Support
Best in #Java
Average in #Java
nanohttpd Support
Best in #Java
Average in #Java

quality kandi Quality

  • nanohttpd has 0 bugs and 0 code smells.
nanohttpd Quality
Best in #Java
Average in #Java
nanohttpd Quality
Best in #Java
Average in #Java

securitySecurity

  • nanohttpd has 1 vulnerability issues reported (0 critical, 0 high, 1 medium, 0 low).
  • nanohttpd code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
nanohttpd Security
Best in #Java
Average in #Java
nanohttpd Security
Best in #Java
Average in #Java

license License

  • nanohttpd is licensed under the BSD-3-Clause License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
nanohttpd License
Best in #Java
Average in #Java
nanohttpd License
Best in #Java
Average in #Java

buildReuse

  • nanohttpd releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions, examples and code snippets are available.
  • nanohttpd saves you 4154 person hours of effort in developing the same functionality from scratch.
  • It has 8822 lines of code, 684 functions and 87 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
nanohttpd Reuse
Best in #Java
Average in #Java
nanohttpd Reuse
Best in #Java
Average in #Java
Top functions reviewed by kandi - BETA

kandi has reviewed nanohttpd and discovered the below as its top functions. This is intended to give you an instant insight into nanohttpd implemented functionality, and help decide if they suit your requirements.

  • Synchronized .
  • Sends a file to the http request .
  • Send response to output stream .
  • Read payload info from the stream .
  • Read file from file .
  • Handle websocket request .
  • Handle a frame fragment .
  • Loads the mime types from the given resource .
  • Runs the server .
  • Executes an instance of NanoHTTPD .

nanohttpd Key Features

Build status:

Coverage Status:

Current central released version:

Quickstart

copy iconCopydownload iconDownload
mvn compile
mvn exec:java -pl webserver -Dexec.mainClass="org.nanohttpd.webserver.SimpleWebServer"

Custom web app

copy iconCopydownload iconDownload
mvn archetype:generate -DgroupId=com.example -DartifactId=myHellopApp -DinteractiveMode=false
cd myHellopApp

Maven dependencies

copy iconCopydownload iconDownload
<dependencies>
	<dependency>
		<groupId>org.nanohttpd</groupId> <!-- <groupId>com.nanohttpd</groupId> for 2.1.0 and earlier -->
		<artifactId>nanohttpd</artifactId>
		<version>CURRENT_VERSION</version>
	</dependency>
</dependencies>

Gradle dependencies

copy iconCopydownload iconDownload
dependencies {
	runtime(
		[group: 'org.nanohttpd', name: 'nanohttpd', version: 'CURRENT_VERSION'],
	)
}

Develop your own specialized HTTP service

copy iconCopydownload iconDownload
	<dependency>
		<groupId>org.nanohttpd</groupId> <!-- <groupId>com.nanohttpd</groupId> for 2.1.0 and earlier -->
		<artifactId>nanohttpd</artifactId>
		<version>CURRENT_VERSION</version>
	</dependency>

Develop a websocket based service

copy iconCopydownload iconDownload
	<dependency>
		<groupId>org.nanohttpd</groupId> <!-- <groupId>com.nanohttpd</groupId> for 2.1.0 and earlier -->
		<artifactId>nanohttpd-websocket</artifactId>
		<version>CURRENT_VERSION</version>
	</dependency>

Develop a custom HTTP file server

copy iconCopydownload iconDownload
	<dependency>
		<groupId>org.nanohttpd</groupId>
		<artifactId>nanohttpd-webserver</artifactId>
		<version>CURRENT_VERSION</version>
	</dependency>

Living on the edge

copy iconCopydownload iconDownload
<dependencies>
	<dependency>
		<artifactId>nanohttpd</artifactId>
		<groupId>org.nanohttpd</groupId>
		<version>XXXXX-SNAPSHOT</version>
	</dependency>
</dependencies>
...
<repositories>
	<repository>
		<id>sonatype-snapshots</id>
		<url>https://oss.sonatype.org/content/repositories/snapshots</url>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</repository>
</repositories>

generating an self signed SSL certificate

copy iconCopydownload iconDownload
keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 360 -keysize 2048 -ext SAN=DNS:localhost,IP:127.0.0.1  -validity 9999

How download an installed app with nanohttpd

copy iconCopydownload iconDownload
 if (method.equals(Method.GET)) {
            if (a) {
                answer = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; " +
                        "charset=utf-8\"><title> HTTP File Browser</title>";
                for (App file : appShare) {
                    answer += "<a href=\"" + file.getAppName()
                            + "\" alt = \"\">" + file.getAppName()
                            + "</a><br>";
                }
                answer += "</head></html>";
                if(blabla.equals(header.get("referer"))){
                    a=false;
                }

            } else {
                for (int i = 0; i < appShare.size(); i++) {
                    if (appShare.get(i).getAppName().equals(appnames))
                        arrayC = i;
                }
                answer = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; " +
                        "charset=utf-8\"><title> Download " + appShare.get(arrayC).getAppName() + "</title>";
                // serve file download
                InputStream inputStream;
                Response response = null;

                if (mStatusUpdateListener != null) {
                    mStatusUpdateListener.onDownloadingFile(
                            new File(appShare.get(arrayC).getApkPath()), false);
                }

                try {
                    inputStream = new FileInputStream(

                            new File(appShare.get(arrayC).getApkPath()));
                    response = new DownloadResponse(

                            new File(appShare.get(arrayC).getApkPath()), inputStream);
                } catch (Exception e) {
                    e.printStackTrace();
                }            response.addHeader(
                        "Content-Disposition", "attachment; filename=" + appShare.get(arrayC).getAppName()+".apk");
                return response;


            }

NanoHTTPD - write to a socket instead of copy a string to deliver pages

copy iconCopydownload iconDownload
OutputStream getOutputStream();
public OutputStream getOutputStream() {
    return outputStream;
}
public final void sender(@NonNull OutputStream outputStream, @NonNull Runnable run) {
    SimpleDateFormat gmtFrmt = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
    gmtFrmt.setTimeZone(TimeZone.getTimeZone("GMT"));

    try {
        if (status == null) {
            throw new Error("sendResponse(): Status can't be null.");
        }
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream, new ContentType(mimeType).getEncoding())), false);
        pw.append("HTTP/1.1 ").append(status.getDescription()).append(" \r\n");
        if (mimeType != null) {
            printHeader(pw, "Content-Type", mimeType);
        }
        if (getHeader("date") == null) {
            printHeader(pw, "Date", gmtFrmt.format(new Date()));
        }
        for (Entry<String, String> entry : header.entrySet()) {
            printHeader(pw, entry.getKey(), entry.getValue());
        }
        for (String cookieHeader : cookieHeaders) {
            printHeader(pw, "Set-Cookie", cookieHeader);
        }
        if (getHeader("connection") == null) {
            printHeader(pw, "Connection", (keepAlive ? "keep-alive" : "close"));
        }
        long pending = data != null ? contentLength : 0;
        if (requestMethod != Method.HEAD && chunkedTransfer) {
            printHeader(pw, "Transfer-Encoding", "chunked");
        }
        pw.append("\r\n");
        pw.flush();

        run.run(); // <-- your streaming happens here

        outputStream.flush();
        NanoHTTPD.safeClose(data);
    } catch (IOException ioe) {
        NanoHTTPD.LOG.log(Level.SEVERE, "Could not send response to the client", ioe);
    }
}
    public final Response serve(IHTTPSession session) {
        OutputStream outputStream = session.getOutputStream();

        newFixedLengthResponse("").sender(outputStream, () -> {
            new OutputStreamWriter(outputStream).write("Yo, World!");
        } ;

        return null;
    }
//            throw new ResponseException(Status.INTERNAL_ERROR, "SERVER INTERNAL ERROR: Serve() returned a null response.");
            return;
-----------------------
OutputStream getOutputStream();
public OutputStream getOutputStream() {
    return outputStream;
}
public final void sender(@NonNull OutputStream outputStream, @NonNull Runnable run) {
    SimpleDateFormat gmtFrmt = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
    gmtFrmt.setTimeZone(TimeZone.getTimeZone("GMT"));

    try {
        if (status == null) {
            throw new Error("sendResponse(): Status can't be null.");
        }
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream, new ContentType(mimeType).getEncoding())), false);
        pw.append("HTTP/1.1 ").append(status.getDescription()).append(" \r\n");
        if (mimeType != null) {
            printHeader(pw, "Content-Type", mimeType);
        }
        if (getHeader("date") == null) {
            printHeader(pw, "Date", gmtFrmt.format(new Date()));
        }
        for (Entry<String, String> entry : header.entrySet()) {
            printHeader(pw, entry.getKey(), entry.getValue());
        }
        for (String cookieHeader : cookieHeaders) {
            printHeader(pw, "Set-Cookie", cookieHeader);
        }
        if (getHeader("connection") == null) {
            printHeader(pw, "Connection", (keepAlive ? "keep-alive" : "close"));
        }
        long pending = data != null ? contentLength : 0;
        if (requestMethod != Method.HEAD && chunkedTransfer) {
            printHeader(pw, "Transfer-Encoding", "chunked");
        }
        pw.append("\r\n");
        pw.flush();

        run.run(); // <-- your streaming happens here

        outputStream.flush();
        NanoHTTPD.safeClose(data);
    } catch (IOException ioe) {
        NanoHTTPD.LOG.log(Level.SEVERE, "Could not send response to the client", ioe);
    }
}
    public final Response serve(IHTTPSession session) {
        OutputStream outputStream = session.getOutputStream();

        newFixedLengthResponse("").sender(outputStream, () -> {
            new OutputStreamWriter(outputStream).write("Yo, World!");
        } ;

        return null;
    }
//            throw new ResponseException(Status.INTERNAL_ERROR, "SERVER INTERNAL ERROR: Serve() returned a null response.");
            return;
-----------------------
OutputStream getOutputStream();
public OutputStream getOutputStream() {
    return outputStream;
}
public final void sender(@NonNull OutputStream outputStream, @NonNull Runnable run) {
    SimpleDateFormat gmtFrmt = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
    gmtFrmt.setTimeZone(TimeZone.getTimeZone("GMT"));

    try {
        if (status == null) {
            throw new Error("sendResponse(): Status can't be null.");
        }
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream, new ContentType(mimeType).getEncoding())), false);
        pw.append("HTTP/1.1 ").append(status.getDescription()).append(" \r\n");
        if (mimeType != null) {
            printHeader(pw, "Content-Type", mimeType);
        }
        if (getHeader("date") == null) {
            printHeader(pw, "Date", gmtFrmt.format(new Date()));
        }
        for (Entry<String, String> entry : header.entrySet()) {
            printHeader(pw, entry.getKey(), entry.getValue());
        }
        for (String cookieHeader : cookieHeaders) {
            printHeader(pw, "Set-Cookie", cookieHeader);
        }
        if (getHeader("connection") == null) {
            printHeader(pw, "Connection", (keepAlive ? "keep-alive" : "close"));
        }
        long pending = data != null ? contentLength : 0;
        if (requestMethod != Method.HEAD && chunkedTransfer) {
            printHeader(pw, "Transfer-Encoding", "chunked");
        }
        pw.append("\r\n");
        pw.flush();

        run.run(); // <-- your streaming happens here

        outputStream.flush();
        NanoHTTPD.safeClose(data);
    } catch (IOException ioe) {
        NanoHTTPD.LOG.log(Level.SEVERE, "Could not send response to the client", ioe);
    }
}
    public final Response serve(IHTTPSession session) {
        OutputStream outputStream = session.getOutputStream();

        newFixedLengthResponse("").sender(outputStream, () -> {
            new OutputStreamWriter(outputStream).write("Yo, World!");
        } ;

        return null;
    }
//            throw new ResponseException(Status.INTERNAL_ERROR, "SERVER INTERNAL ERROR: Serve() returned a null response.");
            return;
-----------------------
OutputStream getOutputStream();
public OutputStream getOutputStream() {
    return outputStream;
}
public final void sender(@NonNull OutputStream outputStream, @NonNull Runnable run) {
    SimpleDateFormat gmtFrmt = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
    gmtFrmt.setTimeZone(TimeZone.getTimeZone("GMT"));

    try {
        if (status == null) {
            throw new Error("sendResponse(): Status can't be null.");
        }
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream, new ContentType(mimeType).getEncoding())), false);
        pw.append("HTTP/1.1 ").append(status.getDescription()).append(" \r\n");
        if (mimeType != null) {
            printHeader(pw, "Content-Type", mimeType);
        }
        if (getHeader("date") == null) {
            printHeader(pw, "Date", gmtFrmt.format(new Date()));
        }
        for (Entry<String, String> entry : header.entrySet()) {
            printHeader(pw, entry.getKey(), entry.getValue());
        }
        for (String cookieHeader : cookieHeaders) {
            printHeader(pw, "Set-Cookie", cookieHeader);
        }
        if (getHeader("connection") == null) {
            printHeader(pw, "Connection", (keepAlive ? "keep-alive" : "close"));
        }
        long pending = data != null ? contentLength : 0;
        if (requestMethod != Method.HEAD && chunkedTransfer) {
            printHeader(pw, "Transfer-Encoding", "chunked");
        }
        pw.append("\r\n");
        pw.flush();

        run.run(); // <-- your streaming happens here

        outputStream.flush();
        NanoHTTPD.safeClose(data);
    } catch (IOException ioe) {
        NanoHTTPD.LOG.log(Level.SEVERE, "Could not send response to the client", ioe);
    }
}
    public final Response serve(IHTTPSession session) {
        OutputStream outputStream = session.getOutputStream();

        newFixedLengthResponse("").sender(outputStream, () -> {
            new OutputStreamWriter(outputStream).write("Yo, World!");
        } ;

        return null;
    }
//            throw new ResponseException(Status.INTERNAL_ERROR, "SERVER INTERNAL ERROR: Serve() returned a null response.");
            return;
-----------------------
OutputStream getOutputStream();
public OutputStream getOutputStream() {
    return outputStream;
}
public final void sender(@NonNull OutputStream outputStream, @NonNull Runnable run) {
    SimpleDateFormat gmtFrmt = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
    gmtFrmt.setTimeZone(TimeZone.getTimeZone("GMT"));

    try {
        if (status == null) {
            throw new Error("sendResponse(): Status can't be null.");
        }
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream, new ContentType(mimeType).getEncoding())), false);
        pw.append("HTTP/1.1 ").append(status.getDescription()).append(" \r\n");
        if (mimeType != null) {
            printHeader(pw, "Content-Type", mimeType);
        }
        if (getHeader("date") == null) {
            printHeader(pw, "Date", gmtFrmt.format(new Date()));
        }
        for (Entry<String, String> entry : header.entrySet()) {
            printHeader(pw, entry.getKey(), entry.getValue());
        }
        for (String cookieHeader : cookieHeaders) {
            printHeader(pw, "Set-Cookie", cookieHeader);
        }
        if (getHeader("connection") == null) {
            printHeader(pw, "Connection", (keepAlive ? "keep-alive" : "close"));
        }
        long pending = data != null ? contentLength : 0;
        if (requestMethod != Method.HEAD && chunkedTransfer) {
            printHeader(pw, "Transfer-Encoding", "chunked");
        }
        pw.append("\r\n");
        pw.flush();

        run.run(); // <-- your streaming happens here

        outputStream.flush();
        NanoHTTPD.safeClose(data);
    } catch (IOException ioe) {
        NanoHTTPD.LOG.log(Level.SEVERE, "Could not send response to the client", ioe);
    }
}
    public final Response serve(IHTTPSession session) {
        OutputStream outputStream = session.getOutputStream();

        newFixedLengthResponse("").sender(outputStream, () -> {
            new OutputStreamWriter(outputStream).write("Yo, World!");
        } ;

        return null;
    }
//            throw new ResponseException(Status.INTERNAL_ERROR, "SERVER INTERNAL ERROR: Serve() returned a null response.");
            return;

Failed resolution of: Lcom/google/android/gms/common/internal/zzbq for MiniControllerFragment

copy iconCopydownload iconDownload
implementation 'com.google.android.gms:play-services-cast-framework:15.0.0'

Marathon | Java Driver on a JNLP application - No Top Level Window Available

copy iconCopydownload iconDownload
driver.switchTo().window("Topaz Client");

Android Java: AlertDialog method called from another class causes null pointer exception

copy iconCopydownload iconDownload
public static Context context;
context = this;
new Handler(Looper.getMainLooper()).post(new Runnable(){
            @Override
            public void run(){

                new AlertDialog.Builder(context)
                        .setTitle("Warning, some fields are empty")
                        .setNegativeButton("OK",new DialogInterface.OnClickListener(){
                            @Override
                            public void onClick(DialogInterface dialogInterface,int i){
                                dialogInterface.cancel();
                                showNotification=false;
                            }
                        }).show();

            }
        });
-----------------------
public static Context context;
context = this;
new Handler(Looper.getMainLooper()).post(new Runnable(){
            @Override
            public void run(){

                new AlertDialog.Builder(context)
                        .setTitle("Warning, some fields are empty")
                        .setNegativeButton("OK",new DialogInterface.OnClickListener(){
                            @Override
                            public void onClick(DialogInterface dialogInterface,int i){
                                dialogInterface.cancel();
                                showNotification=false;
                            }
                        }).show();

            }
        });
-----------------------
public static Context context;
context = this;
new Handler(Looper.getMainLooper()).post(new Runnable(){
            @Override
            public void run(){

                new AlertDialog.Builder(context)
                        .setTitle("Warning, some fields are empty")
                        .setNegativeButton("OK",new DialogInterface.OnClickListener(){
                            @Override
                            public void onClick(DialogInterface dialogInterface,int i){
                                dialogInterface.cancel();
                                showNotification=false;
                            }
                        }).show();

            }
        });

Community Discussions

Trending Discussions on nanohttpd
  • How download an installed app with nanohttpd
  • NanoHTTPD - write to a socket instead of copy a string to deliver pages
  • Sonarqube Critical error: wait for JVM process failed Windows
  • Failed resolution of: Lcom/google/android/gms/common/internal/zzbq for MiniControllerFragment
  • Marathon | Java Driver on a JNLP application - No Top Level Window Available
  • Build a restapi in android from JSON
  • Spring Boot Azure CosmosDB NoClassDefFoundError: Could not initialize class com.azure.data.cosmos.internal.directconnectivity.rntbd.RntbdConstants
  • Android Java: AlertDialog method called from another class causes null pointer exception
Trending Discussions on nanohttpd

QUESTION

How download an installed app with nanohttpd

Asked 2021-Sep-01 at 11:51

Hello i want to make a http server with nanohttpd that shows installed apps, and convert them to apk and download. I can list but how can i download the app i select

List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA;
for (ApplicationInfo packageInfo : packages) {

        String name = String.valueOf(packageManager.getApplicationLabel(packageInfo));
        if (name.isEmpty()) {
            name = packageInfo.packageName;
        }
        Drawable icon = packageManager.getApplicationIcon(packageInfo);
        String apkPath = packageInfo.sourceDir;
        apps.add(new App(name, apkPath, icon, packageInfo.packageName));
}

if (method.equals(Method.GET)) {
    for (App file : apps) {

        answer += "<a href=\"" + file.getAppName()
                + "\" alt = \"\">" + file.getAppName()
                + "</a><br>";
    }

     

ANSWER

Answered 2021-Sep-01 at 11:51

Ok, I basicly take the url after list the apps and check which appname equal to url after that i start to download it like that

 if (method.equals(Method.GET)) {
            if (a) {
                answer = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; " +
                        "charset=utf-8\"><title> HTTP File Browser</title>";
                for (App file : appShare) {
                    answer += "<a href=\"" + file.getAppName()
                            + "\" alt = \"\">" + file.getAppName()
                            + "</a><br>";
                }
                answer += "</head></html>";
                if(blabla.equals(header.get("referer"))){
                    a=false;
                }

            } else {
                for (int i = 0; i < appShare.size(); i++) {
                    if (appShare.get(i).getAppName().equals(appnames))
                        arrayC = i;
                }
                answer = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; " +
                        "charset=utf-8\"><title> Download " + appShare.get(arrayC).getAppName() + "</title>";
                // serve file download
                InputStream inputStream;
                Response response = null;

                if (mStatusUpdateListener != null) {
                    mStatusUpdateListener.onDownloadingFile(
                            new File(appShare.get(arrayC).getApkPath()), false);
                }

                try {
                    inputStream = new FileInputStream(

                            new File(appShare.get(arrayC).getApkPath()));
                    response = new DownloadResponse(

                            new File(appShare.get(arrayC).getApkPath()), inputStream);
                } catch (Exception e) {
                    e.printStackTrace();
                }            response.addHeader(
                        "Content-Disposition", "attachment; filename=" + appShare.get(arrayC).getAppName()+".apk");
                return response;


            }

Source https://stackoverflow.com/questions/68970840

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install nanohttpd

We'll create a custom HTTP server project using Maven for build/dep system. This tutorial assumes you are using a Unix variant and a shell. First, install Maven and Java SDK if not already installed. Then run:. You should now have a HTTP file server running on http://localhost:8080/.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.