我有一個以下的REST風格的web服務,我有兩個http get方法。一個功能通過應用程序登錄並執行其他功能。以下是代碼:如何從單一的webservices類調用不同的方法
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
/**
* REST Web Service
*
* @author Pointer
*/
@Path("generic")
public class GenericResource {
@Context
private UriInfo context;
/**
* Creates a new instance of GenericResource
*/
public GenericResource() {
}
/**
* Retrieves representation of an instance of
* com.ef.apps.xmpp.ws.GenericResource
*
* @return an instance of java.lang.String
*/
@GET
@Produces("text/html")
public String SignIn(@QueryParam("username") String username, @QueryParam("password") String password, @QueryParam("extension") String extension) {
//TODO return proper representation object
return "Credentials " + username + " : " + password + " : " + extension;
}
@GET
@Produces("text/html")
public String SignOut(@QueryParam("username") String username, @QueryParam("password") String password, @QueryParam("extension") String extension) {
//TODO return proper representation object
return "Credentials " + username + " : " + password + " : " + extension;
}
}
現在,我將在哪裏指定我要調用哪個函數來獲取http?
我已經定義的路徑前級即@Path(「通用」),我必須將其刪除:
你可以有這樣的事情實現這個?因爲我現在正在收到內部服務器錯誤。 – pointer
thanx很多幫助。 – pointer
應該小心這種方法,因爲'/ signin'不是一個「資源」它是一個「動詞」/「動作」,這不是很符合REST原則......此外'GET'不應該在這種情況下使用,但'POST',因爲這個調用會對資源進行「更改」(用戶認證)。 – emgsilva