开发者

Work with OData secured service

开发者 https://www.devze.com 2023-01-21 03:11 出处:网络
I want to generate entity classes and Service class of OData secured service. In OData Java extension page it is written that I need to use org.restlet.ext.odata.Generator class that should get uri an

I want to generate entity classes and Service class of OData secured service. In OData Java extension page it is written that I need to use org.restlet.ext.odata.Generator class that should get uri and output directory parameters. But if my OData service is s开发者_如何学编程ecured the generator instance is not able to generate service classes without username and password of the service. I did not find any way to pass username and password to generator class.

I get 401 HTTP response code.

Please help.


In the org.restlet.ext.odata.Generator class, in the method main, The following code would clear the credential details set in the setCredentials() method.

Service service = new Service(dataServiceUri);
if(service.getMetadata() == null)
{
  errorMessage = "Cannot retrieve the metadata.";
}

Kindly provide a solution for this issue as I am currently unable to generate the classes for my rest service as the service is secured with an user password.

I tried the following code to generate the code for my secured service uri:

import org.restlet.ext.odata.Generator;
import org.restlet.ext.odata.Service;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;

public class ODataRestletGenerator extends Service {

    public ODataRestletGenerator(String serviceUri) {
        super(serviceUri);
    }

    public static final String APPLICATION_URI = "http://ldcigkd.xxx.yyy.corp:50033/xxx/opu/sdata/IWCNT/CUSTOMER/";

    public static void main(String[] args) {

        // Add the client authentication to the call
        ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
        ChallengeResponse credentials = new ChallengeResponse(scheme, "user", "pwd");       
        new ODataRestletGenerator(APPLICATION_URI).setauth(credentials);

        String[] arguments = { APPLICATION_URI, "/customer/src" };
        Generator.main(arguments);
    }

    private void setauth(ChallengeResponse credentials) {

        super.setCredentials(credentials);
    }

}


In the org.restlet.ext.odata.Service subclass that is generated by OData extension, you can call setCredentials() and pass an instance of ChallengeResponse including scheme (BASIC?), login (identifier) and password (secret).

0

精彩评论

暂无评论...
验证码 换一张
取 消