SOAP Version Mismatch: SOAP Version “SOAP 1.2 Protocol” in request does not match the SOAP version “SOAP 1.1 Protocol” of the Web service.

We were getting the below error in our project, when trying to invoke a web service.

[Server:server-one] 07:29:12,927 ERROR [stderr] (http-/10.99.12.28:8080-13) org.springframework.ws.soap.client.SoapFaultClientException: [ISS.0088.9168] SOAP Version Mismatch: SOAP Version "SOAP 1.2 Protocol" in request does not match the SOAP version "SOAP 1.1 Protocol" of the Web service.
[Server:server-one] 07:29:12,928 ERROR [stderr] (http-/10.99.12.28:8080-13) at org.springframework.ws.soap.client.core.SoapFaultMessageResolver.resolveFault(SoapFaultMessageResolver.java:37)
[Server:server-one] 07:29:12,929 ERROR [stderr] (http-/10.99.12.28:8080-13) at org.springframework.ws.client.core.WebServiceTemplate.handleFault(WebServiceTemplate.java:774)
[Server:server-one] 07:29:12,929 ERROR [stderr] (http-/10.99.12.28:8080-13) at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:600)
[Server:server-one] 07:29:12,929 ERROR [stderr] (http-/10.99.12.28:8080-13) at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
[Server:server-one] 07:29:12,930 ERROR [stderr] (http-/10.99.12.28:8080-13) at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:384)
[Server:server-one] 07:29:12,930 ERROR [stderr] (http-/10.99.12.28:8080-13) at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:378)
[Server:server-one] 07:29:12,931 ERROR [stderr] (http-/10.99.12.28:8080-13) at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:370)

Solution:
The solution lies in the configuration files used by spring.
Here in our project, the version specified in this file was 1.2 where as the web service was expecting 1.1






How to make ajax call in spring framework

Write a server side method, with a mapping something as follows:

@RequestMapping("/getKids.html")   
public @ResponseBody
String getChildren(@RequestParam(value = "ocn") String ocn,
HttpServletRequest request, HttpServletResponse response)
{
return ocn.toUpperCase();
}

Here @ResponseBody tells the framework to return value of the method to the browser and not lookup for a view with that name.
You can optionally omit request and response parameters in the signature of the method, if you like to.

After removal of request and response the method will look like

@RequestMapping("/getKids.html")   
public @ResponseBody
String getChildren(@RequestParam(value = "ocn") String ocn)
{
return ocn.toUpperCase();
}

Write a javascript method as follows (This uses jquery to fire ajax request)

