Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.40 KB | None | 0 0
  1. Context Path:/cvgest
  2. Servlet Path:/api
  3. Path Info:/person/1
  4. Query String:null
  5. Stack Trace
  6. org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
  7. org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)
  8. org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)
  9. org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:168)
  10. org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:411)
  11. org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:202)
  12. org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
  13. org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
  14. org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
  15. javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
  16. io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
  17. io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
  18. io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
  19. org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
  20. io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  21. io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
  22. io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
  23. io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  24. io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
  25. io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
  26. io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
  27. io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
  28. io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
  29. io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
  30. io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  31. org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
  32. io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  33. io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  34. io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
  35. io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
  36. io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
  37. io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
  38. io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
  39. io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
  40. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  41. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  42. java.lang.Thread.run(Thread.java:745)
  43.  
  44. package com.goodotcom.cvgest.util;
  45.  
  46. import com.goodotcom.cvgest.model.Category;
  47. import org.hibernate.SessionFactory;
  48. import org.hibernate.boot.Metadata;
  49. import org.hibernate.boot.MetadataBuilder;
  50. import org.hibernate.boot.MetadataSources;
  51. import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
  52. import org.hibernate.boot.registry.StandardServiceRegistry;
  53. import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  54.  
  55. import java.io.File;
  56.  
  57. public class HibernateUtil {
  58. private static SessionFactory sessionFactory;
  59.  
  60. public static SessionFactory getSessionFactory(){
  61. final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
  62. .configure() // configures settings from hibernate.cfg.xml
  63. .build();
  64. try {
  65. sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
  66. }
  67. catch (Exception e) {
  68. // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
  69. // so destroy it manually.
  70. StandardServiceRegistryBuilder.destroy( registry );
  71. }
  72. return sessionFactory;
  73. }
  74. public static void shutdown() {
  75. // Close caches and connection pools
  76. getSessionFactory().close();
  77. }
  78. }
  79.  
  80. package com.goodotcom.cvgest.api;
  81.  
  82. import com.goodotcom.cvgest.model.Person;
  83. import com.goodotcom.cvgest.util.HibernateUtil;
  84. import org.hibernate.Session;
  85.  
  86. import javax.ws.rs.*;
  87. import javax.ws.rs.core.MediaType;
  88. import javax.ws.rs.core.Response;
  89. import java.util.List;
  90.  
  91. @Path("/person")
  92. @Produces(MediaType.APPLICATION_JSON)
  93. public class PersonResourceRESTService {
  94.  
  95. @GET
  96. @Path("/{id:[0-9][0-9]*}")
  97. public Person lookupPersonById(@PathParam("id") int id){
  98. Person person;
  99. Session session= HibernateUtil.getSessionFactory().openSession();
  100. person=session.get(Person.class,id);
  101. HibernateUtil.shutdown();
  102. return person;
  103. }
  104.  
  105. }
  106.  
  107. <?xml version="1.0" encoding="utf-8"?>
  108. <!DOCTYPE hibernate-configuration SYSTEM
  109. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  110.  
  111. <hibernate-configuration>
  112. <session-factory>
  113. <property name="hibernate.dialect">
  114. org.hibernate.dialect.MySQLDialect
  115. </property>
  116. <property name="hibernate.connection.driver_class">
  117. com.mysql.jdbc.Driver
  118. </property>
  119.  
  120. <property name="hibernate.connection.url">
  121. jdbc:mysql://localhost/cv_gest
  122. </property>
  123. <property name="hibernate.connection.username">
  124. cv_gest
  125. </property>
  126. <property name="hibernate.connection.password">
  127. cv_gest
  128. </property>
  129. <property name="cache.provider_class">
  130. org.hibernate.cache.NoCacheProvider
  131. </property>
  132.  
  133. <property name="hbm2ddl.auto">update</property>
  134.  
  135. <property name="show_sql">true</property>
  136. <property name="connection.pool_size">1</property>
  137. <property name="current_session_context_class">thread</property>
  138.  
  139. <!-- List of XML mapping files -->
  140. <mapping resource="skill.hbm.xml"/>
  141. <mapping resource="person.hbm.xml"/>
  142. <mapping resource="category.hbm.xml"/>
  143.  
  144. </session-factory>
  145. </hibernate-configuration>
  146.  
  147. <?xml version="1.0" encoding="UTF-8"?>
  148. <project xmlns="http://maven.apache.org/POM/4.0.0"
  149. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  150. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  151.  
  152. <modelVersion>4.0.0</modelVersion>
  153.  
  154. <groupId>com.goodotcom.cvgest</groupId>
  155. <artifactId>server</artifactId>
  156. <version>1.0-SNAPSHOT</version>
  157.  
  158. <packaging>war</packaging>
  159.  
  160. <properties>
  161. <resteasy.version>3.0.16.Final</resteasy.version>
  162. </properties>
  163.  
  164. <dependencies>
  165.  
  166. <dependency>
  167. <groupId>org.hibernate</groupId>
  168. <artifactId>hibernate-core</artifactId>
  169. <version>5.1.0.Final</version>
  170. </dependency>
  171.  
  172. <dependency>
  173. <groupId>org.slf4j</groupId>
  174. <artifactId>slf4j-simple</artifactId>
  175. <version>1.7.21</version>
  176. <scope>provided</scope>
  177. </dependency>
  178.  
  179. <dependency>
  180. <groupId>javax.inject</groupId>
  181. <artifactId>javax.inject</artifactId>
  182. <version>1</version>
  183. </dependency>
  184.  
  185. <dependency>
  186. <groupId>mysql</groupId>
  187. <artifactId>mysql-connector-java</artifactId>
  188. <version>5.1.38</version>
  189. </dependency>
  190.  
  191. <dependency>
  192. <groupId>junit</groupId>
  193. <artifactId>junit</artifactId>
  194. <version>4.12</version>
  195. <scope>test</scope>
  196. </dependency>
  197.  
  198. <dependency>
  199. <groupId>org.jboss.resteasy</groupId>
  200. <artifactId>resteasy-jaxrs</artifactId>
  201. <version>${resteasy.version}</version>
  202. <scope>provided</scope>
  203. </dependency>
  204. <dependency>
  205. <groupId>org.jboss.resteasy</groupId>
  206. <artifactId>resteasy-servlet-initializer</artifactId>
  207. <version>${resteasy.version}</version>
  208. <scope>provided</scope>
  209. </dependency>
  210.  
  211. <dependency>
  212. <groupId>com.drewnoakes</groupId>
  213. <artifactId>metadata-extractor</artifactId>
  214. <version>2.9.0</version>
  215. </dependency>
  216.  
  217. </dependencies>
  218.  
  219. <build>
  220. <plugins>
  221. <plugin>
  222. <groupId>org.wildfly.plugins</groupId>
  223. <artifactId>wildfly-maven-plugin</artifactId>
  224. <version>1.1.0.Alpha7</version>
  225. </plugin>
  226. </plugins>
  227.  
  228. <finalName>${project.groupId}-${project.artifactId}-${project.version}</finalName>
  229. <!--<plugins>-->
  230. <!--<plugin>-->
  231. <!--<groupId>org.apache.maven.plugins</groupId>-->
  232. <!--<artifactId>maven-deploy-plugin</artifactId>-->
  233. <!--<configuration>-->
  234. <!--<skip>true</skip>-->
  235. <!--</configuration>-->
  236. <!--</plugin>-->
  237.  
  238. <!--<plugin>-->
  239. <!--<groupId>org.apache.maven.plugins</groupId>-->
  240. <!--<artifactId>maven-compiler-plugin</artifactId>-->
  241. <!--<configuration>-->
  242. <!--<source>1.6</source>-->
  243. <!--<target>1.6</target>-->
  244. <!--</configuration>-->
  245. <!--</plugin>-->
  246. <!--</plugins>-->
  247. </build>
  248.  
  249. <profiles>
  250. <profile>
  251. <id>jboss-deploy</id>
  252. <build>
  253. <plugins>
  254. <plugin>
  255. <groupId>org.jboss.as.plugins</groupId>
  256. <artifactId>jboss-as-maven-plugin</artifactId>
  257. <version>7.4.Final</version>
  258. <executions>
  259. <execution>
  260. <id>deploy</id>
  261. <phase>install</phase>
  262. <goals>
  263. <goal>deploy</goal>
  264. </goals>
  265. <configuration>
  266. <username>admin</username>
  267. <password>password</password>
  268. </configuration>
  269. </execution>
  270. </executions>
  271. </plugin>
  272. </plugins>
  273. </build>
  274. </profile>
  275. <profile>
  276. <id>jboss-undeploy</id>
  277. <build>
  278. <plugins>
  279. <plugin>
  280. <groupId>org.jboss.as.plugins</groupId>
  281. <artifactId>jboss-as-maven-plugin</artifactId>
  282. <version>7.4.Final</version>
  283. <executions>
  284. <execution>
  285. <id>deploy</id>
  286. <phase>install</phase>
  287. <goals>
  288. <goal>undeploy</goal>
  289. </goals>
  290. <configuration>
  291. <username>admin</username>
  292. <password>password</password>
  293. </configuration>
  294. </execution>
  295. </executions>
  296. </plugin>
  297. </plugins>
  298. </build>
  299. </profile>
  300. </profiles>
  301.  
  302. </project>
  303.  
  304. <?xml version="1.0" encoding="utf-8"?>
  305. <!DOCTYPE hibernate-mapping PUBLIC
  306. "-//Hibernate/Hibernate Mapping DTD//EN"
  307. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  308.  
  309. <hibernate-mapping>
  310. <class name="com.goodotcom.cvgest.model.Person" table="person">
  311. <meta attribute="class-description">
  312. This class contains the person detail.
  313. </meta>
  314. <id name="id" type="int" column="id">
  315. <generator class="native"/>
  316. </id>
  317. <set name="skills" cascade="save-update" table="person_has_skill">
  318. <key column="person_id"/>
  319. <many-to-many column="skill_id" class="com.goodotcom.cvgest.model.Skill"/>
  320. </set>
  321.  
  322. <property name="cf" column="cf" type="string"/>
  323. <property name="name" column="name" type="string"/>
  324. <property name="surname" column="surname" type="string"/>
  325. <property name="email" column="email" type="string"/>
  326. <property name="tel" column="tel" type="string"/>
  327. <property name="pathCv" column="path_cv" type="string"/>
  328. </class>
  329. </hibernate-mapping>
  330.  
  331. package com.goodotcom.cvgest.model;
  332.  
  333. import javax.persistence.Column;
  334. import javax.persistence.Entity;
  335. import javax.persistence.GeneratedValue;
  336. import javax.persistence.Id;
  337. import javax.persistence.Table;
  338. import java.util.Set;
  339.  
  340. @Entity
  341. @Table(name = "person")
  342. public class Person {
  343. @Id
  344. @Column(name = "id")
  345. @GeneratedValue
  346. private int id;
  347. @Column(name = "cf", unique = true, nullable = false, length = 100)
  348. private String cf;
  349. @Column(name = "name", unique = false, nullable = false, length = 100)
  350. private String name;
  351. @Column(name = "surname", unique = false, nullable = false, length = 100)
  352. private String surname;
  353. @Column(name = "email", unique = true, nullable = false, length = 100)
  354. private String email;
  355. @Column(name = "tel", unique = false, nullable = false, length = 100)
  356. private String tel;
  357. @Column(name = "path_cv", unique = true, nullable = false, length = 100)
  358. private String pathCv;
  359.  
  360. private Set<Skill> skills;
  361.  
  362. public Person(){}
  363.  
  364. public Person(int id, String cf, String name, String surname, String email, String tel, String pathCv) {
  365. this.id = id;
  366. this.cf = cf;
  367. this.name = name;
  368. this.surname = surname;
  369. this.email = email;
  370. this.tel = tel;
  371. this.pathCv = pathCv;
  372. }
  373.  
  374. public int getId() {
  375. return id;
  376. }
  377.  
  378. public void setId(int id) {
  379. this.id = id;
  380. }
  381.  
  382. public String getCf() {
  383. return cf;
  384. }
  385.  
  386. public void setCf(String cf) {
  387. this.cf = cf;
  388. }
  389.  
  390. public String getName() {
  391. return name;
  392. }
  393.  
  394. public void setName(String name) {
  395. this.name = name;
  396. }
  397.  
  398. public String getSurname() {
  399. return surname;
  400. }
  401.  
  402. public void setSurname(String surname) {
  403. this.surname = surname;
  404. }
  405.  
  406. public String getEmail() {
  407. return email;
  408. }
  409.  
  410. public void setEmail(String email) {
  411. this.email = email;
  412. }
  413.  
  414. public String getTel() {
  415. return tel;
  416. }
  417.  
  418. public void setTel(String tel) {
  419. this.tel = tel;
  420. }
  421.  
  422. public String getPathCv() {
  423. return pathCv;
  424. }
  425.  
  426. public void setPathCv(String pathCv) {
  427. this.pathCv = pathCv;
  428. }
  429.  
  430. public Set<Skill> getSkills() {
  431. return skills;
  432. }
  433.  
  434. public void setSkills(Set<Skill> skills) {
  435. this.skills = skills;
  436. }
  437. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement