Skip to content

Commit c17d19f

Browse files
hariprasad108maibin
authored andcommitted
Difference between url and uri bael 864 hariprasad (eugenp#1987)
* Commit URUURLJNDIFS added. * URI URL REST commit. * Revert "URI URL REST commit." This reverts commit d9e2639. * Difference URI URL REST BAEL-864. * Commit Difference URI URL REST eugenp#864, small changes. * Difference URI URL REST project has been moved to spring-rest. * BAEL-864. Deleted unused project and did one small change.
1 parent 29e3437 commit c17d19f

11 files changed

Lines changed: 291 additions & 4 deletions

File tree

core-java/pom.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
<artifactId>commons-math3</artifactId>
4646
<version>${commons-math3.version}</version>
4747
</dependency>
48-
48+
4949
<dependency>
50-
<groupId>org.decimal4j</groupId>
51-
<artifactId>decimal4j</artifactId>
52-
<version>${decimal4j.version}</version>
50+
<groupId>org.decimal4j</groupId>
51+
<artifactId>decimal4j</artifactId>
52+
<version>${decimal4j.version}</version>
5353
</dependency>
5454

5555
<dependency>
@@ -177,6 +177,11 @@
177177
<version>2.1.0.1</version>
178178
</dependency>
179179

180+
<dependency>
181+
<groupId>com.sun.messaging.mq</groupId>
182+
<artifactId>fscontext</artifactId>
183+
<version>${fscontext.version}</version>
184+
</dependency>
180185
</dependencies>
181186

182187
<build>
@@ -382,6 +387,7 @@
382387
<unix4j.version>0.4</unix4j.version>
383388
<grep4j.version>1.8.7</grep4j.version>
384389
<lombok.version>1.16.12</lombok.version>
390+
<fscontext.version>4.6-b01</fscontext.version>
385391

386392
<!-- testing -->
387393
<org.hamcrest.version>1.3</org.hamcrest.version>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.baeldung.filesystem.jndi;
2+
3+
import java.io.File;
4+
import java.util.Hashtable;
5+
6+
import javax.naming.Context;
7+
import javax.naming.InitialContext;
8+
import javax.naming.NamingException;
9+
10+
public class LookupFSJNDI {
11+
InitialContext ctx = null;
12+
13+
public LookupFSJNDI() throws NamingException {
14+
super();
15+
init();
16+
}
17+
18+
private void init() throws NamingException {
19+
Hashtable<String, String> env = new Hashtable<String, String>();
20+
21+
env.put (Context.INITIAL_CONTEXT_FACTORY,
22+
"com.sun.jndi.fscontext.RefFSContextFactory");
23+
// URI to namespace (actual directory)
24+
env.put(Context.PROVIDER_URL, "file:./src/test/resources");
25+
26+
ctx = new InitialContext(env);
27+
}
28+
29+
public InitialContext getCtx() {
30+
return ctx;
31+
}
32+
33+
public File getFile(String fileName) {
34+
File file;
35+
try {
36+
file = (File)getCtx().lookup(fileName);
37+
} catch (NamingException e) {
38+
file = null;
39+
}
40+
return file;
41+
}
42+
43+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.baeldung.filesystem.jndi.test;
2+
3+
import static org.junit.Assert.assertNotNull;
4+
5+
import java.io.File;
6+
7+
import javax.naming.InitialContext;
8+
import javax.naming.NamingException;
9+
10+
import org.junit.Test;
11+
12+
import com.baeldung.filesystem.jndi.LookupFSJNDI;
13+
14+
public class LookupFSJNDITest {
15+
LookupFSJNDI fsjndi;
16+
File file;
17+
InitialContext ctx = null;
18+
final String FILENAME = "test.find";
19+
20+
public LookupFSJNDITest() {
21+
try {
22+
fsjndi = new LookupFSJNDI();
23+
} catch (NamingException e) {
24+
fsjndi = null;
25+
}
26+
}
27+
28+
@Test
29+
public void whenInitializationLookupFSJNDIIsNotNull_thenSuccess() {
30+
assertNotNull("Class LookupFSJNDI has instance", fsjndi);
31+
}
32+
33+
@Test
34+
public void givenLookupFSJNDI_whengetInitialContextIsNotNull_thenSuccess() {
35+
ctx = fsjndi.getCtx();
36+
assertNotNull("Context exists", ctx);
37+
}
38+
39+
@Test
40+
public void givenInitialContext_whenLokupFileExists_thenSuccess() {
41+
File file = fsjndi.getFile(FILENAME);
42+
assertNotNull("File exists", file);
43+
}
44+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test of JNDI on file.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.baeldung.springboot.rest</groupId>
4+
<artifactId>difference-uri-url-rest</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<packaging>war</packaging>
7+
8+
<properties>
9+
<java.version>1.8</java.version>
10+
</properties>
11+
12+
<parent>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-parent</artifactId>
15+
<version>1.5.2.RELEASE</version>
16+
</parent>
17+
18+
<dependencies>
19+
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-web</artifactId>
23+
<scope>compile</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-test</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
31+
</dependencies>
32+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.springboot.rest;
2+
3+
public class Greeting {
4+
private static final long serialVersionUID = 1L;
5+
6+
private Integer id = null;
7+
private String content = null;
8+
9+
public Greeting(Integer id) {
10+
this.id = id;
11+
this.content = "Hello World";
12+
}
13+
14+
public Integer getId() {
15+
return id;
16+
}
17+
18+
public String getContent() {
19+
return content;
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.springboot.rest;
2+
3+
import java.util.concurrent.atomic.AtomicLong;
4+
5+
import org.springframework.stereotype.Component;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RequestMethod;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@RestController("/")
11+
@Component
12+
public class GreetingController {
13+
14+
private final AtomicLong counter = new AtomicLong();
15+
16+
@RequestMapping(value = "/greetings", method = RequestMethod.GET)
17+
public Greeting greeting() {
18+
19+
return new Greeting(new Integer((int) counter.incrementAndGet()));
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.springboot.rest;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.builder.SpringApplicationBuilder;
7+
import org.springframework.boot.web.support.SpringBootServletInitializer;
8+
9+
@EnableAutoConfiguration
10+
@SpringBootApplication
11+
public class SpringBootWebApplication extends SpringBootServletInitializer {
12+
13+
// method for explicit deployment on Application Server
14+
@Override
15+
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
16+
return application.sources(SpringBootWebApplication.class);
17+
}
18+
19+
// run it as standalone JAVA application
20+
public static void main(String[] args) throws Exception {
21+
SpringApplication.run(SpringBootWebApplication.class, args);
22+
}
23+
24+
//Samples
25+
// http://localhost:8080/greetings
26+
// http://localhost:8989/difference-uri-url-rest/greetings
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.springboot.rest.client;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.web.client.RestTemplate;
6+
7+
public class ApplicationClient {
8+
//private static final Logger log = LoggerFactory.getLogger(ApplicationClient.class);
9+
final static String URI_STRING = "http://localhost:8080/difference-uri-url-rest/greetings";
10+
11+
12+
public ApplicationClient() {
13+
super();
14+
}
15+
16+
public Greeting init() {
17+
RestTemplate restTemplate = new RestTemplate();
18+
Greeting greeting = restTemplate.getForObject(ApplicationClient.URI_STRING, Greeting.class);
19+
//log.info(greeting.toString());
20+
return greeting;
21+
}
22+
public static void main(String args[]) {
23+
Greeting greeting = new ApplicationClient().init();
24+
System.out.println(greeting.toString());
25+
}
26+
27+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.springboot.rest.client;
2+
3+
import java.io.Serializable;
4+
5+
public class Greeting implements Serializable {
6+
private static final long serialVersionUID = 1L;
7+
8+
private Integer id = null;
9+
private String content = null;
10+
11+
/** Default constructor is mandatory for client */
12+
public Greeting() {
13+
super();
14+
}
15+
16+
public Greeting(Integer id) {
17+
this.id = id;
18+
this.content = "Hello World";
19+
}
20+
21+
public Integer getId() {
22+
return id;
23+
}
24+
25+
public String getContent() {
26+
return content;
27+
}
28+
29+
@Override
30+
public String toString() {
31+
return "Id: " + getId().toString() + " Content: " + getContent();
32+
}
33+
}

0 commit comments

Comments
 (0)