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
WURFL logging problem
-
- Posts: 32
- Joined: Mon Oct 08, 2012 2:47 am
Re: WURFL logging problem
Hello Rafal,
I will send you the package you requested to your e-mail address immediately.
Fulvio
I will send you the package you requested to your e-mail address immediately.
Fulvio
-
- Posts: 38
- Joined: Tue Jan 31, 2012 10:27 am
Re: WURFL logging problem
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:
Then, the Java code:
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
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>
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;
}
}
}
Fulvio
Re: WURFL logging problem
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:
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>
Re: WURFL logging problem
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.
-
- Posts: 32
- Joined: Mon Oct 08, 2012 2:47 am
Re: WURFL logging problem
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:
- Then, create ONE WURFLRequestFactory, passing it to RequestBuilder, and build the request
- Finally, you can pass the wurflRequest to getDeviceForRequest:
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
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));
}
}
Code: Select all
WURFLRequestFactory factory = new DefaultWURFLRequestFactory(engine.getUserAgentPriority());
RequestBuilder reqBuilder = new ReqBuilder(factory);
WURFLRequest wurflReq = reqBuilder.addHeaders(....., .....).build();
Code: Select all
Device device = engine.getDeviceForRequest(wurflReq);
Beppe
Who is online
Users browsing this forum: No registered users and 5 guests