Thursday, July 23, 2009

Specifying Document Literal Style for Apache CXF

Issue:

I've been assigned to help us migrate from xFire to CXF. Our old Web Services model was' RPC Encoded' and we need to publish/serve a WSDL in Document Literal format. I've hunted for several days researching this topic and running all kinds of example services, etc but finally fell on a good resource here at muleSource: http://www.mulesource.org/display/MULE2USER/Building+a+CXF+Web+Service

None of the other sites explained CXF and the SOAPBinding annotation very well.

Answer:

To specify that a service should be in Document Literal format, use the @SOAPBinding annotation.
  1. import javax.jws.soap.SOAPBinding;
  2. @SOAPBinding(style=SOAPBinding.Style.DOCUMENT,
    use=SOAPBinding.Use.LITERAL,
    parameterStyle=SOAPBinding.ParameterStyle.BARE)

Tuesday, July 14, 2009

Eclipse Doesn't Recognize WebServices Annotations

This is kind of newbie issue but (1) it stumped me (2) no one else blogged a solution and (3) it seems so simple.

Background:

I am creating a web service in Eclipse but Eclipse doesn't recognize the "@WebService" annotation. I don't know if this an Eclipse feature I need to enable or some plug-in I have to install?

  1. I type a web service annotation like @WebService to mark a Java class as a web service.
  2. Eclipse presents the annotation in red and floats the message 'WebService cannot be resolved to a type'
  3. I figure I have to add some plug-in or something and google around awhile but nothing is helpful.
  4. I find some references that I need to have J2EE classes in my classpath
Answer:

Annotations are actually interpreted, they're classes and you need to import the correct (javax.ws) library before you reference one. (This is not really an Eclipse issue).
  1. Find a distribution jar that has the WebService class
  2. Locate Apache geronimo-ws-metadata_2.0_spec-1.1.2.jar, jsr181.jar or J2ee.jar
  3. Add one of the jars to the project classpath
  4. Add an import statement import javax.jws.WebService to your java class
  5. Done, now Eclipse understands the @WebService annotation

BTW:
  • You'll have the same issue when you enter the @WebParam annotation (and whatever other annotations you might use), except you now have to import javax.jws.WebParam.
  • The SOAPBinding annotation is in package javax.jws.soap.SOAPBinding.

Notes:
  • The classes for the Web Services annotations are supplied in a number of common jar files (e.g. the geronimo jar mentioned above is not the only source of the annotations classes):
  • The JDK distribution jsr181.jar
  • The J2EE distribution javaee.jar
  • I'm sure all this is pathetic to those who know web services, but it stumped me awhile, plus I munged up my Eclipse installation trying to find an alternate project type or plugin to configure to get the annotation to be recognized.

Followers