当我尝试运行JAX-RS时,我收到了错误消息,该怎么让它正常工作?PlayerManagementLocal是ejb PlayerManagement的@Local,它可以正常工作。
错误消息。
错误消息。
com.sun.jersey.api.container.ContainerException: An instance of EJB class rest.JSONService could not be looked up using simple form name or the fully-qualified form name.Ensure that the EJB/JAX-RS component implements at most one interface
jaxrs.java
package rest;
import javax.ejb.EJB;
import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import prayForHunt.model.Person;
import prayForHunt.sb.PlayerManagement;
import prayForHunt.sb.PlayerManagementLocal;
@Stateless
@Path("/json")
public class JSONService {
@EJB
PlayerManagementLocal playerManagement;
@GET
@Path("/get/login/{login}/{heslo}")
@Produces(MediaType.APPLICATION_JSON)
public String getTrackInJSON(@PathParam("login") String login, @PathParam("heslo") String heslo) {
return "ahojky";
}
@GET
@Path("/get/{param}")
@Produces(MediaType.APPLICATION_JSON)
public String getting(@PathParam("param") String msg) {
System.out.println("");
if(playerManagement.checkPlayer(msg)){
return "yes";
}
return "no";
}
}
这是代码,无法弄清楚如何让它正常工作——例如...从数据库中找到某些内容并将其与POST/GET服务中的字符串进行比较。
playerManagementLocal.java
@Local
public interface PlayerManagementLocal {
PlayerDTO getPlayers(String login);
List<PlayerDTO> getAllPlayers();
String getPassword(String login);
void newPlayer(PersonDTO user, String password);
void updatePlayer(PlayerDTO player);
void updatePlayerCard(PlayerCardDTO playerCard);
public void removePlayer(PlayerDTO player);
boolean checkPlayer(String login);
boolean checkPlayer(String login, String password);
void saveLocation(FavoriteLocationDTO loc);
List<FavoriteLocationDTO> getPlayerLocations(String login);
void removeLocation(int id);
}
playerManagemet.java
package prayForHunt.sb;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import prayForHunt.DTO.FavoriteLocationDTO;
import prayForHunt.DTO.PersonDTO;
import prayForHunt.DTO.PlayerCardDTO;
import prayForHunt.DTO.PlayerDTO;
import prayForHunt.model.*;
/**
*
* @author Nell
*/
@Stateless
public class PlayerManagement implements PlayerManagementLocal {
@PersistenceContext
EntityManager em;
@Override
public PlayerDTO getPlayers(String login) {
Player playerHelp = em.find(Player.class, login);
if (playerHelp == null) {
return null;
} else {
return new PlayerDTO(playerHelp);
}
}
@Override
public List<PlayerDTO> getAllPlayers() {
List<Player> list = (List<Player>) em.createNamedQuery(Player.Q_GET_ALL_PLAYERS).getResultList();
ArrayList<PlayerDTO> listDTO = new ArrayList<PlayerDTO>();
Iterator it = list.iterator();
while (it.hasNext()) {
listDTO.add(new PlayerDTO((Player) it.next()));
}
return listDTO;
}
@Override
public void newPlayer(PersonDTO user, String password) {
Player player = user.toPlayer();
player.setPassword(password);
PlayerCard card = new PlayerCard();
player.setPlayerCard(card);
em.merge(player);
}
@Override
public void updatePlayer(PlayerDTO player) {
Player en = em.find(Player.class, player.getLogin());
player.toEntity(en);
em.merge(en);
}
@Override
public void updatePlayerCard(PlayerCardDTO playerCard) {
PlayerCard en = em.find(PlayerCard.class, playerCard.getCardId());
playerCard.toEntity(en);
em.merge(en);
}
@Override
public void removePlayer(PlayerDTO player) {
Player en = em.find(Player.class, player.getLogin());
player.toEntity(en);
en = em.merge(en);
em.remove(en);
}
@Override
public boolean checkPlayer(String login) {
Player help = em.find(Player.class, login);
if (help != null) {
return true;
}
return false;
}
@Override
public boolean checkPlayer(String login, String password) {
Player help = em.find(Player.class, login);
if (help != null) {
return false;
}
if (password.equals(help.getPassword())) {
return true;
}
return false;
}
@Override
public String getPassword(String login) {
return em.find(Player.class, login).getPassword();
}
@Override
public void saveLocation(FavoriteLocationDTO loc) {
FavoriteLocation en = em.find(FavoriteLocation.class, loc.getId());
if (en == null) {
en = new FavoriteLocation();
en.setPlayer(em.find(Player.class, loc.getPlayer()));
}
en.setLat(loc.getLat());
en.setLng(loc.getLng());
en.setTitle(loc.getTitle());
en.setDescription(loc.getDescription());
em.merge(en);
}
@Override
public List<FavoriteLocationDTO> getPlayerLocations(String login) {
Player pl = em.find(Player.class, login);
List<FavoriteLocation> list = em.createNamedQuery(FavoriteLocation.Q_GET_ALL_PLAYERS_LOCATIONS).setParameter("player", pl).getResultList();
ArrayList<FavoriteLocationDTO> listDTO = new ArrayList<FavoriteLocationDTO>();
Iterator it = list.iterator();
while (it.hasNext()) {
listDTO.add(new FavoriteLocationDTO((FavoriteLocation) it.next()));
}
return listDTO;
}
@Override
public void removeLocation(int id) {
FavoriteLocation en = em.find(FavoriteLocation.class, id);
em.remove(en);
}
}