diff --git a/core-java/pom.xml b/core-java/pom.xml index 5c9bf06a57..1f4804e059 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -45,11 +45,11 @@ commons-math3 ${commons-math3.version} - + - org.decimal4j - decimal4j - ${decimal4j.version} + org.decimal4j + decimal4j + ${decimal4j.version} @@ -177,6 +177,11 @@ 2.1.0.1 + + com.sun.messaging.mq + fscontext + ${fscontext.version} + @@ -382,6 +387,7 @@ 0.4 1.8.7 1.16.12 + 4.6-b01 1.3 diff --git a/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java b/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java new file mode 100644 index 0000000000..d8d35d5363 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java @@ -0,0 +1,43 @@ +package com.baeldung.filesystem.jndi; + +import java.io.File; +import java.util.Hashtable; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +public class LookupFSJNDI { + InitialContext ctx = null; + + public LookupFSJNDI() throws NamingException { + super(); + init(); + } + + private void init() throws NamingException { + Hashtable env = new Hashtable(); + + env.put (Context.INITIAL_CONTEXT_FACTORY, + "com.sun.jndi.fscontext.RefFSContextFactory"); + // URI to namespace (actual directory) + env.put(Context.PROVIDER_URL, "file:./src/test/resources"); + + ctx = new InitialContext(env); + } + + public InitialContext getCtx() { + return ctx; + } + + public File getFile(String fileName) { + File file; + try { + file = (File)getCtx().lookup(fileName); + } catch (NamingException e) { + file = null; + } + return file; + } + +} diff --git a/core-java/src/test/java/com/baeldung/filesystem/jndi/test/LookupFSJNDITest.java b/core-java/src/test/java/com/baeldung/filesystem/jndi/test/LookupFSJNDITest.java new file mode 100644 index 0000000000..1f31cbade9 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/filesystem/jndi/test/LookupFSJNDITest.java @@ -0,0 +1,44 @@ +package com.baeldung.filesystem.jndi.test; + +import static org.junit.Assert.assertNotNull; + +import java.io.File; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.junit.Test; + +import com.baeldung.filesystem.jndi.LookupFSJNDI; + +public class LookupFSJNDITest { + LookupFSJNDI fsjndi; + File file; + InitialContext ctx = null; + final String FILENAME = "test.find"; + + public LookupFSJNDITest() { + try { + fsjndi = new LookupFSJNDI(); + } catch (NamingException e) { + fsjndi = null; + } + } + + @Test + public void whenInitializationLookupFSJNDIIsNotNull_thenSuccess() { + assertNotNull("Class LookupFSJNDI has instance", fsjndi); + } + + @Test + public void givenLookupFSJNDI_whengetInitialContextIsNotNull_thenSuccess() { + ctx = fsjndi.getCtx(); + assertNotNull("Context exists", ctx); + } + + @Test + public void givenInitialContext_whenLokupFileExists_thenSuccess() { + File file = fsjndi.getFile(FILENAME); + assertNotNull("File exists", file); + } +} diff --git a/core-java/src/test/resources/test.find b/core-java/src/test/resources/test.find new file mode 100644 index 0000000000..0cb7d51df1 --- /dev/null +++ b/core-java/src/test/resources/test.find @@ -0,0 +1 @@ +Test of JNDI on file. \ No newline at end of file diff --git a/spring-rest/difference-uri-url-rest/pom.xml b/spring-rest/difference-uri-url-rest/pom.xml new file mode 100644 index 0000000000..5ab6e63240 --- /dev/null +++ b/spring-rest/difference-uri-url-rest/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + org.baeldung.springboot.rest + difference-uri-url-rest + 0.0.1-SNAPSHOT + war + + + 1.8 + + + + org.springframework.boot + spring-boot-starter-parent + 1.5.2.RELEASE + + + + + + org.springframework.boot + spring-boot-starter-web + compile + + + org.springframework.boot + spring-boot-starter-test + test + + + + \ No newline at end of file diff --git a/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/Greeting.java b/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/Greeting.java new file mode 100644 index 0000000000..cc166587df --- /dev/null +++ b/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/Greeting.java @@ -0,0 +1,21 @@ +package com.baeldung.springboot.rest; + +public class Greeting { + private static final long serialVersionUID = 1L; + + private Integer id = null; + private String content = null; + + public Greeting(Integer id) { + this.id = id; + this.content = "Hello World"; + } + + public Integer getId() { + return id; + } + + public String getContent() { + return content; + } +} \ No newline at end of file diff --git a/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/GreetingController.java b/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/GreetingController.java new file mode 100644 index 0000000000..3fca9a1a76 --- /dev/null +++ b/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/GreetingController.java @@ -0,0 +1,21 @@ +package com.baeldung.springboot.rest; + +import java.util.concurrent.atomic.AtomicLong; + +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController("/") +@Component +public class GreetingController { + + private final AtomicLong counter = new AtomicLong(); + + @RequestMapping(value = "/greetings", method = RequestMethod.GET) + public Greeting greeting() { + + return new Greeting(new Integer((int) counter.incrementAndGet())); + } +} \ No newline at end of file diff --git a/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/SpringBootWebApplication.java b/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/SpringBootWebApplication.java new file mode 100644 index 0000000000..08d4c2c65e --- /dev/null +++ b/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/SpringBootWebApplication.java @@ -0,0 +1,27 @@ +package com.baeldung.springboot.rest; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.support.SpringBootServletInitializer; + +@EnableAutoConfiguration +@SpringBootApplication +public class SpringBootWebApplication extends SpringBootServletInitializer { + + // method for explicit deployment on Application Server + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SpringBootWebApplication.class); + } + + // run it as standalone JAVA application + public static void main(String[] args) throws Exception { + SpringApplication.run(SpringBootWebApplication.class, args); + } + + //Samples + // http://localhost:8080/greetings + // http://localhost:8989/difference-uri-url-rest/greetings +} \ No newline at end of file diff --git a/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/client/ApplicationClient.java b/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/client/ApplicationClient.java new file mode 100644 index 0000000000..2d92c890c5 --- /dev/null +++ b/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/client/ApplicationClient.java @@ -0,0 +1,27 @@ +package com.baeldung.springboot.rest.client; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.client.RestTemplate; + +public class ApplicationClient { + //private static final Logger log = LoggerFactory.getLogger(ApplicationClient.class); + final static String URI_STRING = "http://localhost:8080/difference-uri-url-rest/greetings"; + + + public ApplicationClient() { + super(); + } + + public Greeting init() { + RestTemplate restTemplate = new RestTemplate(); + Greeting greeting = restTemplate.getForObject(ApplicationClient.URI_STRING, Greeting.class); + //log.info(greeting.toString()); + return greeting; + } + public static void main(String args[]) { + Greeting greeting = new ApplicationClient().init(); + System.out.println(greeting.toString()); + } + +} diff --git a/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/client/Greeting.java b/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/client/Greeting.java new file mode 100644 index 0000000000..7d1119d155 --- /dev/null +++ b/spring-rest/difference-uri-url-rest/src/main/java/com/baeldung/springboot/rest/client/Greeting.java @@ -0,0 +1,33 @@ +package com.baeldung.springboot.rest.client; + +import java.io.Serializable; + +public class Greeting implements Serializable { + private static final long serialVersionUID = 1L; + + private Integer id = null; + private String content = null; + + /** Default constructor is mandatory for client */ + public Greeting() { + super(); + } + + public Greeting(Integer id) { + this.id = id; + this.content = "Hello World"; + } + + public Integer getId() { + return id; + } + + public String getContent() { + return content; + } + + @Override + public String toString() { + return "Id: " + getId().toString() + " Content: " + getContent(); + } +} \ No newline at end of file diff --git a/spring-rest/difference-uri-url-rest/src/test/java/com/baeldung/springboot/rest/test/DifferenceURIURLRESTTest.java b/spring-rest/difference-uri-url-rest/src/test/java/com/baeldung/springboot/rest/test/DifferenceURIURLRESTTest.java new file mode 100644 index 0000000000..4397f8e088 --- /dev/null +++ b/spring-rest/difference-uri-url-rest/src/test/java/com/baeldung/springboot/rest/test/DifferenceURIURLRESTTest.java @@ -0,0 +1,32 @@ +package com.baeldung.springboot.rest.test; + +import static org.junit.Assert.assertNotNull; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.web.client.RestTemplate; + +import com.baeldung.springboot.rest.client.Greeting; + +public class DifferenceURIURLRESTTest { + final static String URI_STRING = "http://localhost:8080/difference-uri-url-rest/greetings"; + static RestTemplate restTemplate; + Greeting greeting; + + @BeforeClass + public static void setupTest() { + restTemplate = new RestTemplate(); + } + + @Test + public void givenRestTenplate_whenIsNotNull_thenSuccess() { + assertNotNull("Rest Template not null", restTemplate); + } + + @Test + public void givenWiredConstructorParam_whenIsNotNull_thenSuccess() { + greeting = restTemplate.getForObject(URI_STRING, Greeting.class); + assertNotNull("Greeting class is not null", greeting); + } + +}