File tree Expand file tree Collapse file tree 6 files changed +166
-1
lines changed
java/com/netflix/hystrix/dashboard/eureka
test/com/netflix/hytrix/dashboard/eureka Expand file tree Collapse file tree 6 files changed +166
-1
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,12 @@ dependencies {
66 compile ' org.apache.httpcomponents:httpclient:4.2.1'
77 compile ' log4j:log4j:1.2.17'
88 compile ' org.slf4j:slf4j-log4j12:1.7.0'
9+ compile ' com.squareup.retrofit:retrofit:2.0.2'
10+ compile ' com.squareup.retrofit2:converter-simplexml:2.0.2'
11+ compile ' com.squareup.retrofit2:converter-jackson:2.0.2'
12+ testCompile ' junit:junit:4.12'
913}
1014
1115jettyRun {
12- httpPort = 7979
16+ httpPort = 7979
1317}
Original file line number Diff line number Diff line change 1+ package com .netflix .hystrix .dashboard .eureka ;
2+
3+ import com .netflix .hystrix .dashboard .eureka .pojos .Applications ;
4+
5+ import retrofit2 .Call ;
6+ import retrofit2 .http .GET ;
7+
8+ public interface EurekaService {
9+ @ GET ("v2/apps/" )
10+ Call <Applications > listApps ();
11+ }
Original file line number Diff line number Diff line change 1+ package com .netflix .hystrix .dashboard .eureka ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .List ;
5+
6+ import com .netflix .hystrix .dashboard .eureka .pojos .Application ;
7+ import com .netflix .hystrix .dashboard .eureka .pojos .Applications ;
8+
9+ import retrofit2 .Call ;
10+ import retrofit2 .Retrofit ;
11+ import retrofit2 .converter .simplexml .SimpleXmlConverterFactory ;
12+
13+ public class EurekaServiceInfo {
14+
15+ public Applications retrieveApps () {
16+ try {
17+ Retrofit retrofit = new Retrofit .
18+ Builder ().
19+ baseUrl ("http://127.0.0.1:8080/eureka/" ).
20+ addConverterFactory (SimpleXmlConverterFactory .create ()).
21+ build ();
22+
23+ EurekaService service = retrofit .create (EurekaService .class );
24+ Call <Applications > apps = service .listApps ();
25+ return apps .execute ().body ();
26+
27+ }catch (Exception e ){
28+ throw new RuntimeException (e );
29+ }
30+ }
31+
32+ public List <String > retrieveAllAplications (){
33+
34+ List <String > applications = new ArrayList <String >();
35+ Applications apps = retrieveApps ();
36+ if (apps ==null ) return applications ;
37+
38+ for (Application a : apps .getApplication ()){
39+ applications .add (a .getName ());
40+ }
41+ return applications ;
42+ }
43+
44+ }
Original file line number Diff line number Diff line change 1+ package com .netflix .hystrix .dashboard .eureka .pojos ;
2+
3+ import org .simpleframework .xml .Element ;
4+ import org .simpleframework .xml .Root ;
5+
6+ @ Root (strict = false )
7+ public class Application {
8+
9+ @ Element (required =false )
10+ private String name ;
11+
12+ public Application () {
13+ }
14+
15+ public String getName () {
16+ return name ;
17+ }
18+
19+ public void setName (String name ) {
20+ this .name = name ;
21+ }
22+
23+ @ Override
24+ public String toString () {
25+ return "Application [name=" + name + "]" ;
26+ }
27+
28+ }
Original file line number Diff line number Diff line change 1+ package com .netflix .hystrix .dashboard .eureka .pojos ;
2+
3+ import java .util .ArrayList ;
4+
5+ import org .simpleframework .xml .Element ;
6+ import org .simpleframework .xml .ElementList ;
7+ import org .simpleframework .xml .Root ;
8+
9+ @ Root (strict = false )
10+ public class Applications {
11+
12+ @ Element
13+ private String versions__delta ;
14+
15+ @ Element
16+ private String apps__hashcode ;
17+
18+ @ ElementList (inline =true )
19+ private ArrayList <Application > application ;
20+
21+ public Applications () {
22+ }
23+
24+ public String getVersions__delta () {
25+ return versions__delta ;
26+ }
27+
28+ public void setVersions__delta (String versions__delta ) {
29+ this .versions__delta = versions__delta ;
30+ }
31+
32+ public String getApps__hashcode () {
33+ return apps__hashcode ;
34+ }
35+
36+ public void setApps__hashcode (String apps__hashcode ) {
37+ this .apps__hashcode = apps__hashcode ;
38+ }
39+
40+ public ArrayList <Application > getApplication () {
41+ return application ;
42+ }
43+
44+ public void setApplication (ArrayList <Application > application ) {
45+ this .application = application ;
46+ }
47+
48+ @ Override
49+ public String toString () {
50+ return "Applications [versions__delta=" + versions__delta + ", apps__hashcode=" + apps__hashcode
51+ + ", application=" + application + "]" ;
52+ }
53+
54+ }
Original file line number Diff line number Diff line change 1+ package com .netflix .hytrix .dashboard .eureka ;
2+
3+ import org .junit .Assert ;
4+ import org .junit .Test ;
5+
6+ import com .netflix .hystrix .dashboard .eureka .EurekaServiceInfo ;
7+
8+ public class EurekaServiceInfoTest {
9+
10+ @ Test
11+ public void testRetrieveAppNames () {
12+ EurekaServiceInfo esi = new EurekaServiceInfo ();
13+ Assert .assertNotNull (esi );
14+ }
15+
16+ @ Test
17+ public void TestRetrieveAllAplications () {
18+ EurekaServiceInfo esi = new EurekaServiceInfo ();
19+ Object r = esi .retrieveAllAplications ();
20+ Assert .assertNotNull (r );
21+ System .out .println (r );
22+ }
23+
24+ }
You can’t perform that action at this time.
0 commit comments