This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.URI; | |
import javax.ws.rs.*; | |
import javax.ws.rs.core.*; | |
@Path("/") | |
public class MyResource { | |
private final UriInfo uriInfo; | |
private int qValue; | |
private int pathNum; | |
public MyResource(@QueryParam("test") int qValue, | |
@Context UriInfo uriInfo, | |
@PathParam("num") int pathNum | |
) { | |
this.pathNum = pathNum; | |
this.uriInfo = uriInfo; | |
this.qValue = qValue; | |
} | |
@GET | |
@Path("/test{num:[1,9]{0,1}}") | |
public String handleRequest() { | |
URI uri = uriInfo.getRequestUri(); | |
return String.format("response from: %s%n PathNum: %s%n q: %s%n", | |
uri, pathNum, qValue); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.ws.rs.client.Client; | |
import javax.ws.rs.client.ClientBuilder; | |
import javax.ws.rs.client.WebTarget; | |
public class MyClient { | |
public static void main(String [] args){ | |
Client client=ClientBuilder.newClient(); | |
WebTarget target=client.target("http://localhost:8080/ResourceConstructor/test9"); | |
String response=target.queryParam("test",496).request().get()+""; | |
System.out.println(response); | |
} | |
} |
Buraya kadar olan yazılarımı gözden geçirip hatalarımı düzeltip güncelleyeceğim.Kodlarımı yazdığım bilgisayarım çok eski olduğundan biraz ağır ilerliyoruz.Kısmet olursa bu hafta bilgisayarımı yenileceğim.Daha sonra yazılarımızın sayısı hızla artacak.JAX-RS'i bitirip.HttpClient,mikroservisler gibi konular ile devam edeceğiz.Bu arada yetişirse bu yaz'ın sonuna kadar hibernate,jpa,spring mvc gibi JAVA EE teknolojilerini birlikte öğrenip çok iyi projeler geliştireceğiz.Bir sonraki yazımızda görüşmek üzere kendinize iyi bakın.
Hiç yorum yok:
Yorum Gönder