Change the Stripes HTTP Response Code - java

I'm using the Stripes framework to develop a Java app.
I need to return my custom HTTP response codes, I mean, sometimes in an ActionBean I want to return something different to "200 OK" when I create or update some object.
I'm not able to find any documentation about this. Some help??
Many thanks.

as in
getContext().getResponse().setStatus(500);

Related

SPRING - Can't retrieve a ResponseEntity with Feign while sent correctly formated

I'm trying to communicate information between two micro services in Spring. One is sending a ResponseEntity with an Object in the body, but on the other side I can't seem to get the correct response. All the fields are null.
this is the controller of my first microservice
this is what is returned when called directly
this is the code inspection of the response before it's sent
Then I try to recuperate this response in another micro service.
This is the client
This is the call to the first API
This is the response I get
So I'm stuck there, not getting why my client can't access the data. I have set breakpoints in both of the application and the first one is correctly called.
You can find my code there : https://github.com/Shikatamo/B3Examples
I have tried for 3-4h, and I'm really stuck there. It looks like something really stupid from my part but I can't seem to put my finger on it. All help is greatly appreciated at this point.
Try to get rid of ResponseEntity in your client:
#Component
#FeignClient("CourseStudent")
public interface ICourseStudentClient {
#RequestLine("GET /{id}")
CourseStudents getOneById(#Param("id") Long id);
}

Application/JSON is Unsupported Media Type in restful webservice

I am trying to create a restful-jersey webservice. I have to pass JSON object to the webservice.
#POST
#Path("/saveVehicleTrackingData")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.TEXT_PLAIN)
public String saveVehicleTrackingData(VehicleTracking vehicleTracking) {
return vehicleTracking.toString();
}
When I try try to make request to the service, it says HTTP Status 415 - Unsupported Media Type. Please help. Also, what should be the type of single argument of the method saveVehicleTrackingData.
PS: I am using POSTMAN to make http request. http://goo.gl/vwXNXQ
UPDATE :
As pointed out by peeskillet, the missing thing here is JSON Provider. The next challenge that I have is, how to integrate the JSON Provider in my project. After researching a little, I found FasterXML jackson as one of the JSON provider.
This image is just for reference. I just had it from another post.
Basically when you use raw, it will default to text/plain. The JSON in the drop down, is simply to select syntax highlighting. You still need to set the Content-Type header to application/json. You can click on the Headers button and add it.
For your first question:
What kind of hosting (Tomcat, GlassFish or whatever...) are you using, and what is the Java version of the host? I know from experience that different version of Tomcat in combination with Jersey sometimes gives problems with #Consumes(MediaType.APPLICATION_JSON).
About your second question:
You want to build a RESTful webservice, the right name for a path should be; VehicleTrackingData (or whatever you like). This path will work (request/response) with the known HTTP verbs; GET, POST, PUT or DELETE.

AngularJS Post Method RESTFUL

I have an Angular Controller, a factory service and a app.js.
There is also a MongoDB in the background. So i have a GET Method and it's already running very well. But how do i create a post method over HTTP?
So there is a formular as a html file. There are some CheckBoxes and input fields. AngularJS i use for the Frontend, in the background theres a JAVA Program.
You can use the below shorthand syntax for GET and POST requests:
GET: $http.get('/URL').success(successCallback);
POST: $http.post('/URL', data).success(successCallback);
Refer to this link for details on how to set different parameters. You may also have a look at tutorials here.

Starting point for converting jersey project to standard servlet app

I am trying to implement the example shown here.
The example seems to be for a jersey setup, which I am not using or familiar. How hard would it be to convert this to a standard java servlet project(idk how to name this)
What steps should I take. It seems most of the # annotations need to be changed to servlets.
This also seems very differnt from the standard appengine upload setup which all takes place in one servlet.
This would be a lot of work to rework the code to standard servlet and remove jersey. Jersey takes away so much boilerplate code. For example the JSON conversion is done by jersey, which otherwise would have to be custom implemented.
And you can for sure deploy more than one servlet to gae, in which way should this be standard?
Just look at the first method:
#GET
#Path("/url")
public Response getCallbackUrl() {
String url = blobstoreService.createUploadUrl("/rest/file");
return Response.ok(new FileUrl(url)).build();
}
When using only standard servlet you would need to do:
Servlet Definition and Mapping in web.xml to /url
Implement a HttpServlet, override doGet() method
Send Response Code 200 OK
Set appropriate HTTP Response Headers
Convert Response to JSON and write it to response

How to send to a jsp page from a rest call

I've written a rest interface (with jersey), a browser will be calling this rest interface. I would like show some html/jsp to the user as a response to this rest call...
Is this possible? How do I do it?
Yes, that is possible. This post as well as this one gives a hint how to use Viewables to return JSPs as a response.

Categories

Resources