Json Rest Client to beans with Jodd-http and Jackson

package gob.documental.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import gob.documental.DocsVars;
import gob.documental.web.acl.UserDataJson;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;

 * @author Fernando
public class AclServiceWs implements AclService{
    public UserDataJson login(String user, String pass){
        UserDataJson userData = new UserDataJson();
        String urlRest = DocsVars.sgmUrl + "rest/acceso/auth/userName/"+user+"/password/"+pass+"/get";
        Logger.getLogger(AclServiceWs.class.getName()).log(Level.INFO, "URL: {0}", urlRest);
        HttpRequest httpRequest = HttpRequest.get(urlRest);
        HttpResponse response = httpRequest.send();
        ObjectMapper mapper = new ObjectMapper();
        String bodyResp = response.bodyText();
        try {
            Logger.getLogger(AclServiceWs.class.getName()).log(Level.INFO, bodyResp);
            userData =  mapper.readValue(bodyResp, UserDataJson.class);
        } catch (IOException ex) {
            Logger.getLogger(AclServiceWs.class.getName()).log(Level.SEVERE, null, ex);
        // comprobar usuario existente:
            return userData;
        return null;


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s