Home > Java > Java Tutorial > body text

A brief analysis of nodejs and Java access to remote server services

不言
Release: 2018-10-22 16:27:55
forward
2430 people have browsed it

This article brings you a brief analysis of nodejs and Java services for accessing remote servers. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Since this article uses nodejs and Java to access remote server services, let’s first use another programming language, SAP’s ABAP (the programming language I use most in my daily work) to develop a service Bar.

This is the class I use to implement services in ABAP programming language: ZCL_DIS_HTTP_HANDLER

A brief analysis of nodejs and Java access to remote server services

##This class implements an interface defined in IF_HTTP_EXTENSION A method HANDLE_REQUEST.

A brief analysis of nodejs and Java access to remote server services

You don’t have to be confused by the unfamiliar syntax of ABAP. In fact, it is similar to Java Servlet.

A brief analysis of nodejs and Java access to remote server services

I drew a picture:

A brief analysis of nodejs and Java access to remote server services

Mine This remote service is very simple. No matter what the caller sends, it simply returns a text: HELLO WORLD.

Now we will use nodejs and Java to consume.

nodejs

A brief analysis of nodejs and Java access to remote server services##Look at the nodejs code.

The following code passes WANGJER into the Buffer as my username and 123456 as the password. The login method used is Basic Authentication.

var request = require('request');

var getTokenOptions = {

url: "https://

Execution results: It took a total of 1.4 seconds including network overhead.

A brief analysis of nodejs and Java access to remote server services

java

WANGJER in the code below is my username and 123456 is the password. The login method used is Basic Authentication.

package connectivity;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import org.apache.commons.codec.binary.Base64;

import java.util.stream.Collectors;

import org.apache.http.HttpResponse;

import org.apache.http.client.ClientProtocolException;

import org.apache.http.client.HttpClient;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.impl.client.HttpClientBuilder;

public class OPSystemConnectivity

{

static public void main(String[] arg){

final HttpGet get = new HttpGet("https://

The execution result is almost as time-consuming as nodejs.

Note that the method introduced in this article can not only access the services of the remote server, but also achieve the goal of resource downloading: such as downloading pictures, mp3, etc. on a certain server. You only need to pass the URL of the corresponding resource into the system.

Copy after login

The above is the detailed content of A brief analysis of nodejs and Java access to remote server services. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!