I am trying to make my #webparam mandatory using (#XmlElement(required=true) but the generated XSD still shows this as minOccurs="0". Also tried setting nillable=false but still not working.
Here is my web method :
#WebMethod
#WebResult(name = "Biller")
public Biller getBiller(#XmlElement(required=true) #WebParam(name = "billerId") Integer billerId){}
Please suggest.
As specified by me in comments - either you need to wrap your Integer variable into some Java POJO and apply rules for specific fields in that POJO or change to primitive type because - reference types are always optional but constituent fields of wrapper types can be made required or optional.
Primitive types are always required.
Refer this answer
Then comes the question about default values - and for that refer Answers to this question and summary is - if nothing is specified -
minOccurs and maxOccurs default to 1
Now why your call succeeds with SOAP UI - Your xsd is correct and that is acknowledged by SOAP UI so my guess is client might be attaching some default values when its missing. I haven't used SOAP UI. Try examining your request ans see if value is really missing. If value is indeed missing in request then try to examine as why validation is not kicking in.
Related
I'd like to log JSON request entity bodies for all POST requests to all resources in a Dropwizard Application of mine. The catch is that I need to resolve the request's type, make a copy of the entity, and do some custom request field formatting before the entity is logged. I also cannot change the request's Class or the Field's Class in anyway (even with Annotations).
How do I leverage the logic that Jersey and Jackson use for resolving the Java POJO class type before the request is passed into the Resource?
Should I use Filters, Interceptors, or EventListener implementations?
// I need to create raw JSON for instances of this class where fields
// of type Location get specially formatted but only for logging.
// i.e doesn't affect normal structure of the request
class CustomRequest {
// In the raw JSON i create this field's name should be converted
// to 'origin_geo' and its value should be a float with the first
// value being the longitude and the second element being the
// latitude.
public Location origin;
public String otherField;
}
interface Location {
float getLongitude();
float getLatitude();
}
For other Applications to leverage the middleware, I want to avoid needing to create special code for each different request type. I want something generic that is able to recognize Location typed fields for any entity and simply serialize the entity but with modification to those Location typed fields.
Does anyone know the right way to do this with the frameworks at play? I believe Jersey is able to use reflection to resolve the type when the resource method is resolved by looking at the method's parameters and choosing the first parameter that satisfies some set of conditions. I would like to avoid reimplementing this.
Is there any way of getting the metadata for a solr core ?
For instance I know the core name, and can obtain a SolServer from that and I also know the field name.
Is there any way to determine the metadata though. Specifically I would like to know whether the field type is an int or a double.
Thanks
You can make a request to the luke request handler:
http://localhost:8983/solr/corename/admin/luke?show=schema&wt=json&_=1453816769771
The output will include the schema for the core, along with the defined fields, their settings and their types:
{"fields":{"xyz":{"type":"string","flags":"I-S-M---OF-----l","copyDests":[],"copySources":[]}, .... }
A neat trick to find these endpoints is to watch the 'network' tab when browsing the admin interface to Solr, as the admin interface is just a static HTML / Javascript frontend that makes all the requests for actual content from the Solr server behind the scenes.
In the context of Spring Webflow 2.0.x......
I handle form binding "typemismatches", i.e. as a result of trying to map a String onto a Integer field, by using the following in my messages.properties
typeMismatch={0} contains invalid data.
This works fine.
The problem is that if the field that the typeMismatch error occurred on was "required" then I also receive an error for the missing required field, which is logical I guess because the value that was submitted was never bound. ("Required" being defined in a Commons Validation XML file)
So, I dont want to see the "XXX is required field" error message when the field is only missing due to the typeMismatch. How do I resolve this? I thought about overriding initBinder() on the FormAction but quickly got nowhere.....
Like Yves mentioned, among the three approaches, i have used a custom validator method and its very easy. You can use a custom validator which checks if the form field already has a xml error message of required. If the field does not have an error, then you can check for your string validation. That way it will display only one.
The other method that you could use is try a multiple xml validation, one being required and the other one being a mask which checks for a particular regular expression. In your case if your field is an integer field, then you can go and perform a mask with regex checking for only numbers. The order of mask, required or required, mask in the xml decides which message gets a higher preference.
For example:
<field property="somefield" depends="required,mask" page="2">
<arg key="somelabel"/>
<var>
<var-name>mask</var-name>
<var-value>${somepattern}</var-value>
</var>
</field>
You have many options, in order of preference:
Set selectively the message typeMismatch.target.yourFieldName or typeMismatch.int in resources files
Implement your own Validator so that you can send a dedicated message when Integer parsing will fail before the binding step
Create a BindingErrorProcessor to handle different kind of parsing issues
Could anyone please clarify the defination of attribute?
for example, in the following code, what is an attribute:
request.setAttribute("ja",new foo.Employee());
Is the attribute in the above code an object of type foo.Employee(), or it is key/value pair, or it is actually "ja"?
Request attributes are values indexed by a key (in your case "ja") which are shared in the life of the request object. In Java filter, servlet, jsp, include and forward use same request object so for example you can push an object in a servlet and pull it in a JSP.
The same approach is for session and application scopes
Request attributes are (or at least act like) a map of objects, in this case the key is "ja" and the value is a new foo.Employee.
The session, page, and application have the same data structure.
From the servlet API specification:
Attributes are objects associated with a request. Attributes may be set by the
container to express information that otherwise could not be expressed via the API,
or may be set by a servlet to communicate information to another servlet (via the
RequestDispatcher). Only one attribute value may be associated with an attribute name.
Here an attribute is a custom piece of information (here a new foo.Employee) added to your request (in a Map,Object> . This information will last as long as this request is processed and it can be used later in the process, for example by a JSP.
It's a key value pair
From the docs:
setAttribute
public void
setAttribute(java.lang.String name,
java.lang.Object o)
Stores an attribute in this request. Attributes are reset between
requests. This method is most often
used in conjunction with
RequestDispatcher.
Attribute names should follow the same conventions as package names.
Names beginning with java., javax.,
and com.sun.*, are reserved for use by
Sun Microsystems.
If the value passed in is null, the effect is the same as calling
removeAttribute(java.lang.String).
I'm using JAX-WS api for wsdl generation.
Java-bean class is something like:
public class MyBean {
private String nullableField;
private String notNullableField;
// and here appropriate get/set/ters
}
When wsdl is generated then nullability of this fields is not specified.
Question: what (and where) necessary to specify that fields have corresponding nillable='' value in wsdl? I.e. how can I specify fields nullability in plain java code for wsdl?
At this time I'm generating wsdl and then correcting xml manually for fields nullability. That's not convenient. I want this nillable attribute'll be generated by java-ws automatically.
Any suggestions?
Thanks.
AFAIK, it is still not possible to generate nillable=false when using #WebParam i.e. when using a Java-first approach (as discussed in this thread). Actually, I'd recommend to use a WSDL-first approach if you want fine control.