WURFL logging problem

rjanicki
Posts: 6
Joined: Tue Nov 27, 2012 11:07 am

WURFL logging problem

Postby rjanicki » Tue Nov 27, 2012 11:10 am

We're currently testing WURFL software on our test development. However, we've some issues with implementing the library in the project. We're having similar problems to KenAdams from this topic: http://www.scientiamobile.com/forum/vie ... ?f=8&t=215 . In our case, the logging is taking over our current logging properties (we're based on log4j). How can we change it? Probably solution from the mentioned post could help us.

Best regards,
Rafal Janicki

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

Re: WURFL logging problem

Postby support-all » Tue Nov 27, 2012 12:18 pm

Hello Rafal,
I will send you the package you requested to your e-mail address immediately.

Fulvio

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

Re: WURFL logging problem

Postby fulvio.crivellaro » Wed Nov 28, 2012 4:18 am

I took some time to extract the core of the solution, consisting in two files: the xml configuration file of logback and a Java class extending Filter<ILoggingEvent>.
The former declares the Filter class to use, the latter decides whether the log should be displayed or not, depending on the package name.

First, the configuration file must contain these lines, which as you can see declare the java class your.packagename.logexample.WURFLLogFilter:

Code: Select all

    <!-- Default configuration : log on stdout appender, only root logger configured-->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    	<filter class="your.packagename.logexample.WURFLLogFilter" />
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>%-15(%d{HH:mm:ss} [%thread]) %.-1level %logger{30} %line - %msg%n%xEx{10}</Pattern>
        </encoder>
    </appender>

    <!-- level are:
          trace < debug < info < warn < error < off
          "off" completely shut down logging for the given logger
     -->
    <root level="info">
        <appender-ref ref="STDOUT"/>
    </root>
Then, the Java code:

Code: Select all

public class WURFLLogFilter extends Filter<ILoggingEvent> {

	private static final String NET_PACKAGE = "net.sourceforge.wurfl";
	private static final String COM_PACKAGE = "com.scientiamobile";
	
	@Override
	public FilterReply decide(ILoggingEvent event) {
		
		// get the
		String loggerName = event.getLoggerName();
		
		if (loggerName.startsWith(COM_PACKAGE) || loggerName.startsWith(NET_PACKAGE)) {
			return FilterReply.DENY;
		} else {
			return FilterReply.NEUTRAL;
		}
	}
}
Of course, the logback.xml file has to be visible by the code, and the package name has to be customized according to your project.

Fulvio

rjanicki
Posts: 6
Joined: Tue Nov 27, 2012 11:07 am

Re: WURFL logging problem

Postby rjanicki » Wed Nov 28, 2012 7:16 am

Thank you for the help. Actually, in my case it didn't work out as I was using log4j previously. So what I've done is removing logback dependency from the project and all my logging is now as previously.
Here is a snippet for maven:

Code: Select all

			<dependency>
			<groupId>net.sourceforge.wurfl</groupId>
			<artifactId>wurfl</artifactId>
			<version>1.4.3.1</version>
			<exclusions>
				<exclusion>
					<artifactId>logback-classic</artifactId>
					<groupId>ch.qos.logback</groupId>
				</exclusion>
			</exclusions>
		</dependency>

Zhah001
Posts: 1
Joined: Wed Feb 18, 2015 5:03 am

Re: WURFL logging problem

Postby Zhah001 » Wed Feb 18, 2015 5:05 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.

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

Re: WURFL logging problem

Postby support-all » Wed Feb 18, 2015 11:52 am

Hi,
currently it is possible to use the Java API without servlet. You can create a WURFLEngine and retrieve the device using getDeviceForRequest passing:
- the plain user-agent (String)
- or a WURFLRequest, if you want to pass the headers.
For the last case you can do something like that:
- Create a simple class to build the request:

Code: Select all

class RequestBuilder {
    
    WURFLRequestFactory factory;
    Map<String, String> headers = new HashMap<String, String>();

    public ReqBuilder(WURFLRequestFactory factory) {
        this.factory = factory;
    }
 
    public ReqBuilder addHeader(String name, String value) {
        headers.put(name, value);
        return this;
    }
 
    public WURFLRequest build() {
        return factory.createRequest(new MapHeaderProvider(headers));
    }
}
- Then, create ONE WURFLRequestFactory, passing it to RequestBuilder, and build the request

Code: Select all

    WURFLRequestFactory factory = new DefaultWURFLRequestFactory(engine.getUserAgentPriority());
    RequestBuilder reqBuilder = new ReqBuilder(factory);
    WURFLRequest wurflReq = reqBuilder.addHeaders(....., .....).build();
- Finally, you can pass the wurflRequest to getDeviceForRequest:

Code: Select all

    Device device = engine.getDeviceForRequest(wurflReq);
Please remember that even if you will not use the servlet, you have to include java http servlet to build path, because of WURFL needs this.

Beppe


Who is online

Users browsing this forum: No registered users and 11 guests