Clarification while using axis2-wsdl2java-approach - java

I am trying to use axis2-wsdl2code-maven-plugin for auto generating the server side class files from a wsdl.
I am not sure how to implement the SkeletonInterface to call the business logic. There is an auto-generated Skeleton file which implements the interface, but it has a un-implemented method in it.
The problem is that I am not allowed to modify auto-gen files hence not sure on how to implement the method.
Below are the things that I have tried:
Few issues that I am facing:
i. Tried to rename the interface implementation class and call it through service.xml, but the new impl was not being called. (AuthenticatedServicesValidSkeletonImpl.java)
ii. Tried to extend the Skeleton class, but got null pointer exception while deploying the application and there was nothing much which I could get from the logs.
iii. Tried with cfx plugin for auto-generation of classes as well, but getting similar issues in it.
Please help regarding this.

You need to put your business logic in the un-implemented method in the AuthenticatedServicesValidSkeletonImpl.java. This will provide you a POJO of Request, and at the end, you need to return back a POJO of Response which will then be serialized into the WebService Response. The Request and Response objects are already created by WSDL2java, you just need to use them.

Related

Files upload in Spring using PUT method - testing and general idea

I am designing REST API of simple file storage where one of the operations is file upload that goes together with some file metadata (using "multipart/form-data").
For some cases I need the file ID to be generated out of my application so I use PUT Http method. When ID goes from outside the best practice is to use PUT method instead of POST. The reason is that PUT operation is idempotent. POST is not idempotent and is used when ID is generated internally.
Do you think that going with PUT is correct for file upload? (I have also POST because ID is sometimes generated internally)
Assuming that it is correct I have an issue with automated integration testing in Spring. The problem is with MockMvc support class called MockMultipartHttpServletRequestBuilder when writing integration test. It does not allow to change POST to PUT. Http method is constructor parameter somewhere higher in inheritence hierarchy and the filed is "private final". All the constructors of these classes are with default visibility modifier so when I extend it I am not able to call super constructors. It is completly sealed.
Any idea how to achieve this call with PUT method? (I can use Java or Groovy for this)
ResultActions response= mockMvc.perform(
fileUpload("/files")
.file(file)
.param("origin", origin)
)

Need help on Spring Security REST API plugin for grails

I just faced the issue while using Spring Security REST API plugin for grails.
When I want to update some object of certain class. I then call the URL with PUT in it and the object which needed to updated.
But suppose I send the different object of different class, It still takes the id from there gets the object of required class and updates it.
Example: I want to update the test object, so I call /com/test with PUT and object of com.Test domain (this works great)
But if I call the same URL /com/test with object of com.Test123 domain, it then takes the id and gets the object of Test domain with the same id and updates it.
I don't need this. If the class doesn't match, it must show the class mismatch error.
Is it some configuration issue?
What is the wire format for your PUT request.
If it is JSON then the server will simply try and re-create your server side object from the JSON data. And so long as the signatures match the object will be unmarshalling without an error.
To get the sort of behavior you are looking for you need to use XML and JAXB. In this case the XML sent across will have enough info to ensure the correct class is created when unmarshalling.

Java Webservice based on Object