function populateSubAgents(obj)
{
$.ajax({
url: "getKids.html?ocn="+obj.value,
success: function(data) {
$("#subAgentName").html(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (XMLHttpRequest.status == 0) {
alert(' Check Your Network.');
} else if (XMLHttpRequest.status == 404) {
alert('Requested URL not found.');
} else if (XMLHttpRequest.status == 500) {
alert('Internel Server Error.');
} else {
alert('Unknown Error.n' + XMLHttpRequest.responseText);
}
}
});
}

What is the difference between @RequestMapping’s param attribute AND @RequestParam

Source : http://www.captaindebug.com/2011/07/accessing-request-parameters-using.html#uds-search-results

@RequestMapping is only used to map request URLs to your controller.
The ‘params’ value is used to narrow the mapping down allowing you to map different param values
(uuids in this case) to different methods. For example:

/** This is only called when uuid=6 e.g.: /help/detail?uuid=6 */ 
@RequestMapping(value = "/help/detail", params={"uuid=6"}
method = RequestMethod.GET)
public String displaySomeHelpDetail(Model model) {

// Do Something
return "view.name"
}

/** This is only called when uuid=1234 e.g.: /help/detail?uuid=1234 */ 
@RequestMapping(value = "/help/detail", params={"uuid=1234"}
method = RequestMethod.GET)
public String displaySomeHelpDetail(Model model) {

// Do Something Else
return "another.view.name"
}

Whilst @RequestParam is used to pass request parameters into a method so that you can use them.
For example:

@RequestMapping(value = "/help/detail", 
method = RequestMethod.GET)
public String displaySomeHelpDetail(@RequestParam("uuid") String uuid, Model model) {

log.info("The uuid = " + uuid);
return "view.name"
}

Problem using c:set of jstl

The problem was that i was not able to set the value of a variable defined in a scriptlet.


Root cause: The tag lib i was using was perhaps of an older version.

Older version:


Newer version:


Please do post more information if you have more knowledge about this problem.

How to upload file using struts and hiberate?

How to upload file using struts and hibernate?

I spent 5-6 hours figuring out how can I upload a file into Blob in a database. So I decided to write a short article.

Add enctype=”multipart/form-data” in the form tag (in JSP)



Add 2 fields in ActionForm, one which is populated via struts framework.
Second one which is read by hibernate i.e. uploadedBlob

// This is filled by the code written in Action Class.
// This has to be done manually and is not done automatically.
private Blob uploadedBlob;
public Blob getUploadedBlob() {
return uploadedBlob;
}

public void setUploadedBlob(Blob uploadedba) {
this.uploadedBlob = uploadedba;
}

// This is the actual FormFile which gets populated into the ActionForm
// by struts framework.
private FormFile uploadedfile;
public FormFile getUploadedfile() {
return uploadedfile;
}

public void setUploadedfile(FormFile uploadedfile) {
this.uploadedfile = uploadedfile;
}

Add the following in formbean.hbm.xml


In Action Class, convert FormFile to Blob and set it in FormBean (while saving)

// Convert FormFile to a byte Array
byte[] byteArray=formbean.getUploadedfile().getFileData();
// Convert this byteArray to a blob
Blob myblob=Hibernate.createBlob(byteArray);
formbean.setUploadedBlob(myblob);

For saving this formbean to database use

private boolean saveOrUpdate(SolutionFormBean formbean) 
{
Session session = null;

//Transaction object
// Nothing happens without transaction in hibernate.
Transaction transaction = null;
try {
// This step will read hibernate.cfg.xml
// and prepare hibernate for use
SessionFactory sessionFactory = new Configuration()
.configure().buildSessionFactory();
session = sessionFactory.openSession();
// Using a transaction is mandatory.
transaction = session.beginTransaction();
session.saveOrUpdate(formbean);
// Commit it
transaction.commit();
System.out.println("Done");
return true;
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
} finally {
// Actual row insertion will happen at this step
if(session!=null)
{
session.flush();
session.close();
}
return true;
}
}

While reading Blob from database, you would have to do the reverse, i.e.
convert Blob to byteArray and write to ServletOutputStream

Blob dbBlob = dbBean.getUploadedBlob();
int bloblength=(int)dbBlob.length();
byte[] tempByte = dbBlob.getBytes(1, bloblength);
// Now we have converted blob to byte array.
ServletOutputStream out = response.getOutputStream();
// For reading more about this header do check out the following link
// http://javakafunda.blogspot.com/2011/10/forcing-saveas-using-http-header.html
response.setHeader("Content-Disposition", "attachment; filename="
+formbean.getFilename());
out.write(tempByte);
out.flush();
out.close();

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object

I was getting the following error in the logs of the tomcat, when I try to start the tomcat server.

Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object

Things I tried but didn’t work
=========================
1) I used class finder to find that which jar contains this class java.lang.Object, and it was rt.jar.
I added rt.jar in the classpath. But of no use.
2) I made a Environment variable CATALINA_HOME, JAVA_HOME, but didn’t help.
3) I tried rebooting the machine every time, after I set the paths specified in step 2.
4) Uninstalling and re-installing the tomcat didn’t help.

ROOT CAUSE AND SOLUTION:
=========================
During installation of tomcat, the default jre directory that was coming on the installation screens of tomcat didn’t had rt.jar
I realized this when I checked the jre folder.

Then I decided to uninstall and re-install tomcat and while re-installation I took care while specifying the jre folder. And the new jre folder had rt.jar

This solution made it work. 🙂

I m happy 🙂

The prefix “jaxb” for element “jaxb:globalBindings” is not bound.

I’m using xjc to compile XML Schema into JAXB objects and the
compiling is fine unless I try to define jaxb bindings. For instance,
if I try adding this code in the schema:




bindingStyle="modelGroupBinding"
choiceContentProperty="true" >


<jaxb:javaType name="short"
xmlType="xs:long"
printMethod="javax.xml.bind.DatatypeConverter.printShort"
parseMethod="javax.xml.bind.DatatypeConverter.parseShort"/>



xjc complains with:
[ERROR] The prefix “jaxb” for element “jaxb:globalBindings” is not
bound.

SOLUTION
========

Missing namespace declaration. There should be something like this:
xmlns:jaxb=”URI”
Just look for the other namespace definitions (i.e. xmlns:s) and
add the above attribute to the end.

Source : http://www.velocityreviews.com/forums/t137983-problem-in-xjc-with-recognizing-jaxb-prefix.html

Classes not being generated in WEB-INF/classes folder

Posting this on behalf of Vaibhav Garg..

The settings in the Eclipse were perfect to store the output in the output folder as WEB-INF/classes folder. But, still the classes were not being generated in this folder when the code was built. 

Reason:

