File tree 3 files changed +63
-0
lines changed
3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .sample ;
2
+
3
+ import javax .ws .rs .core .Application ;
4
+ import javax .ws .rs .ApplicationPath ;
5
+ import java .util .Collections ;
6
+ import java .util .Set ;
7
+
8
+ @ ApplicationPath ("rest" )
9
+ public class App extends Application {
10
+ @ Override
11
+ public Set <Class <?>> getClasses (){
12
+ return Collections .singleton (SimpleRest .class );
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ package com .sample ;
2
+
3
+ import javax .servlet .ServletContextListener ;
4
+ import javax .servlet .ServletContextEvent ;
5
+ import javax .servlet .ServletContext ;
6
+ import javax .servlet .ServletRegistration ;
7
+ import static javax .servlet .ServletRegistration .Dynamic ;
8
+ import javax .servlet .annotation .WebListener ;
9
+
10
+ @ WebListener
11
+ public class Config implements ServletContextListener {
12
+ public void contextInitialized (ServletContextEvent sce ) {
13
+ ServletContext context = sce .getServletContext ();
14
+ Dynamic servlet = context .addServlet ("app" , org .glassfish .jersey .servlet .ServletContainer .class );
15
+ servlet .setLoadOnStartup (1 );
16
+ ServletRegistration registration = context .getServletRegistration ("app" );
17
+ registration .addMapping ("/jersey/*" );
18
+ }
19
+
20
+ public void contextDestroyed (ServletContextEvent sce ){}
21
+ }
Original file line number Diff line number Diff line change
1
+ package com .sample ;
2
+
3
+ import javax .ws .rs .GET ;
4
+ import javax .ws .rs .Path ;
5
+ import javax .ws .rs .Produces ;
6
+ import javax .ws .rs .core .MediaType ;
7
+
8
+ @ Path ("/simple" )
9
+ public class SimpleRest {
10
+
11
+ @ GET
12
+ @ Produces (MediaType .APPLICATION_JSON )
13
+ public Simple getSimple () {
14
+ return new Simple ("simple name" );
15
+ }
16
+
17
+ public static class Simple {
18
+ private String name ;
19
+
20
+ public Simple (String name ){
21
+ this .name = name ;
22
+ }
23
+
24
+ public String getName () {
25
+ return name ;
26
+ }
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments