Spring RestTemplate invoking webservice with errors and analyze status code

You need to implement ResponseErrorHandler in order to intercept response code, body, and header when you get non-2xx response codes from the service using rest template. Copy all the information you need, attach it to your custom exception and throw it so that you can catch it in your test. public class CustomResponseErrorHandler implements ResponseErrorHandler … Read more

Jersey Grizzly REST service not visible outside localhost

To make a server IP adress visible outside of localhost, you must fist open the neccessary firewall ports(if you have one), or use “0.0.0.0” instead of “localhost” in order for the server to listen to all IP addresses and network adapters. Before testing it in your local network, try pinging your server device from your … Read more

Is HTTP 404 an appropriate response for a PUT operation where some linked resource is not found? [closed]

There are a number of 4xx HTTP status codes. The most likely are either 404 or 409: 404 Not Found The server has not found anything matching the effective request URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, … Read more

Unit testing jersey Restful Services

For Jersey web services testing there are several testing frameworks, namely: Jersey Test Framework (already mentioned in other answer – see here documentation for version 1.17 here: https://jersey.java.net/documentation/1.17/test-framework.html) and REST-Assured (https://code.google.com/p/rest-assured) – see here a comparison/setup of both (http://www.hascode.com/2011/09/rest-assured-vs-jersey-test-framework-testing-your-restful-web-services/). I find the REST-Assured more interesting and powerful, but Jersey Test Framework is very easy to … Read more

How to remove the “_embedded” property in Spring HATEOAS

I close HAL feature, because it is hard to using Resources/Resource by restTemplate. I disable this feature by following code: public class SpringRestConfiguration implements RepositoryRestConfigurer { @Override public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.setDefaultMediaType(MediaType.APPLICATION_JSON); config.useHalAsDefaultJsonMediaType(false); } } It work for me. HAL is good if there are more support with restTemplate.

RESTful API – Designing sub-resources

Both approaches can be considered RESTful, provided you do not break the REST constraints defined in the chapter 5 of Roy Thomas Fielding’s dissertation: Client-server Stateless Cache Uniform interface Layered system Code-on-demand I cannot see major pitfalls in both approaches, but I would prefer the Approach B over the Approach A: the URLs are shorter, … Read more

Django REST Framework: raise error when extra fields are present on POST

Came across this question and found that using object level validation is a bit easier. This entails simply defining a validate method: class ModelASerializer(serializers.ModelSerializer): … def validate(self, data): if hasattr(self, ‘initial_data’): unknown_keys = set(self.initial_data.keys()) – set(self.fields.keys()) if unknown_keys: raise ValidationError(“Got unknown fields: {}”.format(unknown_keys)) return data

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)