Difference between url and uri bael 864 hariprasad (#1987)

* Commit URUURLJNDIFS added.

* URI URL REST commit.

* Revert "URI URL REST commit."

This reverts commit d9e26399be1f3a26d871cd0600036e3a4558cde2.

* Difference URI URL REST BAEL-864.

* Commit Difference URI URL REST #864, small changes.

* Difference URI URL REST project has been moved to spring-rest.

* BAEL-864. Deleted unused project and did one small change.
This commit is contained in:
hariprasad108 2017-06-04 21:39:21 +02:00 committed by maibin
parent 29e3437545
commit c17d19ff21
11 changed files with 291 additions and 4 deletions

View File

@ -47,9 +47,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.decimal4j</groupId> <groupId>org.decimal4j</groupId>
<artifactId>decimal4j</artifactId> <artifactId>decimal4j</artifactId>
<version>${decimal4j.version}</version> <version>${decimal4j.version}</version>
</dependency> </dependency>
<dependency> <dependency>
@ -177,6 +177,11 @@
<version>2.1.0.1</version> <version>2.1.0.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.sun.messaging.mq</groupId>
<artifactId>fscontext</artifactId>
<version>${fscontext.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -382,6 +387,7 @@
<unix4j.version>0.4</unix4j.version> <unix4j.version>0.4</unix4j.version>
<grep4j.version>1.8.7</grep4j.version> <grep4j.version>1.8.7</grep4j.version>
<lombok.version>1.16.12</lombok.version> <lombok.version>1.16.12</lombok.version>
<fscontext.version>4.6-b01</fscontext.version>
<!-- testing --> <!-- testing -->
<org.hamcrest.version>1.3</org.hamcrest.version> <org.hamcrest.version>1.3</org.hamcrest.version>

View File

@ -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<String, String> env = new Hashtable<String, String>();
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;
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1 @@
Test of JNDI on file.

View File

@ -0,0 +1,32 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung.springboot.rest</groupId>
<artifactId>difference-uri-url-rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -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;
}
}

View File

@ -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()));
}
}

View File

@ -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
}

View File

@ -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());
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}