Tidying up some mess and redundancy, adding request logging.
This commit is contained in:
parent
bb5d51b3c7
commit
1518f7597d
9 changed files with 38 additions and 54 deletions
|
|
@ -2,12 +2,11 @@ package dev.activitypub.activitypubbot;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object bound to "springbot" prefix in {@link org.springframework.core.env.Environment}.
|
* Using the "springbot" prefix for our configuration values.
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConfigurationProperties(prefix = "springbot")
|
@ConfigurationProperties(prefix = "springbot")
|
||||||
|
|
@ -23,8 +22,4 @@ public class APProperties {
|
||||||
*/
|
*/
|
||||||
@Getter @Setter private String domain; // = "activitypub.bot";
|
@Getter @Setter private String domain; // = "activitypub.bot";
|
||||||
|
|
||||||
/*String getScheme() { return this.scheme; }
|
|
||||||
String getDomain() { return this.domain; }
|
|
||||||
void setScheme( String scheme ) { this.scheme = scheme; }
|
|
||||||
void setDomain( String domain ) { this.domain = domain; }*/
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,49 +1,15 @@
|
||||||
package dev.activitypub.activitypubbot;
|
package dev.activitypub.activitypubbot;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.springframework.boot.CommandLineRunner;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
|
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
||||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableJpaAuditing
|
@EnableJpaAuditing
|
||||||
public class ActivityPubBotApplication extends SpringBootServletInitializer {
|
public class ActivityPubBotApplication extends SpringBootServletInitializer {
|
||||||
|
|
||||||
//comment below if deploying outside web container -->
|
|
||||||
/*@Override
|
|
||||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
|
||||||
return builder.sources(ActivityPubBotApplication.class);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ActivityPubBotApplication.class);
|
SpringApplication.run(ActivityPubBotApplication.class);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(ActivityPubBotApplication.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
|
|
||||||
return args -> {
|
|
||||||
System.out.println("Beany McBeanface");
|
|
||||||
|
|
||||||
/* String[] beanNames = ctx.getBeanDefinitionNames();
|
|
||||||
Arrays.sort(beanNames);
|
|
||||||
for (String beanName : beanNames) {
|
|
||||||
System.out.println(beanName);
|
|
||||||
}* /
|
|
||||||
};
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
package dev.activitypub.activitypubbot;
|
package dev.activitypub.activitypubbot;
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import java.sql.Date;
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityListeners;
|
import jakarta.persistence.EntityListeners;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -23,12 +21,6 @@ import java.time.Instant;
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class Bot {
|
public class Bot {
|
||||||
|
|
||||||
// TODO: probably the wrong way to do this, and it isn't really compatible with 'Entity' anyway
|
|
||||||
//private APProperties props;
|
|
||||||
/*public Bot(APProperties props) {
|
|
||||||
this.props = props;
|
|
||||||
}*/
|
|
||||||
// non-data auto-generated primary key, this should never be exposed
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
@GeneratedValue(strategy=GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ import org.springframework.ui.Model;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This handles requests relating to our bots (users) - so things like
|
||||||
|
* /@username and /users/username.
|
||||||
|
*/
|
||||||
@Controller
|
@Controller
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BotController {
|
public class BotController {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ package dev.activitypub.activitypubbot;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database shenanigans...
|
||||||
|
*/
|
||||||
public interface BotRepo extends JpaRepository<Bot, Long> {
|
public interface BotRepo extends JpaRepository<Bot, Long> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package dev.activitypub.activitypubbot;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.filter.CommonsRequestLoggingFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ripped this off of the Internet somewhere to turn on some detailed
|
||||||
|
* request logging. It does the job! TODO: How to get/show remote IP?
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class ReqLogFilterConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CommonsRequestLoggingFilter logFilter() {
|
||||||
|
CommonsRequestLoggingFilter filter
|
||||||
|
= new CommonsRequestLoggingFilter();
|
||||||
|
filter.setIncludeQueryString(true);
|
||||||
|
filter.setIncludePayload(true);
|
||||||
|
filter.setMaxPayloadLength(10000);
|
||||||
|
filter.setIncludeHeaders(true);
|
||||||
|
filter.setAfterMessagePrefix("REQUEST DATA: ");
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Here we handle any JSON/REST requests.
|
* Here we handle any JSON/REST requests, which is how ActivityPub instances talk to each other.
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping( headers = "accept=application/json" )
|
@RequestMapping( headers = "accept=application/json" )
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,9 @@ import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Here we handle all non-JSON/REST requests - i.e. the normal "web" view
|
* General web requst implementations
|
||||||
*/
|
*/
|
||||||
@Controller
|
@Controller
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ springbot.scheme=https
|
||||||
logging.file.name=logs/springbot.log
|
logging.file.name=logs/springbot.log
|
||||||
logging.file.path=logs
|
logging.file.path=logs
|
||||||
spring.output.ansi.enabled=ALWAYS
|
spring.output.ansi.enabled=ALWAYS
|
||||||
|
logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG
|
||||||
|
|
||||||
spring.mvc.view.prefix: /WEB-INF/views/
|
spring.mvc.view.prefix: /WEB-INF/views/
|
||||||
spring.mvc.view.suffix: .jsp
|
spring.mvc.view.suffix: .jsp
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue