Archive for the ‘General’ Category
Maven: resume build from a module
Case
Your have a multi-module project. For any reason, the build fails on your 32nd project (out of 70).
You indentify the issue, fix it, and need rebuild your project. Yet, you don’t want to rebuild the 31 first projects. Rather, you prefer to start on the 32nd one.
On older version of Maven, you had to edit your pom.xml, comment the 31 projects, launch the build and uncomment the projects.
Fix
From Maven 2.1, a new option is available: -rf or —resume-from. Thanks to this option, you can hint to Maven to restart the build at any point you like.
ServletAuthentication.AUTHENTICATED
Case
You have this code
[java]ServletAuthentication servletAuthentication = new ServletAuthentication(LOGIN_USERNAME_LABEL, LOGIN_PASSWORD_LABEL);
Integer answer = servletAuthentication.weak(request, response);[/java]
But you always get FAILED_AUTHENTICATION as answer, while you expect to receive AUTHENTICATED.
Fix
In WebLogic configuration, set the control flag for Custom Authentication Provider and Default Weblogic Authentication Provider at SUFFICIENT.
Mule: File transport reads many times the same file
Case
With Mule ESB 2.2.1, I use a classic <file:inbound-endpoint>:
[xml]<file:inbound-endpoint path="${fromPath}"
pollingFrequency="3000" fileAge="5000"
moveToDirectory="${moveToDirectory}"
synchronous="true"
>
<transformers>
<transformer ref="mySimpleCSVParser">
</transformers>
</file:inbound-endpoint>
[/xml]
When I launch the Mule with no component (entreprise layer), everything is OK: the file is loaded, parsed and moved. But when I introduce a minimal component, which does nothing, then the file is read many times. Mule ESB seems to loop indefinitely, reading the file many times, without deleting it from the directory.
[java]INFO 2010-03-04 15:47:18,291 [connector.file.0.receiver.6] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: C:\temp\myFile.txt[/java]
Fix
Firstly I tried to increase the pollingFrequency attribute, assuming that the file had not yet been completely parsed when another cycle of “load-parse-move”. But it did not fix the issue.
Indeed, the problem was not related to the component layer, but to the parser itself. To fix the issue, you have to ensure the InputStream is properly closed in your Transformer layer:
[java]try
{
inputStream.close();
return answer;
} catch (IOException e)
{
throw new TransformerException((Message)null, e);
}[/java]
Get a field of a bean in Spring
Case
I have to instanciate an object of type FooDao. The only constructor available is FooDao(Connection connection).
On another hand, I have a bean of type BasicDataSource. From this BasicDataSource, I can get a Connection, through the call of BasicDataSource.getConnection().
Question: how to instanciate a bean of type FooDao in Spring?
Solution
The idea, to retrieve a field member of a bean, is to use the attributes factory-bean and factory-method, from which we will get a new bean.
Use the following Spring context file:
[xml]
<bean id="myBasicDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<!– complete … –>
</bean>
<bean id="connection" factory-bean="myBasicDataSource" factory-method="getConnection"
scope="singleton"/>
<bean id="myFooDao" class="com.my.company.FooDao">
<constructor-arg ref="connection"/>
</bean>
[/xml]
Many thanks to David Chau from SFEIR for his help in this issue!
EhCache integration within Spring
Case
You have to use a EhCache in a couple of beans, instancied via Spring.
Fix
In your main Spring configuration file, declare the following block:
[xml]
<bean id="customCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="shared" value="false" />
<property name="cacheManager">
<bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath*:ehcache.xml" />
</bean>
</property>
<property name="cacheName" value="SampleConfigOne" />
</bean>
[/xml]
Then, in any of your beans, declare the following property:
[xml]<property name="cache" value="customCache"/>[/xml]
Unit Test output redirection onto the console, with Maven 2
Case
You have to build your project. All tests are OK when you run them in your IDE, but one or more unit tests fail when you launch the build with Maven 2. When this happens, you have to open the SureFire tests reports to read the failures details.
But you’d rather read the failure in the standard output. In other terms, you would like the output to be redirected onto the console, and not in log files.
Fix
When you launch the build, specify the following option:
-Dsurefire.useFile=false
Change settings.xml location
Case
You have to use a custom-set settings.xml file, rather the default one.
By default, settings.xml is assumed to be in one the two following folders:
$M2_HOME/conf/settings.xml
$HOME/.m2/settings.xml
Fix
Use the -s option, for instance:
mvn install -s /path/to/file/otherSettings.xml
WebLogic 10.x new features
Recent history
BEA WebLogic 9.0, 9.1 and 9.2 were released from 2007: the main features were: a new console, WLST (WebLogic ScriptingTool), deployment plans, WebLogic Diagnostic Framework (WLDF), new security providers (RDBMS, SAML 1.1, etc.), JMS performance improvements, support of Java EE 4, JDK 5, Spring, OpenJPA, Kodo, etc.
Since this date, some events happened:
- Oracle bought Sun (2009)
- Oracle released WebLogic 10.3 (2008)
- Oracle bought BEA (2008)
WebLogic Server 10 General Features
- Developer productivity ehancements
- JDK 6, Java EE 5
- Support of
EJB3 andJPA - BEA enhancements
- Web Services: more annotations, less XML
JAX-RPCWeb Services EnhancementsJAX-WS2.0 Web Services Implementation
- Misc:
- Better administration console
- Auto-Record of Admin Console actions as WLST scripts
- Automatic JTA Transaction Recovery Service (TRS) migration
- SNMP 3.0
- Production Application Redeployment enhancements
- Clustering – Unicast messaging (in addition to Multicast)
Programmer Perspective
- New persistence engine: TopLink
- OEPE (Oracle Entreprise Pack for Eclipse): sequence of tools and plugins for Eclipse: remote deployment, debugging, editors for
weblogic.xmlandweblogic-application.xml, wizards, facets, Weblogic ClientGen,WSDLCandJAXBwizards - Optimizations for
Springintegration and certication - Web 2.0:
- Ajax / Dojo client support
- Http publish / submit engine for collaborative applications:
- Bayeux protocol
- data exchange within applications over persistent connections
- scalability for Dojo clients
- Ad-hoc tools for:
- Oracle Database
Spring- JAX-WS webservices
Lightweight WebLogic Server
WebLogic 10 offers a light weight server:
- Install only “core” WebLogic server
- Optionally, startup other services (
,JDBCEJB,JMS, etc.) - FastSwap: modify classes without requiring redeployment.
Architect Perspective
Architects have to consider WebLogic as a complete suite, and not only WebLogic Server:
- Oracle RAC integration: Connectivity to RAC with load balancing, failover, transactions
- Enterprise Messaging with
JMS: High performance and reliableJMSmessaging engine “built-in” - ActiveCache with Coherence*Web and
EJB/JPA: Coherence Data Grid caching included and integrated - Operations Automation: Tools for automating management of applications and servers
- Operations Insight: Tools for diagnosing problems in development and production
- Other features
- Development tools: Choice of tools for developer productivity
- Web Services: Enterprise Web Services for SOA
- TopLink: Persist application data to stores with performance and productivity. It works in a way similar to Hibernate L2 cache.
Spring: Enable flexible choice of dev frameworks with same WebLogic QOS
Production and Support Perspective
WebLogic 10 provides a tool: JRockit Mission Control
- monitors more than 150 parameters:
- CPU
- memory
- leaks
- latency spikes
- threads
- object references
connectionsJDBCJMS- pools
- clusters
- configuration files
- etc.
- allows to compare WebLogic domains
- Runtime Analyzer: runtime capture for offline analysis, Garbage Collector analysis, etc.
Coherence – ActiveCache
Coherence is the Data Grid offered by Oracle. It allows to store Java objects in memory, and share them between all instances. From a certain viewpoint, Coherence looks like the GigaSpaces.
Roadmap for Future WebLogic Releases
- Support of Java EE 6 (ratified by the community in last December)
OSGideployment- More native integration for WebLogic Server – Coherence – Oracle Database
- JRockit Flight Recorder for constant record
- Virtualization
- More integration with Maven, Hudson and Cruise Control
- Shared Library: use the same
JARfor many applications, rather than packing the sameJARin differentEARs. - On long term:
- IDE
- NetBeans to be oriented onto J2ME development
- JDevelopper to remain Oracle strategic IDE
- Contributions to Eclipse to go on
- JRockit and Sun HotSpot JVMs to be merged.
- IDE
Operand type clash: java.util.Date is incompatible with DATETIME
Case
With Mule ESB, I try to integrate an object of type java.util.Date into a column of type datetime in a Sybase DB table.
I get the following error:
[java] java.sql.SQLException: Operand type clash: java.util.Date is incompatible with DATETIME[/java]
Explanation – Fix
The stacktrace is explicit: java.util.Dates are not compatible with Sybase datetime, as Java’s Strings are not compatible with Sybase numeric(10, 3) for instance.
To fix the issue, you have to cast your java.util.Date as java.sql.Date or java.sql.Timestamp. The cast is very easy to perform:
[java]private static java.sql.Timestamp javaDate2SqlTimestamp(java.util.Date javaDate){
final java.sql.Timestamp answer = new java.sql.Timestamp(javaDate.getTime());
return answer;
}[/java]
The method is quite similar for java.sql.Dates cast.
weblogic.management.internal.InteractiveConfigurationException
Case
You have to create a Weblogic 9.2 domain. When you launch the admin application, Weblogic tries to retrieve a wrong config.xml, in a location that you did not hint. Then, Weblogic suggests to create such config.xml
Short stacktrace
[java]No config.xml was found.
Would you like the server to create a default configuration and boot? (y/n): n
<Feb 9, 2010 4:49:56 PM CET> <Critical> <WebLogicServer> <BEA-000362> <Server failed. Reason:
There are 1 nested errors:
weblogic.management.internal.InteractiveConfigurationException: \wrong\path\config.xml not found.
If you wish to have the server generate a default configuration file and boot, please re-execute your start command and respond to prompts or pass additional parameter of -Dweblogic.management.GenerateDefaultConfig[/java]
Fix
In your start scripts and $WL_HOME/bin/setDomainEnv.cmd, check your settings, among which all the occurences of DOMAIN_HOME. Another important parameter to check is LONG_DOMAIN_HOME.