wood burning stoves 2.0*
The moose likes Web Services and the fly likes general web service definition question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "general web service definition question" Watch "general web service definition question" New topic
Author

general web service definition question

jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
i have the following class

@XmlAccessorType(XmlAccessType.FIELD)
public class Payment {

@XmlElement(required = true)
private String paymentID;

@XmlElement(required = false, nillable = true)
protected List<PaymentStatusHistoryDetail> statusHistory;
}


my questions are:

1. how can i limit the string lenght for paymentID
2. how can i limit the list lengh for statusHistory, ie, i want only 4 items.
3. is there way to use an annotation as validator for paymentID.

thank you for help
Lingan Rajan
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
Even if a restiction like the below is put inline with the element in wsdl , the generated classes do not have any annotation to restrict the length.
I usually code a handler to intercept the request and validate against the schema.

You can try to add the maxlength attribute in wsdl to see if that helps the lists size.
As I said before it may not reflect in the annotations. You could do this validation too in the handler.

<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="20"/>
</xsd:restriction>
</xsd:simpleType>
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
but if i use .xsd to define all the datatype it could be too difficult to maintain since i have 2 places need to work on java code and .xsd file.

i am really hoping there is way to annotate the attributes so that i could do validation once data is entered.

Lingan Rajan
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
Jim
I may be missing something here , But usually you should be able to refer the XSD from within your WSDL and generate the classes.
This way it is always only one place where you are maintining the definitions.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
jim li wrote:i am really hoping there is way to annotate the attributes so that i could do validation once data is entered.

As far as I know, JAXB has no support for this.
You may be able to use JSR 303, aka Bean Validation, to annotate the JAXB classes.
However, I feel that the solution suggested by Lingan Rajan in connection with WSDL-first development is a much better idea.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
Lingan Rajan wrote:Jim
I may be missing something here , But usually you should be able to refer the XSD from within your WSDL and generate the classes.
This way it is always only one place where you are maintining the definitions.


1 .so for the datatype definition, do i have to manually define them or can i use to tool to generate it .

2. once have the datatype definition ready in .xsd, and i generate wsld file and .xsd file from my java classes.

how can i associate datatype .xsd file with .xsd files which are generated from java. do i have to manually change it ? (i mean change it line by line since the .xsd from java class has its original definition instead of pointing to datatype which i defined.)

thank you
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
If you want to do code-first development, you can do this the first time and let JAX-WS generated the WSDL and XML schemas for you.
However, after the first time, you use the WSDL-first approach and only change the WSDL and/or XML schemas, from which you then generate artifacts.
So:
1. JAX-WS can generate them for you the first time.
2. You generate artifacts from the WSDL which, if needed, imports any XML schemas it uses.

To make sure that your JAX-WS web service uses the existing WSDL and does not generate a new one, use the wsdlLocation attribute in the @WebService annotation.
Best wishes!
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
Ivan Krizsan wrote:Hi!
If you want to do code-first development, you can do this the first time and let JAX-WS generated the WSDL and XML schemas for you.
However, after the first time, you use the WSDL-first approach and only change the WSDL and/or XML schemas, from which you then generate artifacts.
So:
1. JAX-WS can generate them for you the first time.
2. You generate artifacts from the WSDL which, if needed, imports any XML schemas it uses.

To make sure that your JAX-WS web service uses the existing WSDL and does not generate a new one, use the wsdlLocation attribute in the @WebService annotation.
Best wishes!


this is what i did:

1. generate wsdl and .xsd files
2. import defined data type <xs:include schemaLocation="WebServiceDataType.xsd"/>
manually edit the .xsd file such as change the variable type from String to customizedString which is defined in a separate .xsd file

3. generate java code based on the wsld file and .xsd files
4. generate wsld and .xsd file based on the java classes. (now here is the problem, the variable that i defined as customizedString in .xsd files has changed back to String, can anyone tell me how to not make this happen, i want my customized data type. in addition, my include line
<xs:include schemaLocation="WebServiceDataType.xsd"/> is gone
)

please help

thank you
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Have you, as I suggested in my earlier post, modified in the @WebService annotation to point to the existing WSDL, using the wsdlLocation attribute?
Best wishes!
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
Ivan Krizsan wrote:Hi!
Have you, as I suggested in my earlier post, modified in the @WebService annotation to point to the existing WSDL, using the wsdlLocation attribute?
Best wishes!



Hi Ivan

thank you for the reply. i still got problems.

1. i have one aaservice. wsdl file, one aaservice_chemea.xsd file , and one datatype xsd file which was created by me mannually (datatype .xsd file is included in aaservice_chemea.xsd)
2. generate java classes based on aaservice. wsdl file.
3. generate wsdl files based on java classes with wsdlLocation which points to the existing wsdl file
4. aaservice. wsdl file, aaservice_chemea.xsd file are overridden. datatype .xsd file is not included in aaservice_chemea.xsd. (this is the problem, since i do not want to go through every atrribute again and manually edit them to point to a datatype which is defined in .xsd file again)

how can i fix it?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Why do you do step 3? Have you tried skipping it?
It seems unnecessary to me - just modify the generated classes to point to the existing WSDL.
Best wishes!
Aditya Keyal
Ranch Hand

Joined: Dec 01, 2008
Posts: 71
Ivan Krizsan wrote:Hi!
Have you, as I suggested in my earlier post, modified in the @WebService annotation to point to the existing WSDL, using the wsdlLocation attribute?
Best wishes!


Hi Ivan,

I am trying to re-use my existing wsdl for a JAX-WS application I created. (I am using Glassfishv3 with RI version - JAX-WS RI 2.2-hudson-752).

I placed my wsdl in the WEB-INF/wsdl folder. the value of @WebService.wsdlLocation is the name of my wsdl file . However every time I access the wsdl a generated file is being dispensed.
When I referred the glassfish RI 2.2 annotation documents it says that this feature is currently not implemented. I was wondering which version of RI or server were you using. Or if I am doing something wrong please let me know. Thanks.


- Aditya Webservices Blog
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I have succeeded specifying the location of an existing WSDL like this:

Note how the location of the WSDL is specified using the wsdlLocation attribute.
Best wishes!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: general web service definition question
 
Similar Threads
convert java classes to .xsd xml schema in eclise
InvalidMappingException
Doubt on the JAXB: XML Schema to Java mapping for anonymous complex type.
XMLDocument.selectNodes
How to set minOccurs="1" in wsdl for an input parameter to web service method.