public class

Net

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.Net

Class Overview

Network routines class. Proxy supported; http/https redirects supported.

Summary

Public Constructors
Net()
Create a default object for a direct Internet connections.
Net(Proxy proxy)
Create a default object with optional proxy settings: The user-agent is set to "PNF Software UP"; the timeouts are set to 60 seconds for connect, 30 seconds for read; redirects are followed.
Public Methods
static String buildProxyString(Proxy p)
Create a string representing the internal state of a network proxy object.
synchronized byte[] downloadBinary(String address)
Issue a GET request and receive the answer.
synchronized int getConnectTimeout()
synchronized Proxy getProxy()
synchronized int getReadTimeout()
synchronized String getUserAgent()
synchronized String httpPost(String address, String data)
synchronized String httpPost(String address, String data, long[] serverTimestampArray)
Convenience routine to send POST data to the JPS or the floating license controller.
static Proxy parseProxyString(String s)
Parse a string representing basic proxy settings.
synchronized void setConnectTimeout(int timeout)
synchronized void setFollowAllRedirects(boolean follow_all_redirects)
synchronized void setProxy(Proxy proxy)
synchronized void setReadTimeout(int timeout)
synchronized void setUserAgent(String userAgent)
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Net ()

Create a default object for a direct Internet connections. Same as Net(null).

public Net (Proxy proxy)

Create a default object with optional proxy settings: The user-agent is set to "PNF Software UP"; the timeouts are set to 60 seconds for connect, 30 seconds for read; redirects are followed.

Parameters
proxy optional proxy configuration

Public Methods

public static String buildProxyString (Proxy p)

Create a string representing the internal state of a network proxy object. To be used in conjunction with parseProxyString(String).

Returns
  • the proxy-representing string, null on error. An empty string means a direct (ie, non-proxied) connection

public synchronized byte[] downloadBinary (String address)

Issue a GET request and receive the answer. If the content is gzip-ed, it will be returned as decoded.

Parameters
address the HTTP or HTTPS URL
Returns
  • response bytes, or null on error

public synchronized int getConnectTimeout ()

public synchronized Proxy getProxy ()

public synchronized int getReadTimeout ()

public synchronized String getUserAgent ()

public synchronized String httpPost (String address, String data)

public synchronized String httpPost (String address, String data, long[] serverTimestampArray)

Convenience routine to send POST data to the JPS or the floating license controller.

Do not use this method to http-post just anything. The data string to be posted will be:

  • URL-encoded using UTF8
  • prepended with "data="

The server's response, if any, must be a sequence of strings. The strings will be concatenated with newline characters and returned as a single string object.

Parameters
address string to be posted
data HTTP URL (HTTPS not supported as of now)
serverTimestampArray optional, filled with the server timestamp provided in the HTTP response (epoch in ms)
Returns
  • the server response, as a unique string (see description above), or null on error

public static Proxy parseProxyString (String s)

Parse a string representing basic proxy settings. The format is: type|hostname|port where type can be either "http" or "socks".

Parameters
s the non-null string
Returns
  • a proxy object, null on error

public synchronized void setConnectTimeout (int timeout)

public synchronized void setFollowAllRedirects (boolean follow_all_redirects)

public synchronized void setProxy (Proxy proxy)

public synchronized void setReadTimeout (int timeout)

public synchronized void setUserAgent (String userAgent)