Posts Tagged ‘Java’
No source code is available for type org.junit.Assert; did you forget to inherit a required module?
Case
You run a GWT application, with a a service layer. Those services are tested through unit tests, which may use EasyMock, among other frameworks. Of course, you hinted at related jars, such us JUnit, by a <scope>test</scope> in your pom.xml.
Yet, when you run the GWT application with a Jetty light container, you get the following message:
Compiling module lalou.jonathan.gwt.client.MyModule
Validating newly compiled units
[java][ERROR] Errors in ‘file:/C:/eclipse/workspace/…/test/unit/lalou/jonathan/gwt/client//MyServiceUnitTest.java’
[ERROR] Line 26: No source code is available for type org.easymock.MockControl; did you forget to inherit a required module?
[ERROR] Line 76: No source code is available for type org.junit.Assert; did you forget to inherit a required module?[/java]
Fix
Since Maven2 and GWT scopes are fully independant, you have to modify you *.gwt.xml. Replace:
[xml] <source path=’client’/>[/xml]
with:
[xml]<source path=’client’ excludes="**/*UnitTest.java,**/*RuntimeTest.java"/>[/xml]
NB: Never forget that Google teams work with Ant, and not with Maven!
No source code is available for type … ; did you forget to inherit a required module?
Context
In a GWT application, you have to use RPC calls, using entities which are package in external jar archives. With Eclipse, no error appears ; yet when you build the project with Maven2, you get this message:
[java][INFO] [ERROR] Errors in ‘file:/C:/eclipse/workspace/myGwtProject/src/java/com/lalou/jonathan/web/gwt/client/component/JonathanPanel.java’
(…)
[INFO] [ERROR] Line 24: No source code is available for type com.lalou.jonathan.domain.MyEntity; did you forget to inherit a required module?
(…)
[INFO] Finding entry point classes[/java]
Fix
In related jar
In the project to which MyEntity belongs to (here: my/depended/project):
- create a file
com/lalou/jonathan/MyDependedProject.gwt.xml, with as content:[xml]<module>
<source path="">
<include name="**/MyEntity.java"/>
</source>
</module>[/xml] - In the pom.xml:
- Add the source
MyEntity.javain built jar. This way, the Java file itself will be considered as a resource, like an XML or property file. To perform this, the quickest manner is to add the following block in thepom.xml:
[xml]<resources>
<resource>
<directory>${basedir}/src/java</directory>
<includes>
<include>**/MyEntity.java</include>
</includes>
</resource>
</resources>[/xml] - Add an
<include>**/*.gwt.xml</include>so that to have toMyDependedProject.gwt.xmlfile in the built jar.
In GWT project
In your
*.gwt.xmlfile, add the dependency:[xml]<inherits name=’com.lalou.jonathan.MyDependedProject’ />[/xml]
Caution!
All these operations need be done on all dependencies -either direct or indirect-. Therefore, possibly you may have a huge amount of code to be got.
Another issue appears when you use a jar of which you do not have the source code, such as in the case of tiers API for instance. - Add the source
Basic RPC call with GWT
Let’s assume you have a “Hello World” GWT application. You need emulate a basic RPC call (RMI, EJB, etc.). Here is the program:
Under the *.gwt.client folder:
Create an service interface:
[java]@RemoteServiceRelativePath("fooService")
public interface FooService extends RemoteService {
public String getHelloFoo(String totoName);
}[/java]
Create another interface for asynchronous call. You can notice the method name differs lightly from the one in the other interface:
[java]public interface FooServiceAsync {
void getHelloFoo(String fooName, AsyncCallback<String> callback);
}[/java]
Under the *.gwt.server folder, create an implementation for service interface:
[java]public class FooServiceImpl extends RemoteServiceServlet implements FooService {
public FooServiceImpl() {
// TODO init
}
public String getHelloFoo(String fooName) {
// TODO call actual service
return "hello world!";
}
}[/java]
In the web.xml file, add the following blocks:
[xml] <!– Servlets –>
<servlet>
<servlet-name>fooService</servlet-name>
<servlet-class>com…….server.FooServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fooService</servlet-name>
<url-pattern>/ivargwt/fooService</url-pattern>
</servlet-mapping>
[/xml]
The tags content match the argument given as parameter to RemoteServiceRelativePath annotation above.
From then, in your concrete code, you can instantiate the service and call remote method:
[java]FooServiceAsync fooService = GWT.create(FooService.class);
fooService.getHelloFoo("how are you?", new AsyncCallback<String>() {
public void onSuccess(String result) {
MessageBox.alert("OK", result, null);
}
public void onFailure(Throwable caught) {
MessageBox.alert("ERROR", "rpc call error-" + caught.getLocalizedMessage(), null);
}
});
[/java]
Now you can compile, package your war and deploy under Tomcat or WebLogic.
NB: special to “black-belt GWT guy” David Chau from SFEIR.
GWT to GXT migration
These days, I am discovering GWT, and more accurately ExtGWT, aka GXT.
Case
I have to write a “Hello World” application based on GXT.
Steps
- Firstly, follow Lars Vogel’s tutorial to have a “Hello World” in GWT.
- In Eclipse, add a dependancy from your project to
extjs-gxt-lib-2.1.1.jar(version compatible with your GWT version: 1.7 or 2.0), available at this link. - In your
*.gwt.xmlfile, remove:
[xml]<inherits name=’com.google.gwt.user.theme.standard.Standard’/>[/xml]and add:
[xml]<inherits name=’com.extjs.gxt.ui.GXT’/>[/xml]
- Get the gxt-all.css file, copy it into
war/css/folder - In your
*.htmlfile, add the lines:
[xml]<link rel="stylesheet" type="text/css" href="css/gxt-all.css" />[/xml] - Now, adapt your Java entry point source class, replacing GWT widgets with GXT ones.
- Restart your server and refresh the page in your browser. You have your “Hello World” in GXT!
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.
Cannot run this command because Java services are not enabled. A user with System Administrator (SA) role must reconfigure the system to enable Java.
Context
An object is marshallized and sent on TibcoRV 8.1. An instance of Mule ESB 2.2.1 listens to TibcoRV, reads the message, unmarshalls the object and builds an SQL insert query.
The query is very simple:
[sql]insert into myTable(dateColumn, stringColumn) values(…)[/sql]
It is executed in a Jdbc connector declared on Mule configuration file:
[xml] <jdbc:connector name="jdbcConnector" dataSource-ref="mySybaseDB" pollingFrequency="1000">
<jdbc:query key="writeTest"
value="INSERT INTO myTable(dateColumn, stringColumn)
VALUES(#[map-payload:myJavaDate],#[map-payload:myJavaString])"/>
</jdbc:connector>[/xml]
The DB is Sybase. The first column is of type datetime, the second one is varchar. The values are retrieved from a java.util.Date and a java.lang.String.
Case
When the query is run, I get the error:
[java]java.sql.SQLException: Cannot run this command because Java services are not enabled. A user with System Administrator (SA) role must reconfigure the system to enable Java.[/java]
(you may get a com.sybase.jdbc2.jdbc.SybSQLException instead of java.sql.SQLException)
Explanation – Fix
The error is related only to Sybase, and not to TibcoRV and Mule: by default, Sybase cannot manage Java Dates (java.util.Date). You have to start explicitly the Java services. To perform that:
- login with an username owing the rights “
sa_role“ - run the SQL query: [sql]sp_configure ‘enable java’, 1[/sql]
- the restart the Sybase server
Now it should work. A similar error may occur with JBoss.
Remote debug on Mule 2.2.1
Case
You have to run a standalone Mule 2.2.1 in debug mode. Since Mule is launched in standalone, you have to debug a remote application.
Fix
Nice case
- Edit the
%MULE_HOME%/conf/wrapper.conf - Uncomment the line:
wrapper.java.additional.<n>=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
- Don’t forget to set the parameter <n>
Boring case
In my case (Windows XP SP2, Java 1.5), the Mule refused to start and freezed:
------------------------------------------------------------------------ The JVM is being launched with a debugger enabled and could possibly be suspended. To avoid unwanted shutdowns, timeouts will be disabled, removing the ability to detect and restart frozen JVMs. ------------------------------------------------------------------------ Launching a JVM... Listening for transport dt_socket at address: 5005 ------------------------------------------------------------------------ Startup: Timed out waiting for a signal from the JVM. The JVM was launched with debug options so this may be because the JVM is currently suspended by a debugger. Any future timeouts during this JVM invocation will be silently ignored. ------------------------------------------------------------------------
The fix this:
- Download the jar spring-agent here.
- Move it into
%MULE_HOME%/lib/user/ - Edit the
%MULE_HOME%/conf/wrapper.conf - add the following block:
wrapper.java.additional.3=-javaagent:%MULE_HOME%\lib\user\spring-agent-2.5.3.jar wrapper.java.additional.4=-Xdebug wrapper.java.additional.5=-Xnoagent wrapper.java.additional.6=-Djava.compiler=NONE wrapper.java.additional.7=-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
localhost:5005
TibrvException[error=4,message=Tibrv not initialized]
Case
In a JUnit test, I send a message on a TibcoRV, but I get the following error:
TibrvException[error=4,message=Tibrv not initialized]
Fix
In order, proceed as this:
- check an RVD daemon is running 😉
- check
tibrvj.jaris in your classpath 😉 - check the instanciation of transport layer
new TibrvRvdTransport(service, network, daemon);is done within yourpublic void testXXX(), and not in thesetUp().
org.springframework.beans.factory.xml.XmlBeanDefinitionReader: Ignored XML validation warning org.xml.sax.SAXParseException: SchemaLocation: schemaLocation value = … must have even number of URI’s
Context
Mule 2.2.1 ESB config file with a TibcoRV connector, under Windows XP SP2 and Java 5.
The error happened in this context, yet I assume it would occur in any occurence related to XSD / XML schemas.
Error
org.springframework.beans.factory.xml.XmlBeanDefinitionReader: Ignored XML validation warning
org.xml.sax.SAXParseException: SchemaLocation: schemaLocation value = 'http://www.mulesource.org/schema/mule/management/2.2 http://www.mulesource.org/schema/mule/management/2.2/mule-management.xsd http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.mulesource.org/schema/mule/core/2.2/mule.xsd http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
http://www.mulesource.org/schema/mule/tibcorv/2.2 http://www.mulesource.org/schema/mule/tibcorv/2.2/mule-tibcorv.xsd' must have even number of URI's.
Headers of XML config file:
[xml]<mule xmlns=&quot;http://www.mulesource.org/schema/mule/core/2.2&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:management="http://www.mulesource.org/schema/mule/management/2.2"
xmlns:tibcorv="http://www.mulesource.org/schema/mule/tibcorv/2.2
xsi:schemaLocation="http://www.mulesource.org/schema/mule/management/2.2
http://www.mulesource.org/schema/mule/management/2.2/mule-management.xsd
http://www.mulesource.org/schema/mule/core/2.2
http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.mulesource.org/schema/mule/vm/2.2
http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
http://www.mulesource.org/schema/mule/tibcorv/2.2
http://www.mulesource.org/schema/mule/tibcorv/2.2/mule-tibcorv.xsd">[/xml]
Explanation – Fix
Each time, the attribute xsi:schemaLocation must have an even number of lines: a “public” XSD address and a “non-public” one. For non English-fluent speakers, I remind that a number is even if, and only if, it is a multiple of 2 ; otherwise it is odd.
In our case, one line is redundant. To fix this issue, you have to remove the redundant line, and ensure each line belongs to a consistent pair of lines: for instance:
http://www.mulesource.org/schema/mule/tibcorv/2.2
and
http://www.mulesource.org/schema/mule/tibcorv/2.2/mule-tibcorv.xsd