Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
@@ -0,0 +1,21 @@
package com.baeldung.flips;
import org.flips.describe.config.FlipWebContextConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.Import;
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class })
@Import(FlipWebContextConfiguration.class)
public class ApplicationConfig {
public static void main(String[] args) {
SpringApplication.run(ApplicationConfig.class, args);
}
}
@@ -0,0 +1,65 @@
package com.baeldung.flips.controller;
import com.baeldung.flips.model.Foo;
import com.baeldung.flips.service.FlipService;
import org.flips.annotation.FlipOnDateTime;
import org.flips.annotation.FlipOnDaysOfWeek;
import org.flips.annotation.FlipOnEnvironmentProperty;
import org.flips.annotation.FlipOnProfiles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.time.DayOfWeek;
import java.util.List;
@RestController
public class FlipController {
private FlipService flipService;
@Autowired
public FlipController(FlipService flipService) {
this.flipService = flipService;
}
@RequestMapping(value = "/foos", method = RequestMethod.GET)
@FlipOnProfiles(activeProfiles = "dev")
public List<Foo> getAllFoos() {
return flipService.getAllFoos();
}
@RequestMapping(value = "/foo/{id}", method = RequestMethod.GET)
@FlipOnDaysOfWeek(daysOfWeek = {
DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY,
DayOfWeek.FRIDAY, DayOfWeek.SATURDAY, DayOfWeek.SUNDAY
})
public Foo getFooByNewId(@PathVariable int id) {
return flipService.getFooById(id).orElse(new Foo("Not Found", -1));
}
@RequestMapping(value = "/foo/last", method = RequestMethod.GET)
@FlipOnDateTime(cutoffDateTimeProperty = "last.active.after")
public Foo getLastFoo() {
return flipService.getLastFoo();
}
@RequestMapping(value = "/foo/first", method = RequestMethod.GET)
@FlipOnDateTime(cutoffDateTimeProperty = "first.active.after")
public Foo getFirstFoo() {
return flipService.getLastFoo();
}
@RequestMapping(value = "/foos/{id}", method = RequestMethod.GET)
@FlipOnEnvironmentProperty(property = "feature.foo.by.id", expectedValue = "Y")
public Foo getFooById(@PathVariable int id) {
return flipService.getFooById(id).orElse(new Foo("Not Found", -1));
}
@RequestMapping(value = "/foo/new", method = RequestMethod.GET)
public Foo getNewThing() {
return flipService.getNewFoo();
}
}
@@ -0,0 +1,12 @@
package com.baeldung.flips.model;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor
public class Foo {
@NonNull private final String name;
@NonNull private final int id;
}
@@ -0,0 +1,50 @@
package com.baeldung.flips.service;
import com.baeldung.flips.model.Foo;
import org.flips.annotation.FlipBean;
import org.flips.annotation.FlipOnSpringExpression;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Service
public class FlipService {
private final List<Foo> foos;
public FlipService() {
foos = new ArrayList<>();
foos.add(new Foo("Foo1", 1));
foos.add(new Foo("Foo2", 2));
foos.add(new Foo("Foo3", 3));
foos.add(new Foo("Foo4", 4));
foos.add(new Foo("Foo5", 5));
foos.add(new Foo("Foo6", 6));
}
public List<Foo> getAllFoos() {
return foos;
}
public Optional<Foo> getFooById(int id) {
return foos.stream().filter(foo -> (foo.getId() == id)).findFirst();
}
@FlipBean(with = NewFlipService.class)
@FlipOnSpringExpression(expression = "(2 + 2) == 4")
public Foo getNewFoo() {
return new Foo("New Foo!", 99);
}
public Foo getLastFoo() {
return foos.get(foos.size() - 1);
}
public Foo getFirstFoo() {
return foos.get(0);
}
}
@@ -0,0 +1,13 @@
package com.baeldung.flips.service;
import com.baeldung.flips.model.Foo;
import org.springframework.stereotype.Service;
@Service
public class NewFlipService {
public Foo getNewFoo() {
return new Foo("Shiny New Foo!", 100);
}
}
@@ -0,0 +1,27 @@
package com.baeldung.jsonp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.PropertySource;
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class })
@PropertySource("classpath:jsonp-application.properties")
public class JsonPApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(JsonPApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(JsonPApplication.class, args);
}
}
@@ -0,0 +1,38 @@
package com.baeldung.jsonp.model;
public class Company {
private long id;
private String name;
public Company() {
super();
}
public Company(final long id, final String name) {
this.id = id;
this.name = name;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(final long id) {
this.id = id;
}
@Override
public String toString() {
return "Company [id=" + id + ", name=" + name + "]";
}
}
@@ -0,0 +1,27 @@
package com.baeldung.jsonp.web.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baeldung.jsonp.model.Company;
@Controller
public class CompanyController {
@RequestMapping(value = "/companyResponseBody", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Company getCompanyResponseBody() {
final Company company = new Company(2, "ABC");
return company;
}
@RequestMapping(value = "/companyResponseEntity", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Company> getCompanyResponseEntity() {
final Company company = new Company(3, "123");
return new ResponseEntity<Company>(company, HttpStatus.OK);
}
}
@@ -0,0 +1,13 @@
package com.baeldung.jsonp.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping()
public String retrieveIndex() {
return "index";
}
}
@@ -0,0 +1,16 @@
package com.baeldung.jsonp.web.controller.advice;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice;
// AbstractJsonpResponseBodyAdvice was deprecated in favor of configuring CORS properly
// We still want to cover the usage of JSON-P in our articles, therefore we don't care that it was deprecated.
@SuppressWarnings("deprecation")
@ControllerAdvice
public class JsonpControllerAdvice extends AbstractJsonpResponseBodyAdvice {
public JsonpControllerAdvice() {
super("callback");
}
}
@@ -0,0 +1,14 @@
package org.baeldung.spring43.attributeannotations;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/test")
public class AttributeAnnotationsTestController {
@GetMapping
public String get(@SessionAttribute String login, @RequestAttribute String query) {
return String.format("login = %s, query = %s", login, query);
}
}
@@ -0,0 +1,17 @@
package org.baeldung.spring43.attributeannotations;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class ParamInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
request.getSession().setAttribute("login", "john");
request.setAttribute("query", "invoices");
return super.preHandle(request, response, handler);
}
}
@@ -0,0 +1,28 @@
package org.baeldung.spring43.cache;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Foo {
private static final Logger log = LoggerFactory.getLogger(Foo.class);
private static final AtomicInteger instanceCount = new AtomicInteger(0);
private final int instanceNum;
public Foo() {
instanceNum = instanceCount.incrementAndGet();
}
public static int getInstanceCount() {
return instanceCount.get();
}
public void printInstanceNumber() {
log.info("Foo instance number: {}", instanceNum);
}
}
@@ -0,0 +1,14 @@
package org.baeldung.spring43.cache;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@Service
public class FooService {
@Cacheable(cacheNames = "foos", sync = true)
public Foo getFoo(String id) {
return new Foo();
}
}
@@ -0,0 +1,5 @@
package org.baeldung.spring43.composedmapping;
public class Appointment {
}
@@ -0,0 +1,9 @@
package org.baeldung.spring43.composedmapping;
import java.util.Map;
public interface AppointmentService {
Map<String, Appointment> getAppointmentsForToday();
}
@@ -0,0 +1,31 @@
package org.baeldung.spring43.composedmapping;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.apache.logging.log4j.Logger;
@Controller
@RequestMapping("/appointments")
public class AppointmentsController {
private AppointmentService appointmentService;
@Autowired
private Logger logger;
@Autowired
public AppointmentsController(AppointmentService appointmentService) {
this.appointmentService = appointmentService;
}
@GetMapping
public Map<String, Appointment> get() {
logger.info("Getting appointments...");
return appointmentService.getAppointmentsForToday();
}
}
@@ -0,0 +1,5 @@
package org.baeldung.spring43.ctor;
public class FooRepository {
}
@@ -0,0 +1,15 @@
package org.baeldung.spring43.ctor;
public class FooService {
private final FooRepository repository;
public FooService(FooRepository repository) {
this.repository = repository;
}
public FooRepository getRepository() {
return repository;
}
}
@@ -0,0 +1,18 @@
package org.baeldung.spring43.defaultmethods;
import java.time.LocalDate;
public class DateHolder implements IDateHolder {
private LocalDate localDate;
@Override
public LocalDate getLocalDate() {
return localDate;
}
@Override
public void setLocalDate(LocalDate localDate) {
this.localDate = localDate;
}
}
@@ -0,0 +1,16 @@
package org.baeldung.spring43.defaultmethods;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public interface IDateHolder {
LocalDate getLocalDate();
void setLocalDate(LocalDate localDate);
default void setStringDate(String stringDate) {
setLocalDate(LocalDate.parse(stringDate, DateTimeFormatter.ofPattern("dd.MM.yyyy")));
}
}
@@ -0,0 +1,8 @@
package org.baeldung.spring43.depresolution;
import org.springframework.stereotype.Repository;
@Repository
public class FooRepository {
}
@@ -0,0 +1,18 @@
package org.baeldung.spring43.depresolution;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Service;
@Service
public class FooService {
private final FooRepository repository;
public FooService(ObjectProvider<FooRepository> repositoryProvider) {
this.repository = repositoryProvider.getIfUnique();
}
public FooRepository getRepository() {
return repository;
}
}
@@ -0,0 +1,10 @@
package org.baeldung.spring43.scopeannotations;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.ApplicationScope;
@Component
@ApplicationScope
public class AppPreferences extends InstanceCountingService {
}
@@ -0,0 +1,15 @@
package org.baeldung.spring43.scopeannotations;
import java.util.concurrent.atomic.AtomicInteger;
public class InstanceCountingService {
private static final AtomicInteger instanceCount = new AtomicInteger(0);
private final int instanceNumber = instanceCount.incrementAndGet();
public int getInstanceNumber() {
return instanceNumber;
}
}
@@ -0,0 +1,10 @@
package org.baeldung.spring43.scopeannotations;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
@Component
@RequestScope
public class LoginAction extends InstanceCountingService {
}
@@ -0,0 +1,36 @@
package org.baeldung.spring43.scopeannotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/appointments")
public class ScopeTestController {
@Autowired
private LoginAction loginAction;
@Autowired
private UserPreferences userPreferences;
@Autowired
private AppPreferences appPreferences;
@GetMapping("/request")
public String getRequestNumber() {
return Integer.toString(loginAction.getInstanceNumber());
}
@GetMapping("/session")
public String getSessionNumber() {
return Integer.toString(userPreferences.getInstanceNumber());
}
@GetMapping("/application")
public String getApplicationNumber() {
return Integer.toString(appPreferences.getInstanceNumber());
}
}
@@ -0,0 +1,10 @@
package org.baeldung.spring43.scopeannotations;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.SessionScope;
@Component
@SessionScope
public class UserPreferences extends InstanceCountingService {
}