I'm calling a external web service with a "Web Service Step". The serialization of a java.util.Date field generates for example this line :: <documentdate>2016-08-10+01:00</documentdate>

Is there a way to change this behavior so the serialization converts the date to string without the timezone?

asked 10.08.2016 at 12:31

tiago's gravatar image

tiago
(suspended)
accept rate: 0%

edited 10.08.2016 at 16:53

By now the only way i found to remove the timezone data was to modify the generated code. I also tried this solutions http://stackoverflow.com/a/6322336/1055375, http://stackoverflow.com/a/5484319/1055375 but it didnt worked for me

(11.08.2016 at 11:34) tiago tiago's gravatar image

Hi tiago

You may want to create a override, call customClass in axis2:

public class ConvertDateWithoutTimeZone extends ConverterUtil {

    public static String convertToString(java.util.Date value) {
        /*
         * Since SimpleDateFormat is not thread-safe. We have to create a new
         * instance every time we need to format a Date.
         */
        return new SimpleDateFormat("yyyy-MM-dd").format(value);
    }
}

1st approach

You may want to package your class into a JAR file, put it in the ${ivy.engine}/webapps/ivy/WEB-INF/ and follow the way to set the system property as described in http://stackoverflow.com/a/5484319/495558. The ConverterUtil calls Class.forName to instantiate your class at runtime but it may not work because your class is usually loaded by PMV ClassLoader. So putting the custom converter class in the webapps/WEB-INF enables it to be loaded.

2nd approach

Long time ago, our project also have a similar issue when we want to control the format of Date generating by axis2. After creating the custom class, before each WebService step, we invoke:

java.lang.reflect.Field isCustomClassPresentField = org.apache.axis2.databinding.utils.ConverterUtil.class
        .getDeclaredField("isCustomClassPresent");
isCustomClassPresentField.setAccessible(true);
isCustomClassPresentField.setBoolean(null, true);
isCustomClassPresentField.setAccessible(false);
java.lang.reflect.Field customClassField = org.apache.axis2.databinding.utils.ConverterUtil.class
        .getDeclaredField("customClass");
customClassField.setAccessible(true);
customClassField.set(null, ConvertDateWithoutTimeZone.class);
customClassField.setAccessible(false);

The idea is to replace the field isCustomClassPresent and the customClass using Reflection instead of using system property approach.

link

answered 30.08.2016 at 02:27

Genzer%20Hawker's gravatar image

Genzer Hawker
(suspended)
accept rate: 66%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×48

Asked: 10.08.2016 at 12:31

Seen: 3,235 times

Last updated: 30.08.2016 at 02:27