I'm using web services and I want to step it up a notch. I'm using Axis2 with JAX-WS. I'm thinking of transfering objects instead of String[]. After I googled a bit, I found that JAXB is the right support to do this.
However, everytime I want to add a modelclass that needs to be transferred, I need to do a lot of work (to shut up about all the annotations where I can make mistakes). So I thought it would be easier to abstract this a bit.
I was thinking of creating web services using the Object type. I can then use methods as addObject(Object object), removeObject(Object object), retrieveObject(). This means my server needs to handle incomming objects. If I then add a new model class, I just need to catch it at server end. My client will need to include the model classes causing some redundancy but I'm OK with that. I have the feeling that Java cannot support my idea at this momemnt. At least JAX-WS & JAXB technologies.
Can you guys tell me if I'm right or wrong about this, if this is a good idea or not and if so, maybe point me into the right direction on how to fix this (even if it means using another technology)
Thanks in advance!
Your client won't need a model type, but you will have to serialize and deserialize your data when you send messages from your server to your client. I'm not sure if JAX-WS is different from JAX-RS, but if they are the same, then you can add annotations that mark whether or not you want to produce/consume json or xml.
Once you serialize your model to json, your client will have no problem reading your data.
Also, yest you can use object when creating request and response objects. In a webservice that I recently wrote I created a service response class similar to this
public class Response
{
private Object data;
private boolean success;
public Response()
{
super();
}
//write getters and setters here
}
I think that I'm using the Object class in a similar fashion to what you have in mind.
I definitely recommend you JAX-RS (implementing JAXB), in particular using the Jersey framework. It's usage is simple and allow you to marshall and unmarshall business objects.
Look at this Jersey Example
Hope it helps!

Apache Wink resource lifecycle

I'd like to know what the expected lifecycle behavior is for a class that responds to REST requests.
I have a class that's derived from javax.ws.rs.core.Application that identifies another class for responding to requests.
In that other class, it is annotated with #Path("foo") and methods within this class are annotated with #Path("bar"). When a request is made to foo/bar, I can see that the constructor is executed, then the PostConstruct method is properly called. After the method returns a response to the client, I can see that PreDestroy is called and then the class is squashed. On the next request, the process repeats.
Is this the correct behavior? Or is there a way that this class can remain in memory so that it doesn't need to go through the constructor and PostConstruct each time a request is made? This method relies on JAXB marshalling and various XSL transformations - I would like to cache the compiled XSLT transformation objects as well as the results of some transformations, but if the class is reinstantiated each time it is called, it makes it impossible for local caching.
This is running with Java 7, Wink, and Tomcat 7. Can someone please let me know if this is the expected behavior, or am I missing something that will just keep this class alive?
Thanks.
By JAX-RS specification, the Resources (the classes annotated with #Path) are created per request.
There are several ways to override this behavior.
The simplest way that can be used according to the JAX-RS specification, is to create a resource instance yourself (you are responsible to call the PostConstruct, not sure when and how you call to PostDestroy in this case) and return it using javax.ws.rs.core.Application.getSingletons()
Alternately, you can put #org.apache.wink.common.annotations.Scope(ScopeType.SINGLETON) annotation on your resource.
If you use Spring, Wink has a neat Spring integration module, so the Spring's lifecycle will be used. See http://incubator.apache.org/wink/1.0/html/5.5%20Spring%20Integration.html

Are there any other possible reasons for getting a GWT Serialization Policy exception?

I've been poking through this for about a week or so, now, and haven't found anything. I'm building an application with GWT, Hibernate, and Gilead, and I'm attempting to make an rpc call that loads a list of LightEntity objects from the database. This call worked perfectly, right up until I made a minimal change to my rpc interface - I added a deleteLightEntity method. Then I started receiving this error:
Type 'com.blah.shared.DomainObject' was not included in the set of types which can be
serialized by this SerializationPolicy or its Class object could not be loaded. For
security purposes, this type will not be serialized."
... which is normally characteristic of objects that don't have a no-args constructor, or perhaps don't implement Serializable or IsSerializable. Except my DomainObjects all do. And they all worked properly before I added this method to the rpc. I've even tried removing the method I added and recompiling, and it doesn't seem to work. I have also manually deleted the generated .gwt.rpc files, and cleared my browser cache. If anyone has any idea what could be causing these troubles, I would be very glad to hear it :)
If your class implements Serializable (and not IsSerializable), it will only be included in the serialization policy if it is referenced in the RPC interface, so check that.
If you have a reason not to reference that class you could use this workaround.
Also, since the error mentions the class DomainObject, which I assume is your global superclass, I would try to make it implement Serializable or IsSerializable too (in addition to its subclasses).
It would also help if you show us some source code.

Categories

Resources