Skip to content

Instantly share code, notes, and snippets.

View dwelch2344's full-sized avatar

David Welch dwelch2344

View GitHub Profile
@dwelch2344
dwelch2344 / SpringDataRestConfig.java
Created August 27, 2015 17:07
Workaround to expose ids with SpringDataRest, if you can't extend RepositoryRestMvcConfiguration
@Slf4j
@Configuration
public class SpringDataRestConfig {
private static final String BASE_PACKAGE = "com.example.yourapp";
@Inject
private RepositoryRestConfiguration restConfig;
@Inject
@FeignClient(url = "${app.api.someService.baseUrl}")
public interface SomeFeign {
@RequestMapping(method = RequestMethod.POST, value = "/steps/",
produces = "application/json")
Step createStep(@RequestBody Step step);
@RequestMapping(method = RequestMethod.PUT, value = "/steps/{stepId}",
produces = "application/json")
Step updateStep(@RequestBody Step step, @PathVariable("stepId") Long stepId);
}
{
version:0,
id:26,
value:"bah",
name:"bahaha",
links:[
{
rel:"self",
href:"http://localhost:8078/api/twilio/steps/26{?projection}"
}
@dwelch2344
dwelch2344 / 1_note.md
Last active August 29, 2015 13:57
HATEOAS doesn't search base classes annotations. See 1_note.md

Notice AbstractResourceController has the actual lookup methods (all of which work). But when an AbstractAssembler implementation builds the links, we don't get the Controller's base URL appended (compare theoutput.json's self vs address ref)

@Component
public class Foo extends InstantiationAwareBeanPostProcessorAdapter implements BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry defRegistry) throws BeansException {
DefaultListableBeanFactory registry = (DefaultListableBeanFactory) defRegistry;
Map<String,JpaRepository> repos = registry.getBeansOfType(JpaRepository.class);
// Repos is always empty :(
Set<Class<?>> entities = new Reflections("com.example").getTypesAnnotatedWith(Entity.class);
for(Class<?> entity : entities){
@dwelch2344
dwelch2344 / Consumer.java
Created April 29, 2014 17:00
While reading a few great articles (http://www.intertech.com/Blog/spring-4-generic-qualifiers/ comes to mind) I noticed that Spring 4 supports injecting generic objects if their type is provided when defining @beans. I'm trying to figure out how I can do that when describing beans in a BeanDefinitionRegistryPostProcessor
public class Consumer{
// these work with qualifiers...
@Inject
private GenericService<User, Long> userService;
@Inject
private GenericService<Organization, Long> orgService;
}
@Configuration
public class SampleConfig<T> {
@Bean
public Service<T> service(){
return new Service<T>(repo());
}
@Bean
public Repository<T> repo(){
@dwelch2344
dwelch2344 / BatchRequestController.java
Last active August 29, 2015 14:03
An example of BatchController's request and responses.
@RestController
@RequestMapping("/$batch")
public class BatchRequestController {
@Inject
private List<RequestMappingHandlerMapping> mappings;
@Inject
private List<HandlerAdapter> handlerAdapters;
@dwelch2344
dwelch2344 / encrypt.sh
Last active August 29, 2015 14:06
OpenSSL RSA cert + private key encryption of files locally
# Generate our cert and key
openssl req -x509 -days 10000 -newkey rsa:2048 -keyout key.pem -out setup.crt -subj '/'
# Strip the password off the key
openssl rsa -in key.pem -out key.pem
# Encrypt our file
openssl smime -encrypt -aes256 -binary -outform PEM -in file.txt -out file.aes setup.crt
# Decrypt our file
openssl smime -decrypt -inform PEM -binary -in file.aes -inkey key.pem -out decrypted.txt
SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
CenturyLink7173 fe:f5:28:2b:7f:40 -83 9,-1 Y US WPA(PSK/TKIP,AES/TKIP) WPA2(PSK/TKIP,AES/TKIP)
Holms01 40:4a:03:df:d3:77 -88 3 N -- WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)