• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

web services client is not validating parameters

 
Ravi Danum
Ranch Hand
Posts: 146
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravi,

Try to use this annotation in the attribute:


 
Ravi Danum
Ranch Hand
Posts: 146
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I just now tried this and get the same results.

-Ravi
 
Oscar Costa
Ranch Hand
Posts: 31
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi,

Maybe this link can help you: http://myarch.com/using-xml-validation-framework-with-web-services
 
Ravi Danum
Ranch Hand
Posts: 146
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello Oscar,

Is this okay to use with JAX-WS?

Thank you very much for your help.

Ravi
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 146
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Peer!

-Ravi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic