Use API outside web application

ecircle
Posts: 4
Joined: Tue Nov 19, 2013 10:32 am

Use API outside web application

Postby ecircle » Tue Dec 17, 2013 5:02 am

Hi,

we want to use the WURFL/ScientiaMobile API within a plain Java application, without ServletContext and without Spring. We use the API as follows to build the WURFLEngine manually:

Code: Select all

        // setup WURFL engine
        InputStream in = WurflRawClassifier.class.getResourceAsStream("/path/to/wurfl.xml");
        WURFLResource resource = new XMLResource(in, "wurfl.xml");
        GeneralWURFLEngine engine = new GeneralWURFLEngine(resource);
        engine.setEngineTarget(EngineTarget.accuracy);
        engine.setCacheProvider(new LRUMapCacheProvider());

        // get device information
        Device device = engine.getDeviceForRequest("Some user agent string");
        String deviceId = device.getId();
        String deviceRootId = device.getDeviceRootId();
        String matchType = device.getMatchType().name();
        Map<String, String> capabilities = device.getCapabilities();
        Map<String, String> virtualCapabilities = device.getVirtualCapabilities();
We want to know if that is the right way to manually build and use the WURFLEngine and/or if something is missing?

Thanks,
Stefan

support-all
Posts: 32
Joined: Mon Oct 08, 2012 2:47 am

Re: Use API outside web application

Postby support-all » Tue Dec 17, 2013 11:08 am

Hello Stefan!

Regarding your question: unless you need to get some more detail, the WURFL Engine setup could be done in a single line in a shorter way, i.e.

Code: Select all

WURFLEngine engine = new GeneralWURFLEngine("/path/to/wurfl.xml");

As for the

Code: Select all

engine.setEngineTarget(EngineTarget.accuracy);
it's okay and regarding your last line,

Code: Select all

engine.setCacheProvider(new LRUMapCacheProvider());

mind that WURFL gets initialized by default with a better cache option. So, unless you're aiming to use this specific option, this line is not needed.

Same goes for the device information: I see you're not willing to use ServletContext and Spring, however it is more efficient to pass a HttpServletRequest to getDeviceForRequest, instead of "Some UA string".

(above mentioned line is:)

Code: Select all

Device device = engine.getDeviceForRequest("Some user agent string");

and mind that the latest two lines

Code: Select all

Map<String, String> capabilities = device.getCapabilities();
Map<String, String> virtualCapabilities = device.getVirtualCapabilities();

do require a lot of computation. Unless it is needed, it is better to get only the caps and vcaps that are really needed, in order to improve the performances. you may want to take a look at the capability filter feature :)


I hope this does answer your question :)


Thanks,

Francesca

ecircle
Posts: 4
Joined: Tue Nov 19, 2013 10:32 am

Re: Use API outside web application

Postby ecircle » Wed Dec 18, 2013 4:14 am

Thanks Francesca for the immediate repsonse.

We choosed the more complex way to setup GeneralWURFLEngine because the wurfl.xml is packaged within a JAR and not directly available in the file system.

We choosed the LRUMapCacheProvider because it was also configured in http://wurfl.sourceforge.net/njava_index.php, but we'll remove it.

We retrive all the capabilites only during evaluation phase, once we identified the interesting capablites we'll use the filter feature, thanks for the hint :)

Kind Regards,
Stefan


Who is online

Users browsing this forum: No registered users and 9 guests