Tidying up some mess and redundancy, adding request logging.

This commit is contained in:
Yvan 2025-01-25 19:50:35 +00:00
parent bb5d51b3c7
commit 1518f7597d
9 changed files with 38 additions and 54 deletions

View file

@ -2,12 +2,11 @@ package dev.activitypub.activitypubbot;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
/**
* Object bound to "springbot" prefix in {@link org.springframework.core.env.Environment}.
* Using the "springbot" prefix for our configuration values.
*/
@Configuration
@ConfigurationProperties(prefix = "springbot")
@ -23,8 +22,4 @@ public class APProperties {
*/
@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; }*/
}

View file

@ -1,49 +1,15 @@
package dev.activitypub.activitypubbot;
import java.util.Arrays;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
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.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
@EnableJpaAuditing
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) {
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);
}* /
};
} */
}

View file

@ -1,17 +1,15 @@
package dev.activitypub.activitypubbot;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import java.sql.Date;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import jakarta.persistence.Id;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.Instant;
/**
@ -23,12 +21,6 @@ import java.time.Instant;
@EntityListeners(AuditingEntityListener.class)
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
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;

View file

@ -9,6 +9,10 @@ import org.springframework.ui.Model;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
/**
* This handles requests relating to our bots (users) - so things like
* /@username and /users/username.
*/
@Controller
@Slf4j
public class BotController {

View file

@ -2,6 +2,9 @@ package dev.activitypub.activitypubbot;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* Database shenanigans...
*/
public interface BotRepo extends JpaRepository<Bot, Long> {
}

View file

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

View file

@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
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
@RequestMapping( headers = "accept=application/json" )

View file

@ -4,11 +4,9 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
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
@Slf4j

View file

@ -5,6 +5,7 @@ springbot.scheme=https
logging.file.name=logs/springbot.log
logging.file.path=logs
spring.output.ansi.enabled=ALWAYS
logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG
spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp