I am trying to develop a IBM JAX_WS web service using RSA 7.5 and Websphere 7 server. Since I am a beginner, hence I am following Java-class first approach i.e. I am creating the Java classes first and then generating the WSDL file.
When i try to create the wsdl file, i am getting an exception:
java.security.PrivilegedActionException:com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationsException
Class has two properties of the same name "planId"
My class refered here looks something like this:
public class MemberDetails{
#XMLElement(required=true)
private String planId;
//public getters and setters for the planId;
}
I dont have any idea like why is this exception happening. Via Google search I tried a few alternatives to resolve it but none of them worked for me :(
Note:
This is the only annotation I am using throughout my workspace. I am not sure if this is dependent on some other annotations or not. But I tried with a few such as #XMLElement(name="Plan",required=true), #XMLType, etc but every time I am getting this exception.
This exception is occuring during wsgen. (java.lang.reflect.InvocationTargetException)
EDIT
Basically, when we create a wsdl from java service method and open that WSDL in SOAP UI, then we get <!--Optional--> at the top of every element. I want to remove this option tag <!--Optional--> tag, hence I am trying for #XMLElement(required=true) approach so that when I open the WSDL in SOAP UI <!--Optional--> does not appears for compulsary elements.
According to my concept, #XMLElement(required=true) will set the minOccurs to 1 i.e. greater than zero and hence the optional comment will be removed from WSDL when I open it in SOAP UI. But Unfortunately its not working hence my concept is incorrect. After the WSDL is generated, I can see that the minOccurs is still 0.
Please explain how can I remove the optional tag when I open the WSDL in SOAP UI.
Regards,
By default JAXB (JSR-222) implementations process public accessor methods and annotated fields. If you annotate a field that you also have get/set methods for you will get this exception:
If you are going to annotate fields then you should specify #XmlAccessorType(XmlAccessType.FIELD)
#XmlAccessorType(XmlAccessType.FIELD)
public class MemberDetails{
#XMLElement(required=true)
private String planId;
//public getters and setters for the planId;
}
Or you can annotate the property
public class MemberDetails{
private String planId;
#XMLElement(required=true)
public String getPlanId() {
return planId;
}
}
For More Information
http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
For JAXB2.0 annotating with #XmlTransient on getter or setter will prevent the conflict.
See more here: http://docs.oracle.com/javase/8/docs/api/javax/xml/bind/annotation/XmlTransient.html
Related
We have a pojo generated from yml which has #JsonProperty defined on the getter. This is based on maven plugin for openapi. For one such yml, we have a field settlementType. We can't change the name as this is the field to be sent to the vendor in the rest api call. When using jackson's ObjectMapper to deserializa the object, we get the following error -
Conflicting setter definitions for property "settlementType":
settlementType(1 param) vs setSettlementType(1 param).
I tried for a mixin class.
public class SettlementTypeMixin {
#JsonProperty("settlementType"
String settlementType;
#JsonIgnore
public void setSettlementType(String settlementType) {
this.settlementType = settelementType;
}
}
I added the mixin to the mapper using addMixinAnnotations method. But I don't see any change in the behavior.
I also tried setting the fieldVisibility, getterVisibility, setterVisibility and CreatorVisibilities as well. There are other types as well which the yml needs and at the end I have to enable the visibility for all the types mentioned below.
I am not able to get the object mapped using jackson. Please let me know if there is a way out for this.
I have annotated a class to be a Panache Entity. However, I have also included JAXB annotations:
#Entity
#XmlRootElement(name = "Person")
#XmlAccessorType(XmlAccessType.NONE)
public class Person extends PanacheEntity {
#XmlAttribute(name = "Name")
public String name;
}
When I try to return the object from a REST call I get the following exception:
2019-12-08 08:30:01,917 ERROR [org.jbo.res.res.i18n] (vert.x-worker-thread-3) RESTEASY002005: Failed executing GET /person: org.jboss.resteasy.plugins.providers.jaxb.JAXBMarshalException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
model.Person#name has mutually exclusive annotations #javax.xml.bind.annotation.XmlTransient and #javax.xml.bind.annotation.XmlAttribute
this problem is related to the following location:
at #javax.xml.bind.annotation.XmlTransient()
at model.Person
this problem is related to the following location:
at #javax.xml.bind.annotation.XmlAttribute(namespace="##default", name="Name", required=false)
at model.Person
at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.getMarshaller(AbstractJAXBProvider.java:187)
at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.writeTo(AbstractJAXBProvider.java:149)
So it seems the the Quarkus Panache framework is adding #XmlTransient to my public property.
I can get round this by changing the access of the name property to private and including getters/setters. However, this approach loses one of the benefits of Panache that your code is more compact and readible.
Is there anyway of keeping the public accessor of the class property and still making it work with JAXB?
Interesting use case.
I think we need to check that the attributes don't have any conflicting JAXB annotation before adding the #XmlTransient one automatically.
And it's probably also an issue with JSON-B/Jackson as we do the same thing.
I don't see any obvious workaround: we need to fix it in Quarkus.
Could you open a GitHub issue with a simple reproducer? Thanks!
The project which I work is a simple Java SE program which is ran using public static void main method. I have a DTO bean called StudentBean:
class StudentBean {
private String firstname;
private String lastname;
private Integer id;
private Integer age;
//setters and getters
}
I have over 100k student beans stored in a java.util.ArrayList. We have set of rules for each field. For ex, firstname should not be null and empty, age cannot be negative.
How do I write java code for validating hundreds of thousands of beans against the rules we have and write the log for the beans which violates the rules?
We thought of writing custom annotations like #NotNull, #NotEmpty, #PositiveNumber and have a validator logic which validates the beans according to the annotations they have on their variables. If you find this good, please point me to online resources which I can use to implement this.
As this is Java SE project, we do not have javax.validation jar, so no scope of using this library. It would be very helpful if we can achieve it using Java SE library only.
You can have a look at hibernate validator, and how to bootstrap the validation. There are already constraints you need available out of the box.
The fact that this is Java SE project doesn't mean you can't bootstrap validation by yourself.
I would try to keep it simple and just use a method public boolean isValid () within the bean which implement your rules. This way you need no annotations and no reflection.
I would like to create an application that saves and retrieves records to the GAE server. I followed the tutorial "Deploying to Google App Engine" http://code.google.com/webtoolkit/doc/latest/tutorial/appengine.html to get started.
I have the StockWatcher application working now, but in my application I need to store a String that can be large (>10KB). I read that I can't use a Java String type to store large strings and need to use the Text data type instead.
I think by Text, they mean: com.google.appengine.api.datastore.Text, but it would be nice to confirm this is correct. ???
Regardless, I can't get Text to work. After some research it appears both the types Key and Text can only be used in the server code and not the client code. It seems that this is because the source code is not available for these classes and GWT needs the source to create the JavaScript code on the client's computer. At least that my current working hypothesis as to why I'm getting the following errors:
21:52:52.823 [ERROR] [myapp] Line 15: The import com.google.appengine.api.datastore cannot be resolved
21:52:52.951 [ERROR] [myapp] Line 103: Key cannot be resolved to a type
21:52:53.011 [ERROR] [myapp] Line 106: Text cannot be resolved to a type
I use the following fields in a class in a shared folder.
shared/MyDataRecord
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
#Persistent
private Text description;
MyDataRecord class in a shared folder because I wanted to use to send back all the fields in one get method return rather than multiple individual field get methods. Here's how I use MyDataRecord class in my server/DataServiceImpl.java class
public class DataServiceImpl extends RemoteServiceServlet implements DataService
{
...
#Override
public MyDataRecord getDataRecord() throws NotLoggedInException
{
...
I've seen some posted solutions suggest using non-standard, 3rd party libraries, like http://www.resmarksystems.com/code/. I couldn't get this one installed, but even if I could, I'd prefer a different solution. Storing Text must be such a common task that I'd prefer to solve this using what is considered a standard solution.
I could change my code to return each field in multiple get methods instead of an single return of a MyDataRecord instance. However, even if that works, that would be significantly more work and more difficult to maintain over time. However, if this is what is normally expected, then that's what I'll do.
I'd like to solve this using what is considered best practices by GWT and GAE. A simple example or tutorial would go a long way, but I can't find one.
Are there example programs/tutorials that show what GWT considers best practices for storing and retrieving large strings?
I am a newbie with both GWT and GAE (as well as web development), please consider this in any responses, thanks.
No Snark Please
The serializable POJO. Note the NotPersistent annotation for description
package com.my.project.shared;
#PersistenceCapable(identityType=IdentityType.APPLICATION,detachable="true")
public class MyParent implements Serializable {
#PrimaryKey
#Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
private Long id;
#NotPersistent //Note the NotPersistent annotation. GAE won't persist this value in big table
private String description;
}
The second POJO. Notice the package
package com.my.project.server;
#PersistenceCapable(identityType=IdentityType.APPLICATION,detachable="true")
public class MyChild implements Serializable{//Not really required to implement Serializable
#PrimaryKey
#Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
private Long id;
#Persistent
private Long parentID;//Reference to the MyParent
#Persistent
private Text description;//The actual value of the description variable.
}
Notice the parent ID mapped in the child. While retrieving you will need to identify which child belongs to which parent.
In pseudo code
1) Load parent from DB
2) Identify child for this parent, and load it
3) Convert child.description->parent.description
4) Now you have a fully constructed parent POJO which is serializable. Send it to the UI
Just reverse the procedure on the way back from UI to GAE.
1) Define a NotPersistent field in your serializable POJO private String description
2) Define a new POJO on the server side which will have private Text description
3) When you persist/load the original POJO, retrieve the new POJO and populate the String description from the Text description
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.