If mathematical operators (+, -, *, /) are made part of an attribute name then Struts 2 may mis-interpret them during lookups. Say if one uses "user-name" as attribute name for storing an object in request scope. On attempt of retrieving this variable from request scope using-
request.getAttribute("user-name");
if Struts 2 does not find this variable in request scope then it looks in ValueStack using OGNL. The OGNL interprets "user-name" as an expression something like ${user - name} and looks for two attributes "user" & "name" and returns difference of value of "user" and "name". This will lead to ClassCastException in your code when you do something like-
User user = (User) request.getAttribute("user-name");
because Struts 2 will return a BigInteger.
Moral of the story, never use mathematical operators in attribute names at least with Struts 2 and of course with JSTL also.
Tuesday, September 04, 2007
Struts 2 does not like mathematical operators in attribute names
Tuesday, August 14, 2007
Bottom Up JAX-RPC web service with JWSDP
A simple step by step guide to develop a bottom up web service using Java Web Services Developer Pack.
Step #1 Install JWSDP
Download Java Web Services Developer Pack 1.6 (JWSDP) from http://java.sun.com/webservices/downloads/webservicespack.html and install it. The installation directory will be called hereafter as $JWSDP_HOME.
Step #2 Write code and Package war file
Write an interface and implementation of it. This interface will be exposed as web service through servlet end-point. Write a configuration file named jaxrpc-ri.xml and save it in WEB-INF folder of the project. This configuration file contains information about web service interface and it’s implementation, location of WSDL file, web service URL. All these information will be used by JWSDP at the time of processing input war file for generating web service.
The jaxrpc-ri.xml looks like below-<?xml version="1.0" encoding="UTF-8"?>
The web.xml must have following entries-
<webServices
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/dd"
version="1.0"
targetNamespaceBase="http://myhost/myService"
typeNamespaceBase="http://myhost/types"
urlPatternBase="/myWs">
<endpoint
name="MyWebService"
displayName="My Web Service"
description="Test JAX-RPC web service"
wsdl="/WEB-INF/myWs.wsdl"
interface="myPackage.MyWsInterface"
implementation="myPackage.MyWsImplementation" />
<endpointMapping
endpointName="MyWebService"
urlPatternBase="/myWs" />
</webServices><listener>
<listener-class>com.sun.xml.rpc.server.http.JAXRPCContextListener</listener-class>
</listener>
<servlet>
<servlet-name>myWs</servlet-name>
<servlet-class>com.sun.xml.rpc.server.http.JAXRPCServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myWs</servlet-name>
<url-pattern>/myWs</url-pattern>
</servlet-mapping>
Step #3 Process war file
Copy above created war file say myWS-in.war to $JWSDP_HOME/jaxrpc/bin directory and create a directory named tmp there. Open command prompt and go to above mentioned directory and fire following command-$ wsdeploy -o myWs.war myWs-in.war -keep -tmpdir ./tmp -verbose
This will create a war file myWs.war
Step #4 Deploy Processed war file on Tomcat
Now deploy the processed war file,
Step #5 Generate Web Service client
Create a file named config.xml with following contents-<configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
Here location is the URL of the web service WSDL, which may change according to server installation, hence update it accordingly and packageName is the package name of the generated web service client classes, which could also be changed to anything.
<wsdl location="http://localhost:8080/myWs/myWs?WSDL"
packagename="myWsClient" />
</configuration>
Save config.xml in $JWSDP_HOME/jaxrpc/bin directory. Now fire following command-$ wscompile -gen:client -keep config.xml
This will create a directory name
An example of client accessing web service is given below-public class WsTest {
public static void main(String[] args) {
try {
MyWsImpl stub = new MyWsImplService_Impl().getXXX();
((Stub)stub)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://myHost/myWs/myWs");
// call the desired method
stub.xxxXXX(. . .);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Friday, August 04, 2006
Switched to 64bit Linux
I bought a new shiny AMD Athlon64 3800+ 64bit machine with NVIDIA GeForce6100 GPU. After inserting the Ubuntu 6.06 CD the installation was a breeze, much simpler than the Windows one. Ubuntu detected all hardware without any problem.
The honeymoon ended in 10 minutes when system refused to accept any input from keyboard and mouse. Hard re-boot was the only option to get out of the deadlock. System was never ran more than 15 minutes at a stretch. Google search hinted about possible graphics card driver issue.
The software install and update feature of Ubuntu is great, far better than Windows updates. This article has a good info, how to install NVidia binary drivers. After installing latest graphics drivers system is running flawless.
Now I have abandoned the Windows and switched over to Linux :-)