Changes

Jump to: navigation, search

Jax-rs 2.0

947 bytes added, 19:23, 16 February 2019
JAX-RS kliens
Response response = client.target(baseUrl).path("login").
request(MediaType.APPLICATION_JSON).post(Entity.json(loginRequest));
 
int status = e.getResponse().getStatus();
if (status < 300) {
String responseString = response.readEntity(String.class);
int status = e.getResponse().getStatus();
LoginResponse loginResponse = objectMapper.readValue(responseString,LoginResponse.class);
</source>
 
 
<source lang="java">
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
 
private static Client client = ClientBuilder.newClient();
 
LoginRequst loginRequest = new LoginRequest();
try {
LoginRequst loginRequest = client.target(baseUrl).path("login").
request(MediaType.APPLICATION_JSON).post(Entity.json(loginRequest), LoginRequst.class);
 
// 400-as hibák
} catch (ClientErrorException e) {
 
ErrorMessageResponse errorMessageResponse = e.getResponse().readEntity(ErrorMessageResponse.class);
int status = e.getResponse().getStatus();
 
// 500-as hibák
} catch (ServerErrorException e) {
...
// 300-as redirekt hibák
} catch (RedirectionException e) {
...
}
</source>

Navigation menu