Changes

Jax-rs 2.0

1,635 bytes added, 16:25, 26 April 2019
Service osztály definiálása
===Path paraméterek kezelése===<br>===Query paraméterek kezelése===<br> ===Header paraméterek kezelése=== <source lang="java"> @GET @Path("/book/") public Book getBook(@HeaderParam("Authorization") String token) { ...  }</source> <br> ==Response objektum előállítása=manuális összeállítása==
A @GET/POST/PUT annotációkkal ellátott metódusoknál a visszatérési objektum típus meghatározására két lehetőségünk van.
A státuszt kétféle képen határozhatjuk meg A Resonse osztálynak többféle metódusa van, ami beállítja a státuszt: ok=200, created=204 ..., vagy mi állítjuk be kézzel: .status(int)
 
<source lang="java">
public Response getContract() {
...
return Response.status(Status.OK).type(MediaType.APPLICATION_JSON).build();
}
</source>
 
<br>
==Hibakezelés==
{| class="wikitable"
! style="font-weight:bold; background-color:#c0c0c0;" | Base Exception
! style="font-weight:bold; background-color:#c0c0c0;" | Status code range
! style="font-weight:bold; background-color:#c0c0c0;" | Description
|-
| ClientErrorException
| 4XX
| Client side error
|-
| ServerErrorException
| 5XX
| Server side error
|-
| RedirectionException
| 3XX
| Redirect
|}
 
 
 
{| class="wikitable"
! style="font-weight:bold; background-color:#c0c0c0;" | Exception
! style="font-weight:bold; background-color:#c0c0c0;" | Status code
! style="font-weight:bold; background-color:#c0c0c0;" | Description
|-
| BadRequestException
| 400
| Malformed message
|-
| NotAuthorizedException
| 401
| Authentication failure
|-
| ForbiddenException
| 403
| Not permitted to access
|-
| NotFoundException
| 404
| Couldn’t find resource
|-
| NotAllowedException
| 405
| HTTP method not supported
|-
| NotAcceptableException
| 406
| Client media type requested not supported
|-
| NotSupportedException
| 415
| Client posted media type not supported
|-
| InternalServerErrorException
| 500
| General server error
|-
| ServiceUnavailableException
| 503
| Server is temporarily unavailable or busy
|}
===Response objektum használata===