Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Spring 3.0 OXM instead of SWS 1.5 [BATCH-1532] #2050

Closed
spring-issuemaster opened this issue Mar 11, 2010 · 9 comments
Closed

Use Spring 3.0 OXM instead of SWS 1.5 [BATCH-1532] #2050

spring-issuemaster opened this issue Mar 11, 2010 · 9 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Mar 11, 2010

cyril vid opened BATCH-1532 and commented

I'm using Spring Batch 2.1.0.RELEASE with Spring 3.0.1.RELEASE with Jdk 1.5.

Test 1
When I use the following environment :
. Spring Batch 2.1.0.RELEASE
. Spring WS 1.5.9 (modules spring-xml and spring-oxm)
. Spring 2.5.6
Everything works fine.

Test 2
When I use the following environment :
. Spring Batch 2.1.0.RELEASE
. Spring 3.1.0.RELEASE
. and WITHOUT spring-oxm module from Spring WS (packages spring-xml and spring-oxm have been integrated into Spring since Spring 3).

I got the UnsupportedOperationException error when runngin XmlFunctionalTests :
Code:

java.lang.UnsupportedOperationException: XStreamMarshaller does not support unmarshalling using SAX XMLReaders
at org.springframework.oxm.xstream.XStreamMarshaller.unmarshalSaxReader(XStreamMarshaller.java:460)
at org.springframework.oxm.support.AbstractMarshaller.unmarshalSaxSource(AbstractMarshaller.java:341)
at org.springframework.oxm.support.AbstractMarshaller.unmarshal(AbstractMarshaller.java:131)
at org.springframework.batch.item.xml.StaxEventItemReader.doRead(StaxEventItemReader.java:222)
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:87)
at org.springframework.batch.sample.iosample.AbstractIoSampleTests.getCredits(AbstractIoSampleTests.java:92)
at org.springframework.batch.sample.iosample.AbstractIoSampleTests.testUpdateCredit(AbstractIoSampleTests.java:53)

Test 3
When I use the following environment :
. Spring Batch 2.1.0.RELEASE
. Spring 3.1.0.RELEASE
. and WITHOUT spring-oxm and spring-xml modules from Spring WS (packages spring-xml and spring-oxm have been integrated into Spring since Spring 3).

I got the ClassNotFoundException error when runngin XmlFunctionalTests :
Code:

java.lang.ClassNotFoundException : org.springframework.xml.transform.StaxSource

Diagnosis and possible solution
This is due to the fact that Spring 3 renamed the package org.springframework.xml.transform from Spring WS 1.5.9 into org.springframework.util.xml.

So you must change the code for StaxEventItemReader and StaxEventItemWriter in order for Spring Batch to work with Spring 3.


Affects: 2.1.0

Reference URL: http://forum.springsource.org/showthread.php?t=85559

Attachments:

Referenced from: commits 571c7fc, 539c403, 0a77a5b, aef9f97

8 votes, 9 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 11, 2010

Dave Syer commented

As mentioned in the forum there is a trivial workaround, which is to not include spring-oxm-3.0, but use 1.5.9 instead.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 25, 2010

Dave Syer commented

I don't think it's a great idea to try and support both Spring 3.0 OXM and the older (but completely identical functionally) stuff in SWS 1.5. The solution proposed requires both to be on the classpath at build time for instance, which is awkward. It's better just to say that SWS is required until we switch to Spring 3.0 as a mandatory dependency.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 6, 2010

drekbour commented

We are already using the new OXM 3 features (after all its one of the advertised release highlights of v3) which and not compatible with the current Batch library. Since we cannot really switch back to the older OXM libraries I have, as an interim patch, extended StaxEventItemReader and changed the unmarshaller call in doRead() to:
T mappedFragment = (T) unmarshaller.unmarshal(StaxUtils.createStaxSource(fragmentReader));

This solved my requirement for using this class with Spring 3.0.1 and Batch 2.1.0 but I'm sure there is more to it than just that.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 21, 2011

Lucas Ward commented

I have the same issue as Drekbour. However, I'm running this particular batch job from within a Grails app (running 1.3.6) This version is pegged to spring 3.0.5, so it isn't possibly to use the older version. I have created my own version of the StaxEventItemReader and modified it to use the new Spring WS code, but ran into some issues, mostly around woodstox. It's a bit trickier to use this type of reader in a grails environment. It may be better in a grails environment to use something like the Groovy XmlSlurper.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 22, 2011

Dave Syer commented

XmlSlurper will not be a streaming API, so you will probably have to suck the whole document into memory, and hence might as well write your own reader anyway.

You shouldn't need to use Woodstox if you have Java 6 though?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 8, 2011

Antonio Mota commented

Hi all.

I have this same issue, is there any news about it? I tried to do the same as drekbour, but I can't just extend StaxEventItemReader and duplicate the code (unfortunately the protected methods operate on private properties, not on protected ones like I was expecting), and that will cause problems elsewhere, and to change the original classes like in the patch is not a option.

Thanks.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 11, 2011

Dave Syer commented

We can accept a patch if anyone can come up with a reflection hack to make it work in Spring 2.5.6 and Spring 3.0. No-one has come forward with one yet (but Josh was looking at it), so all you can do is make your own reader, or stick to OXM 1.5.9.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 15, 2011

Dave Syer commented

Josh has said he will look at a reflection hack for 2.1.7. If it isn't possible this will get bumped up to 2.2.0.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 17, 2011

Yann Moisan commented

Hi all,

I have the same problem.
Moreover, I want to use aliases on field, and unfortunately, the method XStreamMarhaller.setFieldAliases() exist only in the Spring 3 OXM version.

Do you know a workaround ?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.