security and rest work
This commit is contained in:
parent
66f6623c28
commit
279ccd2a55
|
@ -42,7 +42,7 @@ org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
|
|||
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||
|
|
|
@ -88,6 +88,14 @@
|
|||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- util -->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>14.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package org.baeldung.persistence.service;
|
||||
|
||||
import org.baeldung.web.dto.Foo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class FooService {
|
||||
|
||||
public FooService() {
|
||||
super();
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public Foo getById(final Long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Long create(final Foo resource) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.baeldung.spring.config;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("org.baeldung.persistence")
|
||||
public class PersistenceConfig {
|
||||
|
||||
public PersistenceConfig() {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,50 @@
|
|||
package org.baeldung.web.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.baeldung.persistence.service.FooService;
|
||||
import org.baeldung.web.dto.Foo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
@Controller
|
||||
public class FooController {
|
||||
//
|
||||
|
||||
@Autowired
|
||||
private FooService service;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
// API
|
||||
|
||||
@RequestMapping(value = "admin/foo/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Foo get(@PathVariable("id") final Long id, final HttpServletRequest request, final HttpServletResponse response) {
|
||||
final Foo resourceById = Preconditions.checkNotNull(service.getById(id));
|
||||
|
||||
eventPublisher.publishEvent(new SingleResourceRetrieved(this, request, response));
|
||||
return resourceById;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "admin/foo", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public void create(@RequestBody final Foo resource, final HttpServletRequest request, final HttpServletResponse response) {
|
||||
Preconditions.checkNotNull(resource);
|
||||
final Long idOfCreatedResource = service.create(resource);
|
||||
|
||||
eventPublisher.publishEvent(new ResourceCreated(this, request, response, idOfCreatedResource));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package org.baeldung.web.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
public class ResourceCreated extends ApplicationEvent {
|
||||
private final HttpServletResponse response;
|
||||
private final HttpServletRequest request;
|
||||
private final long idOfCreatedResource;
|
||||
|
||||
public ResourceCreated(final Object source, final HttpServletRequest request, final HttpServletResponse response, final long idOfCreatedResource) {
|
||||
super(source);
|
||||
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.idOfCreatedResource = idOfCreatedResource;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public HttpServletResponse getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public HttpServletRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public long getIdOfCreatedResource() {
|
||||
return idOfCreatedResource;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.baeldung.web.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
public class SingleResourceRetrieved extends ApplicationEvent {
|
||||
private final HttpServletResponse response;
|
||||
private final HttpServletRequest request;
|
||||
|
||||
public SingleResourceRetrieved(final Object source, final HttpServletRequest request, final HttpServletResponse response) {
|
||||
super(source);
|
||||
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public HttpServletResponse getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public HttpServletRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue