开发者

how to reconcile conflict between original and generated file within Java web services?

I have a legacy Java application that uses class mypackage.Foo. I would like that application to utilize a web service that开发者_运维百科 returns instances of Foo. To connect to this web service, I use wsimport on the WSDL to generate the artifacts, and it gives me another Foo.java file. Ideally, I would like to tell wsimport to generate artifacts that use the original Foo and to not generate any additional Foo files, but I haven't found way to do that. How do I reconcile the two Foo files within the Java application? It seems my options are:

1) put the generated Foo file in another package. But then assigning otherpackage.Foo to a mypackage.Foo variable fails

2) use the generated Foo instead of the original Foo. In some cases, this would seem the best solution, but the original Foo has functionality that is not in the generated Foo. Besides, making an application-wide change is not feasible.

3) use the first option and write a method to manually copy the fields of otherpackage.Foo into mypackage.Foo. If all else fails, this will be what I do, but seems horribly inelegant.

I'm sure I'm missing a simple best practice out there. Appreciate any insights!


When you are generating Java code from WSDL you can use Apache CXF and it's wsdl2java tool (or by using maven-cxf-codegen-plugin) and specify the following option:

-nexclude <schema-namespace>=<java-package> 

Using this option will:

  • tell the wsdl2java tool to not generate classes from the given XML namespace,
  • tell the tool to put into generated code import from the given java-package.

Of course referenced class must exist in java-package later during compilation (not required during code generation).

In Your example use:

wsdl2java -nexclude <some-schema-namespace-I-dont-know>=mypackage
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