Skip to content

Instantly share code, notes, and snippets.

View rponte's full-sized avatar
🏠
Working from home

Rafael Ponte rponte

🏠
Working from home
View GitHub Profile

Utilizando Link do JAX-RS 2.0 para HATEOAS

  1. Removida classe Link caseira dos projetos livraria e payfast.

  2. Na classe PagamentoResource do payfast, foi criado o método getTransitions que retorna um array de Link do JAX-RS com as transições possíveis, de acordo com o status do pagamento.

  3. O array de Link é utilizado no método links do ResponseBuilder do JAX-RS:

    Response.ok().entity(pagamento).links(links).build()
  4. Na classe ClienteRest da livraria, foi modificado o código dos métodos criarPagamento e confirmarPagamento para utilizar o Link do JAX-RS.

@gregoriokusowski
gregoriokusowski / Teste.java
Last active September 25, 2015 02:26
Abtract methods on java enums
public enum Operacao {
SOMA ("+") {
@Override
Integer executa(Integer a, Integer b) {
return a + b;
}
},
SUBTRACAO ("-") {
@Override
Integer executa(Integer a, Integer b) {
@asouza
asouza / ControllersMustBeRequestScope.java
Created September 16, 2015 14:51
Processor that converts all controllers in request scoped objects :). Just an example.
package br.com.casadocodigo.loja.infra.spring;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.stereotype.Controller;
@gabrielmldantas
gabrielmldantas / htmltopdf.java
Created August 28, 2015 13:28
Convert HTML to PDF using Java
public void convertHtmlToPdf(String html, OutputStream out) throws DocumentException {
Document doc = Jsoup.parse(html);
doc.outputSettings().escapeMode(EscapeMode.xhtml);
Element head = doc.head();
Element style = new Element(Tag.valueOf("style"), doc.baseUri());
style.text("img { -fs-fit-images-to-width: 100% }");
head.appendChild(style);
DefaultUserAgent userAgent = new DefaultUserAgent();
ITextRenderer renderer = new ITextRenderer(userAgent);
renderer.setDocument(DOMBuilder.jsoup2DOM(doc), doc.baseUri());
@alexandreaquiles
alexandreaquiles / CargaHorariaServidores.java
Created July 15, 2015 15:03
Versão alternativa do código do post "Manipulando arquivos com recursos do Java 8" do blog da Caelum com sugestões do http://github.com/csokol. Veja em: http://blog.caelum.com.br/manipulando-arquivos-com-recursos-do-java-8/
package cargaHorariaDosServidores;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.TreeMap;
import java.util.function.Function;
import java.util.function.Predicate;
@peczenyj
peczenyj / input.txt
Last active August 29, 2015 14:09
remover bloco para fim de arquivo.
lala
begin
sddasdas
asdasdasd
asdasd
end
lolo
@joshlong
joshlong / Spring.java
Last active August 29, 2015 14:08
This demonstrates using Spring-native annotations and Spring's `@Qualifier`
package spring;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@joshlong
joshlong / Jsr330.java
Last active August 29, 2015 14:08
This demonstrates using JSR 330 annotations and JSR 330's `@Qualifier` (on Spring)
package jsr330;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import java.lang.annotation.ElementType;
package qualifiers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@joshlong
joshlong / Application.java
Last active October 26, 2022 16:28
Spring's `@Qualifier` is the best of both JSR 250's `@Resource` (which Spring also supports) and JSR 330's `@Inject` (which Spring also supports). You can think of it as a more flexible superset of the two. You can create type-local qualifer annotations as you would w/ JSR 330 or qualify things by bean ID. The Spring `@Qualifier` predates the JS…
package qualifiers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;