Herkese merhaba.Bu yazımızda @MatrixParam ek açıklamasını öğreneceğiz.Bu annotation daha önce öğrenmiş olduğumuz @QueryParam'a benziyor.Örnek verecek olursak apples?order=random&color=red (@QueryParam) apples;order=random;color=red (@MatrixParam).Görünüş olarak fark bu.Matrix parametleri yolun herhangi bir yerinde olabilir apples;order=random;color=red/10/items gibi.En dikkat çekici farklardan bir tanesi de sorgu parametreleri kaynak olduğundan güvenlik açığı yaratabilir, matrix parametleri ise bir kaynak olmayıp kaynağa başvurma yöntemi olduğundan açık daha azdır.Burada daha fazla bilgi mevcut. Kodlarımıza göz atalım.
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
package com.mycompany.matrixparamannotation; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.MatrixParam; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.PathParam; | |
import javax.ws.rs.core.PathSegment; | |
import java.util.List; | |
@Path("/") | |
public class CustomerResource { | |
@GET | |
@Path("customers") | |
public String getCustomers(@MatrixParam("state") String state) { | |
String info = String.format("resource getCustomers(). state:%s%n", state); | |
return info; | |
} | |
@GET | |
@Path("{var:customers}/orders") | |
public String getOrders(@PathParam("var") PathSegment ps) { | |
String info = String.format("resource getOrders(). Path:%s, MatrixParams:%s%n", | |
ps.getPath(), ps.getMatrixParameters()); | |
return info; | |
} | |
@GET | |
@Path("{var1:customers}/{var2:orders}/{month}") | |
public String getMonthOrders(@PathParam("var1") PathSegment customerPs, | |
@PathParam("var2") PathSegment orderPs, | |
@PathParam("month") String month) { | |
String info = String.format("resource getMonthOrders(). Customers Matrix Param: %s," + | |
" Orders Matrix Param: %s, month :%s%n", customerPs.getMatrixParameters(), | |
orderPs.getMatrixParameters(), month); | |
return info; | |
} | |
@GET | |
@Path("testA/{var:.+}") | |
public String testList(@PathParam("var") List<PathSegment> pathSegmentList) { | |
String temp = ""; | |
for (PathSegment pathSegment : pathSegmentList) { | |
temp+= String.format("Path: %s, Matrix Params %s<br/>", pathSegment.getPath(), | |
pathSegment.getMatrixParameters()); | |
} | |
String info = String.format("resource testList.<br/> Matrix Param List:<br/> %s<br/>", temp); | |
return info; | |
} | |
} | |
Arkadaşlar bu konuyu iyi anlatamadığımı düşünüyorum.Biraz rahatsız olduğum için birkaç güne düzgün bir şekilde güncelleyeceğim.İYİ ÇALIŞMALAR..
Hiç yorum yok:
Yorum Gönder