4-18 Getting Started With JAX-WS Web Services for Oracle WebLogic Server
public class SOAP12Impl { WebMethod
public String sayHelloString message { System.out.printlnsayHello: + message;
return Here is the message: + message + ; }
}
Other than set this annotation, you do not have to do anything else for the Web service to use SOAP 1.2, including changing client applications that invoke the Web service;
the WebLogic Web services runtime takes care of all the rest.
4.9 Validating the XML Schema
By default, SOAP messages are not validated against their XML schemas. You can enable XML schema validation for document-literal Web services on the server or
client, as described in the following sections.
4.9.1 Enabling Schema Validation on the Server
To enable schema validation on the server, add the SchemaValidation annotation on the endpoint implementation. For example:
import com.sun.xml.ws.developer.SchemaValidation;
import javax.jws.WebService; SchemaValidation
WebServicename=HelloWorldPortType, serviceName=HelloWorldService public class HelloWorldImpl {
public String sayHelloWorldString message { System.out.printlnsayHelloWorld: + message;
return Here is the message: + message + ; }
}
You can pass your own validation error handler class as an argument to the annotation, if you want to manage errors within your application. For example:
SchemaValidationhandler=ErrorHandler.class
Note: This feature adds a small amount of extra processing to a Web
service request.
Note:
The com.sun.xml.ws.developer.SchemaValidation API is supported as an extension to the JDK 6.0, provided by Sun
Microsystems. Because this API is not provided as part of the JDK 6.0 kit, it is subject to change. For more information about
com.sun.xml.ws.developer.SchemaValidation , see
http:www.docjar.comdocsapicomsunxmlwsdevelo perSchemaValidation.html
.
Programming the JWS File 4-19
4.9.2 Enabling Schema Validation on the Client
To enable schema validation on the client, create a SchemaValidationFeature object and pass this as an argument when creating the PortType stub
implementation.
package examples.webservices.hello_world.client; import com.sun.xml.ws.developer.SchemaValidationFeature;
import javax.xml.namespace.QName; import java.net.MalformedURLException;
import java.net.URL; public class Main {
public static void mainString[] args { HelloWorldService service;
try { service = new HelloWorldServicenew URLargs[0] + ?WSDL,
new QNamehttp:example.org, HelloWorldService ; } catch MalformedURLException murl { throw new RuntimeExceptionmurl; }
SchemaValidationFeature feature = new SchemaValidationFeature;
HelloWorldPortType port = service.getHelloWorldPortTypePortfeature;
String result = null; result = port.sayHelloWorldHi there;
System.out.println Got result: + result ; }
}
You can pass your own validation error handler as an argument to the SchemaValidationFeature
object, if you want to manage errors within your application. For example:
SchemaValidationFeature feature = new SchemaValidationFeatureMyErrorHandler.class;
HelloWorldPortType port = service.getHelloWorldPortTypePortfeature;
4.10 JWS Programming Best Practices