10 Replies Latest reply on Jul 26, 2014 1:03 PM by Ramesh Reddy

    Accessing secured ODATA service in Java

    teiiduser Newbie

      Hello,

       

      We have an ODATA service in place and I am trying to write a consumer in Java. So here is the code so far:

       

      public class TestReadWrite{

        public static final String endpoint="http://localhost:8080/mydataserver/dsl.svc/";

        public static void main(String[] args) {

        TestReadWrite example = new TestReadWrite();

           example.run(args);

        }

       

        private void run(String[] args) {

        ODataConsumer c = ODataJerseyConsumer.create(endpoint);

        // list all products

          for (OEntity product : c.getEntities("Products").execute()) {

            reportEntity("Products: " + product.getProperty("name").getValue(), product);

          }

        }

       

      }

       

      This is a secured ODATA service so I get the error: Exception in thread "main" java.lang.RuntimeException: Expected status OK, found Unauthorized. Server response:

       

      How do I pass the username/password to this service?I tried searching but did not find a decent example. Can anyone help with a code snippet or any clear documentation on the same?

       

      Thank you!