BAEL-553 - Intro to Spring Remoting with HTTP Invokers (#998)
* First test with log4j rolling appenders * small fix * Log4j rolling appender * First set up with rolling file on log4j 2 * Added logback code. * log4j2 more detailed example * log4j2 more detailed example * Improved names and examples * Fixed configurations * improved configs * formatted * Final fix * fixed formatting * Formatting fix * Fix sample apps to avoid try / catch * Fix request to replace files * Fix end lines * Log4j2 logger is shot down at the end. * Initial commit, the server starts launched from maven * made room for client and server projects * made room for client and server projects * base example works * poms restructured * packages restructured * packages restructured * Some renaming and a proper formatting string * Small renamings * Small renamings * Fixed invoked URL in client through fixing bean name * java.time.* instead of java.util.Date * java.time.* instead of java.util.Date * Removed log on file, kepts log on console * Updated Spring and Logback version to latest release. * Exception removed from run()
This commit is contained in:
parent
5cc5d7dc12
commit
5c99b291d5
@ -13,8 +13,8 @@
|
|||||||
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
|
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
|
||||||
|
|
||||||
<servlet.version>3.1.0</servlet.version>
|
<servlet.version>3.1.0</servlet.version>
|
||||||
<logback.version>1.1.7</logback.version>
|
<logback.version>1.1.8</logback.version>
|
||||||
<spring.version>4.2.4.RELEASE</spring.version>
|
<spring.version>4.3.5.RELEASE</spring.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package com.baeldung.api;
|
package com.baeldung.api;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
public class Booking implements Serializable {
|
public class Booking implements Serializable {
|
||||||
|
|
||||||
private int costInCent;
|
private int costInCent;
|
||||||
private int etaInSeconds;
|
private int etaInSeconds;
|
||||||
private String bookingCode;
|
private String bookingCode;
|
||||||
private Date pickUptime;
|
private LocalDateTime pickUptime;
|
||||||
private Address pickUpAddress;
|
private Address pickUpAddress;
|
||||||
private Address dropOffAddress;
|
private Address dropOffAddress;
|
||||||
|
|
||||||
public Booking(Address pickUpAddress, Date pickUptime, Address dropOffAddress, int costInCent, int etaInSeconds, String bookingCode) {
|
public Booking(Address pickUpAddress, LocalDateTime pickUptime, Address dropOffAddress, int costInCent, int etaInSeconds, String bookingCode) {
|
||||||
this.costInCent = costInCent;
|
this.costInCent = costInCent;
|
||||||
this.etaInSeconds = etaInSeconds;
|
this.etaInSeconds = etaInSeconds;
|
||||||
this.bookingCode = bookingCode;
|
this.bookingCode = bookingCode;
|
||||||
@ -33,7 +33,7 @@ public class Booking implements Serializable {
|
|||||||
return bookingCode;
|
return bookingCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getPickUptime() {
|
public LocalDateTime getPickUptime() {
|
||||||
return pickUptime;
|
return pickUptime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,12 +42,11 @@ public class Booking implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public String toString() {
|
@Override public String toString() {
|
||||||
return String.format("Booking: pick up @ %tr in %s, drop down in %s after %d minutes, %.2f $.", pickUptime, pickUpAddress, dropOffAddress, etaInSeconds/60, costInCent/100.0);
|
return String.format("Booking: pick up @ %tr in %s, drop down in %s after %d minutes, %.2f $.", pickUptime, pickUpAddress, dropOffAddress, etaInSeconds / 60, costInCent / 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
System.out.println(
|
System.out.println(new Booking(new Address("a", "b"),
|
||||||
new Booking(new Address("a", "b"), new Date(), new Address("c", "d"), 123_00, 600, "abc")
|
LocalDateTime.now(), new Address("c", "d"), 123_00, 600, "abc"));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,15 +10,11 @@ public class CabBookingClient {
|
|||||||
this.cabService = cabService;
|
this.cabService = cabService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() throws BookingException {
|
||||||
|
|
||||||
Address pickUp = new Address("13 Seagate Blvd, Key Largo, FL 33037", "US");
|
Address pickUp = new Address("13 Seagate Blvd, Key Largo, FL 33037", "US");
|
||||||
Address dropDown = new Address("91831 Overseas Hwy, Tavernier, FL 33070", "US");
|
Address dropDown = new Address("91831 Overseas Hwy, Tavernier, FL 33070", "US");
|
||||||
try {
|
System.out.println( cabService.bookPickUp(pickUp, dropDown, 3) );
|
||||||
System.out.println( cabService.bookPickUp(pickUp, dropDown, 3) );
|
|
||||||
} catch (BookingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class Main {
|
|||||||
return new CabBookingClient(service);
|
return new CabBookingClient(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws Exception {
|
||||||
AnnotationConfigApplicationContext rootContext =
|
AnnotationConfigApplicationContext rootContext =
|
||||||
new AnnotationConfigApplicationContext();
|
new AnnotationConfigApplicationContext();
|
||||||
rootContext.scan(Main.class.getPackage().getName());
|
rootContext.scan(Main.class.getPackage().getName());
|
||||||
|
@ -5,22 +5,23 @@ import com.baeldung.api.Booking;
|
|||||||
import com.baeldung.api.BookingException;
|
import com.baeldung.api.BookingException;
|
||||||
import com.baeldung.api.CabBookingService;
|
import com.baeldung.api.CabBookingService;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
import static java.lang.Math.random;
|
import static java.lang.Math.random;
|
||||||
import static java.lang.System.currentTimeMillis;
|
import static java.time.LocalDateTime.now;
|
||||||
|
import static java.time.temporal.ChronoUnit.MINUTES;
|
||||||
import static java.util.UUID.randomUUID;
|
import static java.util.UUID.randomUUID;
|
||||||
|
|
||||||
public class CabBookingServiceImpl implements CabBookingService {
|
public class CabBookingServiceImpl implements CabBookingService {
|
||||||
|
|
||||||
@Override public Booking bookPickUp(Address pickUpLocation, Address dropOffLocation, int pax) throws BookingException {
|
@Override public Booking bookPickUp(Address pickUpLocation, Address dropOffLocation, int pax) throws BookingException {
|
||||||
if(random()<0.3){
|
if (random() < 0.3) {
|
||||||
throw new BookingException("Cab unavailable");
|
throw new BookingException("Cab unavailable");
|
||||||
}
|
}
|
||||||
int tripTimeInMinutes = (int) (5 + random() * 15);
|
int tripTimeInMinutes = (int) (5 + random() * 15);
|
||||||
int costInCent = 15_00 + tripTimeInMinutes * 5 * pax;
|
int costInCent = 15_00 + tripTimeInMinutes * 5 * pax;
|
||||||
Date pickUpDate = new Date((long) (currentTimeMillis() + (1000 * 60 * random() * 15)));
|
LocalDateTime pickUpDate = now().plus(15L * (long) (random() * 10), MINUTES);
|
||||||
return new Booking(pickUpLocation, pickUpDate, dropOffLocation, costInCent, tripTimeInMinutes * 60,
|
|
||||||
randomUUID().toString());
|
return new Booking(pickUpLocation, pickUpDate, dropOffLocation, costInCent, tripTimeInMinutes * 60, randomUUID().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,23 +5,12 @@
|
|||||||
value="%-30(%d{MMM dd YYYY HH:mm:ss.SSS} [%thread]) %-5level %logger{5} [%file:%line] - %msg%n"/>
|
value="%-30(%d{MMM dd YYYY HH:mm:ss.SSS} [%thread]) %-5level %logger{5} [%file:%line] - %msg%n"/>
|
||||||
|
|
||||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<!-- encoders are assigned the type
|
|
||||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>${logPattern}</pattern>
|
<pattern>${logPattern}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
|
||||||
<file>C:\Users\danidemi\tmp\baledung\app.log</file>
|
|
||||||
<append>false</append>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${logPattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<root level="DEBUG">
|
<root level="DEBUG">
|
||||||
<appender-ref ref="STDOUT"/>
|
<appender-ref ref="STDOUT"/>
|
||||||
<appender-ref ref="FILE"/>
|
|
||||||
</root>
|
</root>
|
||||||
</configuration>
|
</configuration>
|
Loading…
x
Reference in New Issue
Block a user