Try using JobScheduler's REST-API --Java RestClient Test class-

Try using JobScheduler's REST-API --Java RestClient Test class implementation--

1. JobScheduler REST-Source for Test class for API.

Save it with the source file name /tmp/kaeru/

Please check this article for the detailed procedure.

Please check here for the sample code of the Client body that is actually used from this class.


package kaeru;

 *Client class for making REST requests (for testing)
 * @author S.Yatabe

import com.sun.jersey.api.client.Client;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class RestTest {

    public static void main(String[] args) {

        //Character string to be set in the request body
        String bodyStr = "";

        //Rest-Access Token issued by API
        String autKey = "";

        //Jason Mapper
        ObjectMapper mapper = null;

        //For Jason Perth
        JsonNode root = null;

        //Instance client for basic authentication
        RestClient client = new RestClient( "root", "root" );

        //Rest-First perform Basic authentication to issue API Access Token
        String uri = "http://localhost:4446/joc/api/security/login"; // specify URI

        //Post request execution
        String data = uri, bodyStr, MediaType.APPLICATION_JSON_TYPE, null );

        try {
            //JsonParser generation
            mapper = new ObjectMapper();
            root   = mapper.readTree(data);

            //Get an Access Token
            autKey = root.get( "accessToken" ).asText();

        } catch (JsonParseException e) {
        } catch ( Exception e){

        //Set the issued Access Token and Rest-Execute a query with API

        //Get JobScheduler order list information
        uri = "http://localhost:4446/joc/api/orders/"; // specify URI

        //Generate Request body
        StringBuilder bodyStrBuffer = new StringBuilder();
        bodyStrBuffer.append(" { \"jobschedulerId\": \"scheduler\" }" );
        bodyStr = bodyStrBuffer.toString();

        //Instance a version of the client that embeds an Access Token in HeadeField
        client = new RestClient( null, null );

        //Execute a POST request
        data = uri, bodyStr, MediaType.APPLICATION_JSON_TYPE, autKey );
        System.out.println( data );

        //Easy parsing of Json format data with hierarchical structure
        try {

            //JsonParser generation
            mapper = new ObjectMapper();
            root = mapper.readTree( data );

            //Variable to store return data in Json format
            String job     = "";
            String path    = "";
            String orderId = "";
            String pState  = "";
            String nextStartTime = "";

            //Hierarchically parse the orders node
            for ( JsonNode n : root.get("orders") ) {
                    job            = n.get( "job"     ).asText();
                    path           = n.get( "path"    ).asText();
                    orderId        = n.get( "orderId" ).asText();
                    pState         = n.get( "processingState" ).get( "_text" ).asText();
                    nextStartTime  = "";
                    if ( n.get( "nextStartTime" ) != null ){
                        nextStartTime = n.get( "nextStartTime" ).asText();

                    //Result output
                    System.out.println( "[orderId]: " +orderId+ " [job]: " +job+ " [path]: "
                     +path+ " [status]: "+pState+ " [nextStart]: "+nextStartTime );


        } catch (JsonParseException e) {
        } catch ( Exception e){

Recommended Posts

Try using JobScheduler's REST-API --Java RestClient Test class-
Try using JobScheduler's REST-API --Java RestClient implementation--
Try using JobScheduler's REST-API
Try using RocksDB in Java
Try scraping using java [Notes]
Implement Thread in Java and try using anonymous class, lambda
Try using Redis with Java (jar)
[Java] Try to implement using generics
Try using IBM Java method tracing
Try using Hyperledger Iroha's Java SDK
[Java] Where did you try using java?
Try using Java framework Nablarch [Web application]
Try using the Stream API in Java
Study Java Try using Scanner or Map
Try using JSON format API in Java
[Java] Test S3 upload / download using "S3 ninja"
Try using the Wii remote with Java
Try using Firebase Cloud Functions on Android (Java)
Try using Sourcetrail (win version) in Java code
Try using GCP's Cloud Vision API in Java
Try using Sourcetrail (macOS version) in Java code
Try similar search of Image Search using Java SDK [Search]
Try accessing the dataset from Java using JZOS
Try communication using gRPC on Android + Java server
Try using the COTOHA API parsing in Java
Story of test automation using Appium [Android / java]
Try using libGDX
Java class methods
[Java] Class inheritance
java Scanner class
Try using Maven
Try using powermock-mockito2-2.0.2
Java HashMap class
Try using GraalVM
Try Java 8 Stream
Try using jmockit 1.48
Try using sql-migrate
java (abstract class)
[Java] Nested class
Java anonymous class
Try using SwiftLint
Try using Log4j 2.0
About Java class
[java] abstract class
[Java] Object class
Roughly try Java 9
Java local class
Try implementing the Eratosthenes sieve using the Java standard library
Try Image Search's similar search using Java SDK [Registration]
Test field-injected class in Spring boot test without using Spring container
Try image classification using TensorFlow Lite on Android (JAVA)
Try global hooking in Java using the JNativeHook library
Try to build a Java development environment using Docker