This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes web services client is not validating parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "web services client is not validating parameters" Watch "web services client is not validating parameters" New topic
Author

web services client is not validating parameters

Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104
Hello,

I have written a web service and a client. I cannot get the client code to validate the incoming parameters.

I am using JAX-WS and NetBeans.

The generated client code is shown below:

package service;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
* <p>Java class for log complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="log">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="userId" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="appId" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "log", propOrder = {
"userId",
"appId",
})
public class Log {

@XmlElement(required = true)
protected String userId;
protected String appId;

/**
* Gets the value of the userId property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getUserId() {
return userId;
}

/**
* Sets the value of the userId property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setUserId(String value) {
this.userId = value;
}

/**
* Gets the value of the appId property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getAppId() {
return appId;
}

/**
* Sets the value of the appId property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setAppId(String value) {
this.appId = value;
}

}


The code:

@XmlElement(required = true)
protected String userId;


shows that the userId is required, but an exception does not get thrown when the client try to send a message with userId=null.

Is there a property which needs to be activated?

Thanks in advance for any help.

Ravi

Oscar Costa
Ranch Hand

Joined: Feb 05, 2009
Posts: 31

Hi Ravi,

Try to use this annotation in the attribute:



"Do or do not... there is no try!" - Jedi Master Yoda
> SCJP 5 : SCWCD 5 : SCBCD 5 <
Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104
Hello,

I just now tried this and get the same results.

-Ravi
Oscar Costa
Ranch Hand

Joined: Feb 05, 2009
Posts: 31

Ravi,

Maybe this link can help you: http://myarch.com/using-xml-validation-framework-with-web-services
Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104

Hello Oscar,

Is this okay to use with JAX-WS?

Thank you very much for your help.

Ravi
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2921
    
    5
Ravi Danum wrote:The code:
@XmlElement(required = true)
protected String userId;


You are having the wrong expectations with regards to that annotation. It simply indicates that the equivalent schema requires a userId, but there is no commitment on the part of the JAXB code-generator to actually generate code to enforce that constraint.
See javax.xml.bind.annotation.XmlElement.required().

If you want to perform XML Schema validation on the SOAP payload then you can do so with a validating parser in a javax.xml.ws.handler.soap.SOAPHandler - if you are willing to take the associated performance hit.
Writing a Handler in JAX-WS.

It is usually "quicker" to run custom coded constraints on the client

See also Axis 1.4 does not validate input parameters?
Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104
Thanks, Peer!

-Ravi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: web services client is not validating parameters
 
Similar Threads
JAX-WS and REST, anyone?
XML Any Element mapping to Java
Exception on while deploying Ear using Glassfish+Apache CXF 2.3.1+Eclipse Helios
Problem of create Web Service Client
Netbeans jax-ws generated sources erroring on method invocation.