https://github.com/Graylog2/graylog2-server/blob/master/graylog2-server/src/main/java/org/graylog2/rest/resources/messages/MessageResource.java
代码实现代码
请求路径不能与原有的API接口重复,否则报以下异常
A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by“@Consumes” and “@Produces” annotations
package org.graylog2.plugin.custom.resource;
import com.codahale.metrics.annotation.Timed;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.graylog2.plugin.custom.service.TestService;
import org.graylog2.plugin.rest.PluginRestResource;
import org.graylog2.rest.resources.system.inputs.AbstractInputsResource;
import org.graylog2.shared.inputs.InputDescription;
import org.graylog2.shared.inputs.MessageInputFactory;
import org.graylog2.shared.rest.resources.RestResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.Map;
import java.util.UUID;
@Api(value = "Test", description = "Test integrations by Mr Wang")
@Path("/wbx")
public class TestResource extends RestResource {
private static final Logger LOG = LoggerFactory.getLogger(TestResource.class);
@GET
@Path("/uuid")
@Timed
@ApiOperation(value = "Get a Test UUID.")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Specified index does not exist."),
@ApiResponse(code = 404, message = "UUID does not exist.")
})
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
public String search(){
return UUID.randomUUID().toString();
}
}
注册自定义接口
public class CustomModule extends PluginModule {
private void configureUniversalBindings() {
addSystemRestResource(TestResource.class);
}
@Override
protected void configure() {
configureUniversalBindings();
}
private void addMessageProcessorFunction(String name, Class<? extends Function<?>> functionClass) {
addMessageProcessorFunction(binder(), name, functionClass);
}
private MapBinder<String, Function<?>> processorFunctionBinder(Binder binder) {
return MapBinder.newMapBinder(binder, TypeLiteral.get(String.class), new TypeLiteral<Function<?>>() {});
}
private void addMessageProcessorFunction(Binder binder, String name, Class<? extends Function<?>> functionClass) {
processorFunctionBinder(binder).addBinding(name).to(functionClass);
}
}
效果图
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)