Topic
  • 4 replies
  • Latest Post - ‏2015-08-05T06:41:16Z by IMDAAD
Live_Wire
Live_Wire
20 Posts

Pinned topic Consume Maximo RESTful Service using Java

‏2014-01-06T14:31:36Z |

I am using Maximo 7.5.0.3 REST API and want to write REST client in java to consume this RESTful service. I have enabled Maximo security in Maximo 7.5 side to keep the Maximo users to access its own REST services. The below is my Java code to consume above same RESTful service. I am getting 401 error and though I am giving credentials as property, it is not authorizing it.  Please see the attached code(ClientCode.jpg).

Please check the output in "ConsoleResponse.jpg".

Note: I am successfully able to query the same Maximo REST service using the Chrome's Postman plugin. Below 2 are my Postman's (REST client) Headers. 1. MAXAUTH - bWF4YWRtaW46bWF4YWRtaW4= 2. Accept - Application/xml

Though I have given the authorization (MAXAUTH) in headers, I used to get the pop-up window to enter username and password to query Maximo REST service. Once I give the credentials, I get the response (Response.jpg).

 

Please help me to consume the Maximo RESTful service (when native Authentication enabled) using Java code.

 

Thanks in Advance.

Mohan

  • ExInEx
    ExInEx
    88 Posts

    Re: Consume Maximo RESTful Service using Java

    ‏2014-01-09T08:24:22Z  

    'mxintadm' is set in 'mxe.int.dfltuser' System property?

    http://pic.dhe.ibm.com/infocenter/tivihelp/v49r1/topic/com.ibm.mif.doc/gp_intfrmwk/r_integration_props.html

  • TomKennedy
    TomKennedy
    301 Posts

    Re: Consume Maximo RESTful Service using Java

    ‏2015-07-16T16:18:00Z  

    I am using MAM 7.6 with application security set and using Blue Pages for authentication.

     

    I am using same code and have same issue.

    I tried to use maxadmin and mxintadm users, but that does not work.

    I also set the user and password in the URL.

    Any ideass?

     

  • TomKennedy
    TomKennedy
    301 Posts

    Re: Consume Maximo RESTful Service using Java

    ‏2015-07-16T19:05:53Z  

    Here is solution based on code above.  It support getting a ticket and adding a ticket.

     

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.xml.bind.DatatypeConverter;

    public class RESTConsume {
       
        // http://localhost:8080/RESTfulExample/json/product/get
        public static void main(String[] args) {
            
            try {         
            //  String baseURL="XXXXX/maxrest/rest/os";  // Production
                String baseURL="XXXXX/maxrest/rest/os";  // Testing
                String opt=null;
                String ticketid=null;
                String elmsreq=null;
                if ( args.length != 2 ) {
            usage();          
            }
                opt=args[0];              
                if (! opt.equals("GET") && ! opt.equals("POST")  ) {
               usage();
            }
                            
                if ( opt.equals("GET")  ) {
                  ticketid=args[1];
                }
                if ( opt.equals("POST") ) {
                  elmsreq=args[1];
                }

                                                         //Username      password
                String userPassword = "YYYY" + ":" + "YYYY";
            String encoding = DatatypeConverter.printBase64Binary(userPassword.getBytes());
                URL url = null;
                if ( opt.equals("GET")) {
                  url=new URL(baseURL+"/mxsr?ticketid="+ticketid);
            } else {
                  url=new URL(baseURL+"/mxsr?description=elmsdefault&description_longdescription=elmsdetails");
            }
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod(opt);
                connection.setRequestProperty("Accept", "Application/xml");
                connection.setRequestProperty("Authorization", "Basic " + encoding);
                System.out.println("Output from Server ....1 \n");

                /*
                 * if (conn.getResponseCode() != 200) {
                 * System.out.println("Output from Server ....2 \n");
                 *
                 * throw new RuntimeException("Failed : HTTP error code : "+
                 * conn.getResponseCode()); }
                 */
                System.out.println("Output from Server ....3 \n");

                BufferedReader br = new BufferedReader(new InputStreamReader(
                        (connection.getInputStream())));
                System.out.println("Output from Server ....4 \n");
             
                String output;
                System.out.println("Output from Server .... \n");
                while ((output = br.readLine()) != null) {
            
            System.out.println(output);
                }
               

            } catch (MalformedURLException e) {

                e.printStackTrace();

            } catch (IOException e) {

                e.printStackTrace();
            System.out.println(e.toString());

            }

        }

        public static void usage() {
        System.out.println("Usage: RESTConsume GET TICKET_ID | POST ELMSREQ");
            System.exit(1);
        }

    }

  • IMDAAD
    IMDAAD
    1 Post

    Re: Consume Maximo RESTful Service using Java

    ‏2015-08-05T06:41:16Z  

    hi,

     Can anyone help me out in how to get "host name"  for IBM maximo in cloud