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

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

不言
不言forward
2018-10-22 16:27:552568browse

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://<p>Execution results: It took a total of 1.4 seconds including network overhead. </p><p></p><p style="text-align: center;"><span class="img-wrap"><img src="https://img.php.cn//upload/image/431/174/207/1540196741948139.jpg" title="1540196741948139.jpg" alt="A brief analysis of nodejs and Java access to remote server services"></span></p>java<p><strong></strong>WANGJER in the code below is my username and 123456 is the password. The login method used is Basic Authentication. </p><pre class="brush:php;toolbar:false">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://<p>The execution result is almost as time-consuming as nodejs. </p><p> 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. </p><p></p><p class="comments-box-content"></p>

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!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete