Advertisement
Guest User

Untitled

a guest
Dec 8th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 KB | None | 0 0
  1. package entity;
  2.  
  3. import java.io.Serializable;
  4. import javax.persistence.Entity;
  5. import javax.persistence.GeneratedValue;
  6. import javax.persistence.GenerationType;
  7. import javax.persistence.Id;
  8. import javax.xml.bind.annotation.XmlRootElement;
  9.  
  10. /**
  11. *
  12. * @author Penz
  13. */
  14. @Entity(name="Player")
  15. @XmlRootElement
  16. public class Player implements Serializable {
  17.  
  18. @Id
  19. @GeneratedValue(strategy = GenerationType.IDENTITY)
  20. private int playerId;
  21.  
  22. private String username, email, password;
  23.  
  24. // @OneToOne
  25. // private List<Scoreboard> Scoreboard = new ArrayList<>();
  26. //
  27. // @OneToMany
  28. // private List<Upgrade> upgrades = new ArrayList<>();
  29.  
  30. public Player() {
  31. }
  32.  
  33. public Player(String username, String email, String password) {
  34. this.username = username;
  35. this.email = email;
  36. this.password = password;
  37. }
  38.  
  39. public int getPlayerid() {
  40. return playerId;
  41. }
  42.  
  43. public String getUsername() {
  44. return username;
  45. }
  46.  
  47. public void setUsername(String username) {
  48. this.username = username;
  49. }
  50.  
  51. public String getEmail() {
  52. return email;
  53. }
  54.  
  55. public void setEmail(String email) {
  56. this.email = email;
  57. }
  58.  
  59. public String getPassword() {
  60. return password;
  61. }
  62.  
  63. public void setPassword(String password) {
  64. this.password = password;
  65. }
  66.  
  67.  
  68. }
  69.  
  70. package repository;
  71.  
  72. import entity.Player;
  73. import java.util.List;
  74. import javax.ejb.Stateless;
  75. import javax.ws.rs.Consumes;
  76. import javax.ws.rs.DELETE;
  77. import javax.ws.rs.GET;
  78. import javax.ws.rs.POST;
  79. import javax.ws.rs.PUT;
  80. import javax.ws.rs.Path;
  81. import javax.ws.rs.PathParam;
  82. import javax.ws.rs.Produces;
  83. import javax.ws.rs.core.MediaType;
  84. import javax.ws.rs.core.Response;
  85. import service.Authentication;
  86.  
  87. /**
  88. *
  89. * @author Penz
  90. */
  91. @Stateless
  92. public class PlayerFacadeREST extends AbstractFacade<Player> {
  93.  
  94. Authentication auth = new Authentication();
  95.  
  96. public PlayerFacadeREST() {
  97. super(Player.class);
  98. }
  99.  
  100. @POST
  101. @Override
  102. @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  103. public void create(Player entity) {
  104. super.create(entity);
  105. }
  106.  
  107. @PUT
  108. @Path("{id}")
  109. @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  110. public void edit(@PathParam("id") Integer id, Player entity) {
  111. super.edit(entity);
  112. }
  113.  
  114. @DELETE
  115. @Path("{id}")
  116. public void remove(@PathParam("id") Integer id) {
  117. super.remove(super.find(id));
  118. }
  119.  
  120. @GET
  121. @Path("{id}")
  122. @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  123. public Player find(@PathParam("id") Integer id) {
  124. return super.find(id);
  125. }
  126.  
  127. @GET
  128. @Override
  129. @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  130. public List<Player> findAll() {
  131. return super.findAll();
  132. }
  133.  
  134. @GET
  135. @Path("{from}/{to}")
  136. @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  137. public List<Player> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
  138. return super.findRange(new int[]{from, to});
  139. }
  140.  
  141. @GET
  142. @Path("count")
  143. @Produces(MediaType.TEXT_PLAIN)
  144. public String countREST() {
  145. return String.valueOf(super.count());
  146. }
  147.  
  148. @POST
  149. @Consumes(MediaType.APPLICATION_JSON)
  150. @Path("player.register")
  151. public Response registerUser(Player data) {
  152. Response.ResponseBuilder rs = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
  153. String tmp = (auth.encrypt(data.getPassword()));
  154. data.setPassword(tmp);
  155. try {
  156. this.create(data);
  157. rs.status(Response.Status.CREATED);
  158. } catch (Exception ex) {
  159. System.err.println(ex);
  160. }
  161. return rs.build();
  162. }
  163.  
  164. @POST
  165. @Consumes("application/json")
  166. public Response loginUser() {
  167. Response.ResponseBuilder rs = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
  168. try {
  169.  
  170. } catch (Exception ex) {
  171.  
  172. }
  173. return rs.build();
  174. }
  175. }
  176.  
  177. <?xml version="1.0" encoding="UTF-8"?>
  178. <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  179. <persistence-unit name="Dont_Quit_Squid_Backend_PU" transaction-type="JTA">
  180. <jta-data-source>java:app/dqs</jta-data-source>
  181. <class>entity.Player</class>
  182. <exclude-unlisted-classes>false</exclude-unlisted-classes>
  183. <properties>
  184. <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
  185. </properties>
  186. </persistence-unit>
  187. </persistence>
  188.  
  189. [2017-12-08T22:40:26.183+0100] [Payara 4.1] [SCHWERWIEGEND] [] [] [tid: _ThreadID=27 _ThreadName=http-thread-pool::http-listener-1(3)] [timeMillis: 1512769226183] [levelValue: 1000] [[
  190. java.lang.IllegalArgumentException: Object: entity.Player@3a0233d5 is not a known Entity type.
  191. at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4226)
  192. at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:507)
  193. at repository.AbstractFacade.create(AbstractFacade.java:33)
  194. at repository.PlayerFacadeREST.create(PlayerFacadeREST.java:35)
  195. at repository.PlayerFacadeREST.registerUser(PlayerFacadeREST.java:87)
  196. at service.ApiResource.registerUser(ApiResource.java:47)
  197. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  198. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  199. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  200. at java.lang.reflect.Method.invoke(Method.java:497)
  201. at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
  202. at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
  203. at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
  204. at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)
  205. at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
  206. at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
  207. at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
  208. at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
  209. at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
  210. at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
  211. at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
  212. at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
  213. at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
  214. at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
  215. at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
  216. at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
  217. at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
  218. at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
  219. at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
  220. at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
  221. at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
  222. at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
  223. at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1692)
  224. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)
  225. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
  226. at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:654)
  227. at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:593)
  228. at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
  229. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159)
  230. at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
  231. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
  232. at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:483)
  233. at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
  234. at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
  235. at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
  236. at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
  237. at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
  238. at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
  239. at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
  240. at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
  241. at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
  242. at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
  243. at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
  244. at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
  245. at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
  246. at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
  247. at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
  248. at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
  249. at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
  250. at java.lang.Thread.run(Thread.java:745)
  251. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement