Using the Java API outside a servlet

AdDynamo
Posts: 2
Joined: Thu Feb 14, 2013 4:41 am

Using the Java API outside a servlet

Postby AdDynamo » Fri Feb 15, 2013 3:19 am

How would one go about using the Java API without implementing it inside a servlet (as in all the examples). We want to integrate it as a pure Java solution into our existing web applications. In other words, we simple want to instantiate the correct classes and be able to do the lookups.

Would one only need to use the GeneralWURFLEngine for this?

fulvio.crivellaro
Posts: 38
Joined: Tue Jan 31, 2012 10:27 am

Re: Using the Java API outside a servlet

Postby fulvio.crivellaro » Fri Feb 15, 2013 4:37 am

AdDynamo wrote:Would one only need to use the GeneralWURFLEngine for this?
Of course.
The method

Code: Select all

public Device GeneralWURFLEngine.getDeviceForRequest(HttpServletRequest request)
does everything, taking as the only parameter the HttpServletRequest you get from the HttpServlet.doGet and doPost methods.

The servlet example provided with the Java API has one only HttpServlet, hence it owns all the code for simplicity.
Nevertheless, it already shows how to instantiate a GeneralWURFLEngine at initialization time, and share it to all servlets belonging to the web application through the ServletContext, so that the device matching can be performed by one single (though quite cumbersome) line of code:

Code: Select all

Device device = ((GeneralWURFLEngine)getServletContext().getAttribute(WurflWebConstants.WURFL_HOLDER_KEY_PARAM)).getDeviceForRequest(request);
For this purpose, see the class net.sourceforge.wurfl.core.web.WURFLServletContextListener, which is part of the WURFL core, so that it is ready to be used by your web application.

If I did not answered your question, maybe I did not understand what you mean by
AdDynamo wrote:without implementing it inside a servlet (as in all the examples)
Just please describe what you would like to avoid in each Servlet, and I will be glad to help you further.

Regards,
Fulvio

AdDynamo
Posts: 2
Joined: Thu Feb 14, 2013 4:41 am

Re: Using the Java API outside a servlet

Postby AdDynamo » Fri Feb 15, 2013 6:53 am

No, this is 100%. Thank you very much :)


Who is online

Users browsing this forum: No registered users and 84 guests