There were a couple of dependent projects included in the build path. And, there were errors in those projects. Due to this reason, the project was not getting built. And, the error list was huge around 2500 errors in the entire workspace. So, it was difficult to get the exact reason whether the project has some errors or not.

Once the errors in dependent projects were resolved, it got built successfully and the class files got generated in the WEB-INF/classes folder.

Weblogic specific issue abt custom Tags

Dear Friends,

I was facing an issue specifically on weblogic and the same JSP was working fine on Oracle Application Server.
I thought it is worth sharing with all.

ERROR MESSAGE :
The method setTabindex (String) in the type NumericNewTextTag is not applicable for the arguments (int)

After seeing the error message, the obvious thought that came to my mind was, that we are passing an int and it is expecting a String.

Then I thought, why and how it is getting compiled on Oracle AS?
Is JSP to Servlet compilation, vendor specific?
What abt the theory that Java says? write once, run anywhere? Doesn’t this theory apply here?

You’ll get the answers to all these questions at the end of this post.

Problematic code

int tabindex=0;
<nuchtml:numbertextbox
property="txtGrossRevenues"
displayClass=""
mode=""
value=""
onchange="fnOnChange()"
maxlength="13"
onkeypress="checkNumericsNew(event)"
onblur="addCommaCurrencyFormat(this);"
onfocus=" callCurrencyFocus(this)"
onmousedown="Disable_Copy_Paste();"
onkeydown="Disable_Copy_Paste();"
tabindex=""
style="width:200"/>

tabindex++;

Code with Problem resolved.

int tabindex=0;
// Please note the change in tabindex attribute.
<nuchtml:numbertextbox
property="txtGrossRevenues"
displayClass=""
mode=""
value=""
onchange="fnOnChange()"
maxlength="13"
onkeypress="checkNumericsNew(event)"
onblur="addCommaCurrencyFormat(this);"
onfocus=" callCurrencyFocus(this)"
onmousedown="Disable_Copy_Paste();"
onkeydown="Disable_Copy_Paste();"
tabindex=""
style="width:200"/>

tabindex++;

Key Points
===========

On Oracle this custom tag gets translated to somewhat like the following.

// Please note that whatever is the return type 
// of the expression is wrapped into String and then sent to setTabIndex method.
// So even if the developer sends a primitive int, oracle will convert it
// to String before sending it to method.
// Hence no compilation problem on Oracle server.
__jsp_taghandler_33.setTabindex(OracleJspRuntime.toStr(Integer.toString(tabIndex));

Note that, the oracle server converts the argument passed by the user to a String explicitly, which is not the case with weblogic.
So, if you are using a request-time expression value in the attribute of a custom-tag, Make sure that return type of the expression is a String.

Here are the answers to the questions:

Why and how it is getting compiled on Oracle AS?
The above explanation clearly explains that.
Is JSP to Servlet translation, vendor specific?
Yes, JSP to servlet translation varies across vendors.
What abt the theory that Java says? write once, run anywhere? Doesn’t this theory apply here?
This theory still works. Because, it was the mistake on developer’s end, not to comply with the syntax of JSP, which luckily worked on Oracle.

JSP always say, you must pass a String to an custom-tag’s attribute.

Some questions are still boggling my mind?

  1. Is it good that Oracle converts every passed expression to String before passing to the setTabindex method? What should be the ideal translation that is expected from a container?
  2. how abt the literals that are passed like tabindex=”1″, how that were working on weblogic? Why those didn’t create an issue? Did weblogic converted them to String before passing it to method?

Generating dynamic elements in struts !!

Thanks to http://www.techtamasha.com/generate-dynamic-ids-for-struts-html-tags/

Do you use struts tags to generate html content?
If yes, then sooner or later you’ll come across a scenario where you would generate html elements in an array
I faced a similar predicament recently. I had no other option but to use scriptlets to generate id’s for the html elements

However, I soon found out using scriptlets within the struts html tags isn’t really straight forward.

Here’s the code I tried in my first attempt:


//iteration logic here
<html:text property="example[]" styleid="example"/>

Well, if you write the code as shown above, the html code generated would be :

<input type="text" name="example[]" id = "example">

and not


To get the expected result, i.e. for the scriptlet to work inside the struts html tag, write as below:

<html:text property=''
styleid=''/>

Please note that the name of the elements should be like this if you want them to read in Action Class via Action Form.
example[0], example[1], example[2], example[3]……and so on…

What do one needs to retrieve these values in Action Class

  1. Create a property in Action Form with the name example of type String[]. (Though ArrayList may also work, but I have not tried it yet)
  2. Create the corresponding getter setters for the property defined above.