Axon.ivy 7.0 - the Digital Business Platform - is out now...

Hi Everyone,

Now, I got the trouble with format date in SOAP webservice which created by Ivy

alt text

When I call it by SOAP client, I always got the exception like Unmarshalling Error: 28.08.2016 Because as we know, the expected format for date in XML is: YYYY-MM-DDThh:mm:ss. But I want to use the custom format like dd.MM.YYYY

Do you have any ideas about that?

Regards

asked 29.09.2016 at 07:51

vhsvuong's gravatar image

vhsvuong
11456
accept rate: 0%

edited 03.10.2016 at 12:23

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
5.5k11032


You can implement a custom adapter that parses your special date format string into a valid date.

package xmlhelper;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public class DateAdapter extends XmlAdapter<String, Date> {

    private SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");

    @Override
    public String marshal(Date v) throws Exception {
        return dateFormat.format(v);
    }

    @Override
    public Date unmarshal(String v) throws Exception {
        return dateFormat.parse(v);
    }
}

To use it in your webservice you have to modify the generated webservice source class. Simply add an @XmlJavaTypeAdapter annotation into your method parameter definiton:

  @javax.jws.WebMethod
  @javax.jws.WebResult(name="result")
  public CallResult call(
          @javax.jws.WebParam(name="createJavaDataSaved") 
          @XmlJavaTypeAdapter(DateAdapter.class) 
          java.util.Date createJavaDataSaved)
    throws ch.ivyteam.ivy.webservice.process.restricted.WebServiceProcessTechnicalException
  {
    ...
  }

Remember that the generated webservice source will be overwritten whenever you change the mod file of the webservice. So you should at least write a test against your webservice stub so that you get an early warning if the adapter is not in charge anymore.

alt text You can inspect a full sample implementation here: webserviceProviderWithSpecialDateFormat_63.iar

link

answered 03.10.2016 at 13:41

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
5.5k11032
accept rate: 67%

edited 03.03 at 15:55

admin's gravatar image

admin ♦♦
11125

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:

×68
×29

Asked: 29.09.2016 at 07:51

Seen: 611 times

Last updated: 03.03 at 15:55