2012-06-01 2 views
1

내 응용 프로그램에서 웹 서비스를 구현했습니다. 나는 비누 UI와 SOA를 통해 웹 서비스를 통해 내 서버에 개체를 보낼 때 나는 이런 식으로 뭔가 얻을 :요구 사항 수준의 속성을 나타내는 자바 웹 서비스

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:impl="http://impl.arg.lou.com/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <impl:addStudent> 
     <!--Optional:--> 
     <student> 
      <!--Optional:--> 
      <name>?</name> 
     </student> 
     </impl:addStudent> 
    </soapenv:Body> 
</soapenv:Envelope> 

내가 이름 필드는 선택 사양 일하지 않으려을, 그것은 필수 입력해야합니다. 내가 어떻게 해?

저는 Apache cxf를 사용합니다. 요구 수준에 대한

링크 : 웹 서비스 정의에서 http://www.ietf.org/rfc/rfc2119.txt

+0

당신은 당신의 질문의 제목을 변경해야합니다 : 당신은 웹 서비스 메시지 권리를에 제한을 추가하기위한 요구하고있다? – ggarciao

답변

2

당신은 메시지의 XML 스키마를 정의하는 유형 섹션이 있습니다. 이 정의에서 "필수 필드"와 같은 몇 가지 제약 조건을 설정할 수 있습니다.

예 :이 같은 아파치 CXF 구성에서 스키마 유효성 검사를 활성화하지 않으면

이제
<wsdl:definitions name="myService" ...> 
    <wsdl:types> 
    <xs:schema version="1.0" targetNamespace="myNameSpace" xmlns:tns="myNameSpace"> 
     <xs:complexType name="studentType"> 
     <xs:attribute name="name" type="xs:string" use="required" /> 
     </xs:complexType> 
     <xs:element name="student" nillable="false" type="tns:studentType"/> 
    </xs:schema> 
    </wsdl:types> 
    ... 
</wsdl:definitions> 

이, 이것은 서버 측에서 검증되지 않습니다 :

<jaxws:endpoint id="myService" ...> 
    <jaxws:properties> 
    <entry key="schema-validation-enabled" value="true" /> 
    ... 
    </jaxws:properties> 
    ... 
</jaxws:endpoint> 

추 신 : SOAP UI는 대상 웹 서비스의 XML 스키마를 사용하여 기본 요청을 생성합니다. XML 스키마는이 use="required" 또는 nillable="false"는 요소상의 <!-- optional --> 댓글을 추가 할 것이다없는 경우

+0

Java 클래스에서 변수를 정의하기 직전에 주석을 사용할 수 있습니까? – kamaci

+0

JAXWS와 JAXB를 "첫 번째 코드"접근 방식으로 사용하는 경우에는 @XmlElement (nillable = false) 및 @XmlAttribute (required = false)와 같은 JAXB 주석을 사용할 수 있습니다. – ggarciao