What is the difference between Javax.jws and javax.xml.ws

I am new to Java and trying to switch to web services. I found two examples somewhere, and I got confused with the options available.

Firstly, javax.jws.WebService with annotation seems to work fine, but there is a lot of stuff on javax.xml.ws . It seems that javax.jws newer, and there is not much material about it.

What is the difference between these two approaches?

+8
source share
2 answers

Web Services Metadata Annotations (JSR 181)

Using annotations from the JSR 181 specification ( java.jws. xxx ), you can annotate a web service implementation class or a web service interface.

e.g. from Deploying JAX-WS Web Services on Tomcat

 package com.mkyong.ws; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; //Service Endpoint Interface @WebService @SOAPBinding(style = Style.RPC) public interface HelloWorld{ @WebMethod String getHelloWorldAsString(); } 

JAX-WS 2.0 Annotations (JSR 224)

The JSR 224 specification defines annotations for JAX-WS 2.0 ( javax.xml.ws. xxx ).

e.g. from Using SOAP Errors and Exceptions in Java JAX-WS

 @WebFault(name="CheckVerifyFault", targetNamespace="http://www.example.com") public class CheckVerifyFault extends Exception { /** * Java type that goes as soapenv:Fault detail element. */ private CheckFaultBean faultInfo; public CheckVerifyFault(String message, CheckFaultBean faultInfo) { super(message); this.faultInfo = faultInfo; } public CheckVerifyFault(String message, CheckFaultBean faultInfo, Throwable cause) { super(message, cause); this.faultInfo = faultInfo; } public CheckFaultBean getFaultInfo() { return faultInfo; } } 

Per Rainders says:

I believe BEA wants to put something NOW into Weblogic to compete with a similar feature in .NET. (see, developing Web services in WebLogic is also "simple"). Also, the annotations referenced in JAX-WS 2.0 (JSR-224) seem to give you more control. However, JSR-224 explicitly supports / enables JSR-181 (JSR-224: 7.10 Annotations defined by JSR-181).

For a more complete discussion, see JSR 181: Java Simplification Request

See also:

+11
source

These two package namespaces do not define different approaches.

  • If you are creating web-based services, there are two options: SOAP services (AKA web services) or REST services (AKA RESTful services).
  • When implementing SOAP services in Java, the path to use is to use the JAX-WS infrastructure. The framework provides tools such as wsimport and wsgen, and of course the API.
  • The JAX-WS API includes annotations, classes, and interfaces for implementing the SOAP service code and the service consumer (client) code.
  • Together, these JAX-WS API elements use the javax.xml.ws and javax.jws package javax.jws .
  • Just follow the instructions or examples to create services using JAX-WS. Don’t worry about which packages have API elements.
  • But remember to avoid specific provider APIs. Most likely, you will come across specific elements of this provider when using WS- * standards (for example, WS-Security) outside of WSDL and SOAP.
+5
source

Source: https://habr.com/ru/post/943609/


All Articles