We're Hiring!

Adding own service to OMERO

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Adding own service to OMERO

Postby dwj » Thu Feb 18, 2016 11:06 am

Hi OMERO team,

I try to extend the omero server by an own service by following the description at http://www.openmicroscopy.org/site/supp ... Omero.html .

Like descripted in the 'Non-service beans' section I generate a java file 'MyLoginAttemptListener.java' and a xml file 'blitz-myLoginListener.xml'.

Code: Select all
package ome.services;

import ome.services.messages.LoginAttemptMessage;
import org.springframework.context.*;

import java.nio.file.*;
import java.nio.charset.*;
import java.util.*;

/**
* Trivial listener for login attempts.
*/

public class MyLoginAttemptListener implements ApplicationListener<LoginAttemptMessage>
{
    public void onApplicationEvent(LoginAttemptMessage lam)
    {
        if (lam.success != null)
        {
           String message = "Login for user " + lam.user;
           if(lam.success)
              message += " successful!";
          else
             message += " failed!";
           
           List<String> lines = Arrays.asList(message);
           
           try
           {
              //System.out.println(message);
              Files.write(Paths.get("loginLog.txt"), lines, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.APPEND);
           }
           catch(Exception e)
           {
              
           }
        }
    }
}


Both files I add to the JAR file 'extension.jar' and copy this file to OMERO.server/lib/server path of my OMERO installation.

Then I restart my server and login via the web interface.

Unfortunately it seems not to work. I can't find the loginLog.txt file.

Do I miss some point? Or what is the easiest way (if possible without rebuild/reinstall the OMERO-server) to add an own service to OMERO.

Thanks,
Daniel
dwj
 
Posts: 23
Joined: Mon Nov 16, 2015 10:46 am

Re: Adding own service to OMERO

Postby dwj » Fri Feb 19, 2016 2:15 pm

Hi OMERO team,

I made several ‚experiments‘, but I don’t get a working solution.
The following steps I do so far:
1. Get GIT repository of OMERO code
2. At git/../blitz/resources/omero I create a file called ‘example.ice’ (see attachment) with the definition of my “NewService” interface.
3. At git/…/blitz/resources/ome/services I create a file called ‘blitz-NewServiceI.xml’ (see attachment).
4. At git/…/blitz/src/omero/example I created a file called ‘NewServiceI.java’ which subclassings example._NewServiceDisp (see attachment)
5. I build the ‘blitz’ code by ‘python build.py’ without any errors.
• A lot of java-files are generated at git/…/blitz/generated/example
• A lot of class-files are generated at git/…/blitz/target/classes/example
• A ‘omero_example_ice.py’ file at git/…/blitz/generated
6. From inside the git/…/blitz folder I create a JAR file by the following command which adds all generated class files and the xml file:
• jar cvf example.jar generated/example target/classes/example resources/ome/services/blitz-NewServiceI.xml
7. I copied the jar file into OMERO.server/lib/server folder of my OMERO installation
8. I copied the ‘omero_example_ice.py’ file into OMERO.server/lib/python folder of my OMERO installation
9. I add two lines of code to the __init__.py file at OMERO.server/lib/python/omero (around line 11)
• Ice.updateModule("example")
• import omero_example_ice
10. I restart my OMERO server (without error)

11. At my client I wrote a script (see attachment), which should create an instance an object of my NewServerI class. I can upload the script but when I run it, I get the following error:

• Traceback (most recent call last):
• File "./script", line 18, in <module>
• newService = example.NewServiceI()
• NameError: name 'example' is not defined

Does anybody has experiences in creating an own service or know where my mistake is?

Thanks,
Daniel
Attachments
attachment.zip
(1.35 KiB) Downloaded 198 times
dwj
 
Posts: 23
Joined: Mon Nov 16, 2015 10:46 am

Re: Adding own service to OMERO

Postby atarkowska » Fri Feb 19, 2016 7:51 pm

Hi Daniel,

I have just created working example of synchronous service in https://github.com/aleksandra-tarkowska ... le.service on top of OMERO 5.2.1. Could you tell us more what are you trying to do?

You can review set of changes in: https://github.com/openmicroscopy/openm ... e?expand=1

Just clone my repo https://github.com/aleksandra-tarkowska ... oscopy.git and checkout branch iexample.service.
Then build
Code: Select all
./build.py build-dev


export dist/lib/python to your pythonpath:
Code: Select all
export PYTHONPATH=/path/to/omero.git/dist/lib/python:$PYTHONPATH


python script:
Code: Select all
import omero
import Ice
import IceImport
IceImport.load("omero_api_IExample_ice")

c=omero.client('localhost', 4064)
sf=c.createSession('root','omero')

print sf.getAdminService().getEventContext().userId
print sf.getExampleService().helloUserId()

sf.closeOnDestroy()
c.closeSession()
c.__del__()


Let us know if you have more questions.

Ola
atarkowska
 
Posts: 327
Joined: Mon May 18, 2009 12:44 pm

Re: Adding own service to OMERO

Postby dwj » Tue Feb 23, 2016 2:21 pm

Hi

Thanks for your help. Your solution looks like that what we are looking for.
We want to add a service which helps us to generate and follow workflows at the laboratory. We decided for this solution to not have to install a workflow software at all client computers.

Thanks again,
Daniel
dwj
 
Posts: 23
Joined: Mon Nov 16, 2015 10:46 am

Re: Adding own service to OMERO

Postby atarkowska » Sun Feb 28, 2016 10:13 pm

Hi, sorry for a slow response.

Please keep in mind that previous example covers only synchronous service. If the request takes longer you should add asynchronous service to be able to free resources. For example omero.cmd.mail https://github.com/openmicroscopy/openm ... d/Mail.ice and implementation https://github.com/openmicroscopy/openm ... uestI.java

I hope this will be helpful.

Ola
atarkowska
 
Posts: 327
Joined: Mon May 18, 2009 12:44 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest