RMI null GenericValue userLogin problem.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

RMI null GenericValue userLogin problem.

mariotti
Hi,

I am trying to interact with OfBiz using RMI.
I got the example code from:
ExampleRemoteClient.java

Everything works fine with the test message:

        context.put("message", "Remote Service Test");
        return rd.runSync("testScv", context);
        ...
       

But if I try to access the userLogin service:
        res = rd.runSync("userLogin", UtilMisc.toMap("login.username", username, "login.password", password));

I am unable to access the results "res".

As a test code I have:

        res = rd.runSync("userLogin", UtilMisc.toMap("login.username", username, "login.password", password));

        resultCollValues = res.values();

        Set rkv = res.keySet();
        Collection rcv = resultCollValues;

        if (res.keySet().isEmpty()) {
            System.out.println("---: Service Result Map Key: EMPTY!!!");
        } else {
            for (Object o : rkv) {
                System.out.println("---: Service Result Map Keys Objs: "+o.getClass().getName());
                System.out.println("---: Service Result Map Keys String: "+o.toString());
                Object kv = res.get(o.toString());
                System.out.println("---: Service Result Map KV Objs: "+kv.getClass().getName());
                // ERROR: System.out.println("---: Service Result Map KV String: "+kv.toString());
               
            }
        }

The Error is typically: java.lang.NullPointerException

I am new to both OfBiz and Java.. so maybe I am doing something fundamentally wrong ;)

The generic question is: what is the best way to access the result from the
remoteDispatcher.runSync()?

Or alternatively, How can I handle the GV Object?

I am accessing OfBiz from an external application I started to write in Spring.

Thank a lot

Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

mariotti
Problem partially solved!

This class works!

public class Auth {

    protected final static String RMI_URL = "rmi://localhost:1099/RMIDispatcher"; // change to match the remote server
    protected RemoteDispatcher rd = null;

    public Auth() {
        try {
            rd = (RemoteDispatcher) Naming.lookup(RMI_URL);
        } catch (NotBoundException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    //public Map<String, Object> userLogin(String username, String password)
    public void userLogin(String username, String password)
        throws RemoteException, GenericServiceException {

        String resultKeys;
        Map res;


        res = rd.runSync("userLogin", UtilMisc.toMap("login.username", username, "login.password", password));
        System.out.println("---: Service Result RES | class name:"+res.getClass().getName());
       
        if (res.containsKey("userLogin")){
            Object o = res.get("userLogin");
            System.out.println("---: Service Result RES | o get class name:"+o.getClass().getName());

            GenericValue gv = (GenericValue) res.get("userLogin");
            System.out.println("---: Service Result RES | gv get class name :"+gv.getClass().getName());

            Map rmap = gv.getAllFields();

            // TEST: System.out.println("---: Service Result RES RMAP:"+rmap.get("userLogin"));

            if (res.keySet().isEmpty()) {
                System.out.println("---: Service Result RES: IS EMPTY!!!");
            } else {
                resultKeys = rmap.keySet().toString();
                System.out.println("---: Service Result RES | RMAP Keys:"+resultKeys);

                for ( Object m :  rmap.keySet()){
                    System.out.println("---: Service Result RES | RMAP - KEY: "+m.toString());
                    System.out.println("---:                      VALUE: "+rmap.get(m.toString()));
                   
                }

            }

           
        }
       
    }

}

The method just gets all possible fields out of the userLogin RMI call. I guess.

It has all the dependencies of the ExampleRemoteClient.java set (see comments within that file).
[The dependencies might be a bit less, but I did not want really to check at the moment ;)]

If you read the output of this class call to userLogin, it has nothing to do with the userLogin service!!!
as exposed in:

https://demo-trunk.ofbiz.apache.org/webtools/control/ServiceList?sel_service_name=userLogin

The output is:

---: Service Result RES | class name:javolution.util.FastMap
---: Service Result RES | o get class name:org.ofbiz.entity.GenericValue
---: Service Result RES | gv get class name :org.ofbiz.entity.GenericValue
---: Service Result RES | RMAP Keys:[successiveFailedLogins, enabled, lastUpdatedStamp, lastCurrencyUom, passwordHint, lastTimeZone, userLoginId, externalAuthId, hasLoggedOut, isSystem, currentPassword, requirePasswordChange, createdTxStamp, createdStamp, partyId, userLdapDn, lastLocale, disabledDateTime, lastUpdatedTxStamp]
---: Service Result RES | RMAP - KEY: successiveFailedLogins
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: enabled
---:                      VALUE: Y
---: Service Result RES | RMAP - KEY: lastUpdatedStamp
---:                      VALUE: 2013-10-11 22:57:19.849
---: Service Result RES | RMAP - KEY: lastCurrencyUom
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: passwordHint
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: lastTimeZone
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: userLoginId
---:                      VALUE: admin
---: Service Result RES | RMAP - KEY: externalAuthId
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: hasLoggedOut
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: isSystem
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: currentPassword
---:                      VALUE: {SHA}47ca69ebb4bdc9ae0adec130880165d2cc05db1a
---: Service Result RES | RMAP - KEY: requirePasswordChange
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: createdTxStamp
---:                      VALUE: 2013-10-11 22:57:06.338
---: Service Result RES | RMAP - KEY: createdStamp
---:                      VALUE: 2013-10-11 22:57:06.39
---: Service Result RES | RMAP - KEY: partyId
---:                      VALUE: admin
---: Service Result RES | RMAP - KEY: userLdapDn
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: lastLocale
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: disabledDateTime
---:                      VALUE: null
---: Service Result RES | RMAP - KEY: lastUpdatedTxStamp
---:                      VALUE: 2013-10-11 22:57:18.719

(btw: it is a demo ofbiz installation)

It is clear that they are obviously related:
Changing export=true to export=false
in
./framework/common/servicedef/services.xml
Changes the behavior, I cannot access it.

Sorry for confusion.

Did anybody worked on RMI access to OfBiz?

What I would like to achieve at the end is:
An interface that given admin credential can expose some data from OfBiz for a given Party/User.
As you see, at present I have difficulties to even login!

My idea was that to call a service under given credentials, I need to get some credentials first via
userLogin. But it looks like not to be the case.

Anybody with a similar problem?

cheers
F

Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

Jacques Le Roux
Administrator
I have never done that with RMI, but if you want to externally access to an OFBiz SOAP web service which has auth=true then you need to pass the credential

Jacques

On Wednesday, October 30, 2013 10:05 PM mariotti <[hidden email]> wrote:

> Problem partially solved!
>
> This class works!
>
> public class Auth {
>
>    protected final static String RMI_URL =
> "rmi://localhost:1099/RMIDispatcher"; // change to match the remote server
>    protected RemoteDispatcher rd = null;
>
>    public Auth() {
>        try {
>            rd = (RemoteDispatcher) Naming.lookup(RMI_URL);
>        } catch (NotBoundException e) {
>            e.printStackTrace();
>        } catch (MalformedURLException e) {
>            e.printStackTrace();
>        } catch (RemoteException e) {
>            e.printStackTrace();
>        }
>    }
>
>    //public Map<String, Object> userLogin(String username, String password)
>    public void userLogin(String username, String password)
> throws RemoteException, GenericServiceException {
>
> String resultKeys;
> Map res;
>
>
> res = rd.runSync("userLogin", UtilMisc.toMap("login.username", username,
> "login.password", password));
> System.out.println("---: Service Result RES | class
> name:"+res.getClass().getName());
>
> if (res.containsKey("userLogin")){
>     Object o = res.get("userLogin");
>     System.out.println("---: Service Result RES | o get class
> name:"+o.getClass().getName());
>
>     GenericValue gv = (GenericValue) res.get("userLogin");
>     System.out.println("---: Service Result RES | gv get class name
> :"+gv.getClass().getName());
>
>     Map rmap = gv.getAllFields();
>
>     // TEST: System.out.println("---: Service Result RES
> RMAP:"+rmap.get("userLogin"));
>
>     if (res.keySet().isEmpty()) {
> System.out.println("---: Service Result RES: IS EMPTY!!!");
>     } else {
> resultKeys = rmap.keySet().toString();
> System.out.println("---: Service Result RES | RMAP Keys:"+resultKeys);
>
> for ( Object m :  rmap.keySet()){
>     System.out.println("---: Service Result RES | RMAP - KEY:
> "+m.toString());
>     System.out.println("---:                      VALUE:
> "+rmap.get(m.toString()));
>
> }
>
>     }
>
>
> }
>
>    }
>
> }
>
> The method just gets all possible fields out of the userLogin RMI call. I
> guess.
>
> It has all the dependencies of the ExampleRemoteClient.java set (see
> comments within that file).
> [The dependencies might be a bit less, but I did not want really to check at
> the moment ;)]
>
> If you read the output of this class call to userLogin, it has nothing to do
> with the userLogin service!!!
> as exposed in:
>
> https://demo-trunk.ofbiz.apache.org/webtools/control/ServiceList?sel_service_name=userLogin
>
> The output is:
>
> ---: Service Result RES | class name:javolution.util.FastMap
> ---: Service Result RES | o get class name:org.ofbiz.entity.GenericValue
> ---: Service Result RES | gv get class name :org.ofbiz.entity.GenericValue
> ---: Service Result RES | RMAP Keys:[successiveFailedLogins, enabled,
> lastUpdatedStamp, lastCurrencyUom, passwordHint, lastTimeZone, userLoginId,
> externalAuthId, hasLoggedOut, isSystem, currentPassword,
> requirePasswordChange, createdTxStamp, createdStamp, partyId, userLdapDn,
> lastLocale, disabledDateTime, lastUpdatedTxStamp]
> ---: Service Result RES | RMAP - KEY: successiveFailedLogins
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: enabled
> ---:                      VALUE: Y
> ---: Service Result RES | RMAP - KEY: lastUpdatedStamp
> ---:                      VALUE: 2013-10-11 22:57:19.849
> ---: Service Result RES | RMAP - KEY: lastCurrencyUom
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: passwordHint
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: lastTimeZone
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: userLoginId
> ---:                      VALUE: admin
> ---: Service Result RES | RMAP - KEY: externalAuthId
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: hasLoggedOut
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: isSystem
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: currentPassword
> ---:                      VALUE:
> {SHA}47ca69ebb4bdc9ae0adec130880165d2cc05db1a
> ---: Service Result RES | RMAP - KEY: requirePasswordChange
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: createdTxStamp
> ---:                      VALUE: 2013-10-11 22:57:06.338
> ---: Service Result RES | RMAP - KEY: createdStamp
> ---:                      VALUE: 2013-10-11 22:57:06.39
> ---: Service Result RES | RMAP - KEY: partyId
> ---:                      VALUE: admin
> ---: Service Result RES | RMAP - KEY: userLdapDn
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: lastLocale
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: disabledDateTime
> ---:                      VALUE: null
> ---: Service Result RES | RMAP - KEY: lastUpdatedTxStamp
> ---:                      VALUE: 2013-10-11 22:57:18.719
>
> (btw: it is a demo ofbiz installation)
>
> It is clear that they are obviously related:
> Changing export=true to export=false
> in
> ./framework/common/servicedef/services.xml
> Changes the behavior, I cannot access it.
>
> Sorry for confusion.
>
> Did anybody worked on RMI access to OfBiz?
>
> What I would like to achieve at the end is:
> An interface that given admin credential can expose some data from OfBiz for
> a given Party/User.
> As you see, at present I have difficulties to even login!
>
> My idea was that to call a service under given credentials, I need to get
> some credentials first via
> userLogin. But it looks like not to be the case.
>
> Anybody with a similar problem?
>
> cheers
> F
Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

mariotti
Done!

I have all the possible calls done with RMI. It works great. Debugging was a pain.

The worst problem was to deal with the logger.

I will be happy to give here details only if you ask explicitly.

But, Why should I use SOAP?
Or better, why did you use sOAP?



Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

Jacques Le Roux
Administrator
On Wednesday, January 08, 2014 4:16 AM, [hidden email] wrote

> Done!
>
> I have all the possible calls done with RMI. It works great. Debugging was a
> pain.
>
> The worst problem was to deal with the logger.
>
> I will be happy to give here details only if you ask explicitly.
>
> But, Why should I use SOAP?
> Or better, why did you use sOAP?

Actually I often used SOAP because it was a requirement for projects. But then why this requirement? Because of firewalls RMI can be a pain.
With my last large project, we began mostly with SOAP, had some RMI (faster) and finally ended with mostly REST

HTH

Jacques
Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

mariotti
RMI is indeed a pain.

Especially while developing, even without a firewall!

I think in particular because of the way RMI works.

I had to disable the logger here:

disable.log4j.config=true

because it would keep looking for a local logger.... which I did not have.
That single line was my most pain, in particular for missing error information.

I could then revers engineering every call and that was a trumpet! (I slightly like violins).

Then you agree with me that RMI should be (faster). For reasons I do not grasp yet.

To achieve REST you should had to modify pretty good amount
of ofbiz services or done a lot of serialization on top of SOAP.

Right now I am prototyping and I would not yet go for a big adventure.
(even if RMI alone was a good deal of work)
But of course I appreciate already the answer!

I would be happy to help for any simple RMI question. But because I cannot follow everything
drop in this discussion a reference to a question.

For Jacques indeed: how easy is to do REST?

cheers
F



Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

Jacques Le Roux
Administrator
On Saturday, January 11, 2014 11:34 PM, [hidden email] wrote
> Then you agree with me that RMI should be (faster). For reasons I do not
> grasp yet.

Less verbose than any others, objects are sent serialized on the wire. Also another concern, objects must be serializable
 
> To achieve REST you should had to modify pretty good amount
> of ofbiz services or done a lot of serialization on top of SOAP.

I must say I only used external REST services.

> For Jacques indeed: how easy is to do REST?

In OFBiz there is nothing really RESTful. Chris Snow made some efforts in 2010, but did not complete.
https://cwiki.apache.org/confluence/display/OFBIZ/REST+Service+Implementation
https://cwiki.apache.org/confluence/display/OFBIZ/Export+service+using+REST
Adrian also began something more recently in Jira
https://issues.apache.org/jira/browse/OFBIZ-4274
And in 2010 also Chatree contributed something (hard to review)
https://issues.apache.org/jira/browse/OFBIZ-3877

HTH

Jacques
 
> cheers
> F
Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

mariotti
This post was updated on .
mmm...
Then probably "fastness" is a relative concept.

What I would like to achieve is an external application which uses ofbiz and scales.

The application might not need to access ofbiz all the time, i.e. it should scales on its own by spawning
itself on different servers (see amazon ec2). I think that using RMI in this context might make sense (correct me please)
because the overload of "serialization" is on the client (which can scale easier),
and I think there is even a bit more then simple serialization because
RMI insist on executing on the client side part of the code before the actual serialization.
(it is not only required the interface to the objects, but also the actual code, see for example my problem with the logger)
I am not an expert in RMI! This is only reverse engineering! I might be wrong!

This was a new concept for me, coming from plain old RPC.

Indeed REST is probably "network" fast but would not account for the load on the servers. (not that RMI does).
Or in other words you might need to scale ofbiz itself. It is already a solution I am considering.
If all MySQL calls can be assumed to be atomic, which should be the case.

I guess that the optimal solution is the one that works.
But in this respect: would OfBiz move toward REST? And optimize it for that?
Or would it move toward a solid accounting engine library?

Thanks a lot!
F

PS: @Jacques Thanks a lot for the already ongoing discussion. I wish some more participant ;)
Just to see the feelings...

Sorry: Probably we should move this on a new post. But there is not many about RMI.
Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

Jacques Le Roux
Administrator
On Monday, January 13, 2014 8:39 PM, [hidden email] wrote

> mmm...
> Then probably "fastness" is a relative concept.
>
> What I would like to achieve is an external application which uses ofbiz and
> scales.
>
> The application might not need to access ofbiz all the time, i.e. it should
> scales on its own by spawning
> itself on different servers (see amazon ec2). I think that using RMI in this
> context might make sense (correct me please)

Yes as long as you don't fear firewalls settings

> because the overload of "serialization" is on the client (which can scale
> easier),
> and I think there is even a bit more then simple serialization because
> RMI insist on executing on the client side part of the code before the
> actual serialization.
> (it is not only required the interface to the objects, but also the actual
> code, see for example my problem with the logger)

Sorry, I don't remember your problem with the logger :)

> I am not an expert in RMI! This is only reverse engineering! I might be
> wrong!
>
> This was a new concept for me, coming from plain old RPC.
>
> Indeed REST is probably "network" fast but would not account for the load on
> the servers. (not that RMI does).
> Or in other words you might need to scale ofbiz itself. It is already a
> solution I am considering.
> If all MySQL calls can be assumed to be atomic, which should be the case.
>
> I guess that the optimal solution is the one that works.
> But in this respect: would OfBiz move toward REST?

I don't see that moves coming soon. OFBiz was built in the pre REST era. Then SOAP was the defacto web services standard.
Something to consider, though bloated SOAP is still ahead of REST in term of security
https://stackoverflow.com/questions/853620/secure-web-services-rest-over-https-vs-soap-ws-security-which-is-better
If you need most secured RMI, then use SSH Tunneling http://www.javaranch.com/journal/2003/10/rmi-ssh_p1.html

>And optimize it for that?
> Or would it move toward a solid accounting engine library?

Hu? How it relates?

Jacques
 
> Thanks a lot!
> F
Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

mariotti
Just a quick answer, coming back soon, but: RMI is done within an internal network.
Not yet SSL/SSH but not seeing the need though.
We should trust the network before to even think RMI. should we?
Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

Pierre Smits
I would definitely say that transfering data between two endpoints must go
through an encrypted tunnel. No matter what the protocol is. Not only could
you be transmitting business critical data, but also privacy sensitive data.

Pierre Smits

*ORRTIZ.COM <http://www.orrtiz.com>*
Services & Solutions for Cloud-
Based Manufacturing, Professional
Services and Retail & Trade
http://www.orrtiz.com


On Wed, Jan 15, 2014 at 10:28 PM, mariotti <[hidden email]> wrote:

> Just a quick answer, coming back soon, but: RMI is done within an internal
> network.
> Not yet SSL/SSH but not seeing the need though.
> We should trust the network before to even think RMI. should we?
>
>
>
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/RMI-null-GenericValue-userLogin-problem-tp4645375p4647279.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: RMI null GenericValue userLogin problem.

mariotti
Would you mind to argument.
I mean, I get your point. But I still do not see what better security I can offer beside an internal network.
Indeed the transfer is fully encrypted externally. It is only our backside which should deal with it.