2017-02-28 5 views
0

Ich erzeuge wsdl von Java. Ich habe nillable = false im Java-Feld angegeben, aber das Feld akzeptiert einen leeren Wert aus der Web-Service-Anfrage. Meine Bohne istNillable = false funktioniert nicht in Apache cxf

import java.util.Date; 
import java.util.Formatter; 
import java.util.Locale; 

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

import org.springframework.format.annotation.DateTimeFormat; 

@XmlRootElement(name = "LocationData") 
@XmlAccessorType(XmlAccessType.FIELD) 
public class LocationData { 

    private String id; 
    @DateTimeFormat(pattern="yyyy-mm-dd") 
    private Date date; 
    @NotNull 
    @XmlElement(required=true,nillable=false) 
    private String timezone; 
    @XmlElement(required=true,nillable=false) 
    private String location; 

    public void setTimezone(String timezone) { 
     this.timezone = timezone; 
    } 

    public String getTimezone() { 
     return timezone; 
    } 

    public void setLocation(String location) { 
     this.location = location; 
    } 

    public String getLocation() { 
     return location; 
    } 

    public void setDate(Date date) { 
     this.date = date; 
    } 

    public Date getDate() { 
     return date; 
    } 

    public String getId() { 
     return id; 
    } 

    public void setId(String id) { 
     this.id = id; 
    } 

    @Override 
    public String toString() { 
     StringBuilder sb = new StringBuilder(); 
     Formatter formatter = new Formatter(sb, Locale.US); 
     formatter.format("ID:%s\nLocation:%s\nDate:%s\nTime zone:%s\n", getId(), getLocation(), getDate(), getTimezone()); 

     return sb.toString(); 
    } 
} 

Meine Schnittstelle

@WebMethod 
    public LocationData createLocation(LocationData locationData) throws DuplicateLocationException; 

Bitte lassen Sie mich wissen, ist, was das Problem sein könnte? Fehle ich etwas? Jede Hilfe wäre willkommen.

Antwort

0

Ein anderer Weg ist die Validierung verwendet SimpleType mit Mindestwert und verwenden Schema Validierung.

  1. Aktivieren der Schema-Validierung.

    @WebMethod 
    @SchemaValidation(type=SchemaValidationType.BOTH, schemas="mywsdl.wsdl") 
    public LocationData createLocation(LocationData locationData) throws DuplicateLocationException; 
    
  2. Ändern Sie bitte Ihre WSDL-Datei Einschränkungen haben auf timezone

    <xs:element name="timezone"> 
        <xs:simpleType> 
        <xs:restriction base="xs:string"> 
         <xs:minLength value="1" /> 
        </xs:restriction> 
        </xs:simpleType> 
    </xs:element> 
    
+0

ähnlich werde ich 50 verschiedene Check RegexMuster für 50 Textelemente tun. Wenn ich in diesem Fall die obige Methode verwenden würde, müsste ich 50 Restriction Base erstellen. Gibt es eine Möglichkeit, wo ich Regex-Muster für jedes Element deklarieren kann – user6543599