本文整理汇总了Java中org.apache.camel.model.rest.RestDefinition类的典型用法代码示例。如果您正苦于以下问题:Java RestDefinition类的具体用法?Java RestDefinition怎么用?Java RestDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RestDefinition类属于org.apache.camel.model.rest包,在下文中一共展示了RestDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: toRestdefinition
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
private static RestDefinition toRestdefinition(RouteBuilder builder,
Method method,
HttpMethod httpMethod,
String restPath) {
RestDefinition answer = builder.rest();
String fromPath = restPath;
if (httpMethod == HttpMethod.GET) {
answer = answer.get(fromPath);
} else if (httpMethod == HttpMethod.POST) {
answer = answer.post(fromPath);
} else if (httpMethod == HttpMethod.PUT) {
answer = answer.put(fromPath);
} else if (httpMethod == HttpMethod.DELETE) {
answer = answer.delete(fromPath);
} else if (httpMethod == HttpMethod.PATCH) {
answer = answer.patch(fromPath);
} else {
throw new RuntimeException("method currently not supported in Rest Paths : " + httpMethod);
}
answer = setBodyType(answer, method);
return answer;
}
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:27,代码来源:RestHelper.java
示例2: getRestModelAsXml
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public String getRestModelAsXml(String camelContextName) throws Exception {
CamelContext context = this.getLocalCamelContext(camelContextName);
if (context == null) {
return null;
}
List<RestDefinition> rests = context.getRestDefinitions();
if (rests == null || rests.isEmpty()) {
return null;
}
// use a rests definition to dump the rests
RestsDefinition def = new RestsDefinition();
def.setRests(rests);
return ModelHelper.dumpModelAsXml(null, def);
}
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:AbstractLocalCamelController.java
示例3: testAddRestDefinitionsFromXml
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
public void testAddRestDefinitionsFromXml() throws Exception {
RestDefinition rest = loadRest("rest1.xml");
assertNotNull(rest);
assertEquals("foo", rest.getId());
assertEquals(0, context.getRestDefinitions().size());
context.getRestDefinitions().add(rest);
assertEquals(1, context.getRestDefinitions().size());
final List<RouteDefinition> routeDefinitions = rest.asRouteDefinition(context);
for (final RouteDefinition routeDefinition : routeDefinitions) {
context.addRouteDefinition(routeDefinition);
}
assertEquals(2, context.getRoutes().size());
assertTrue("Route should be started", context.getRouteStatus("route1").isStarted());
getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
template.sendBody("seda:get-say-hello-bar", "Hello World");
assertMockEndpointsSatisfied();
}
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:CamelContextAddRestDefinitionsFromXmlTest.java
示例4: testRestOptionsModel
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
public void testRestOptionsModel() throws Exception {
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
assertEquals("/say/hello", rest.getPath());
assertEquals(1, rest.getVerbs().size());
assertIsInstanceOf(OptionsVerbDefinition.class, rest.getVerbs().get(0));
Exchange out = template.request("seda:options-say-hello", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Me");
}
});
assertMockEndpointsSatisfied();
assertNotNull(out);
assertEquals(out.getOut().getHeader("Allow"), ALLOWS);
}
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:FromRestOptionsTest.java
示例5: testFromRestModel
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
public void testFromRestModel() throws Exception {
assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
assertEquals(1, context.getRestDefinitions().size());
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
assertEquals("/say/", rest.getPath());
assertEquals(3, rest.getVerbs().size());
assertEquals("/hello", rest.getVerbs().get(0).getUri());
assertEquals("/bye", rest.getVerbs().get(1).getUri());
assertEquals("/hi", rest.getVerbs().get(2).getUri());
ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
assertEquals("direct:hello", to.getUri());
to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getTo());
assertEquals("direct:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
getMockEndpoint("mock:update").expectedMessageCount(1);
template.sendBody("seda:post-say-hi", "I was here");
assertMockEndpointsSatisfied();
String out = template.requestBody("seda:get-say-hello", "Me", String.class);
assertEquals("Hello World", out);
String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
assertEquals("Bye World", out2);
}
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:FromRestUriPrefixTest.java
示例6: testFromRestModel
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
public void testFromRestModel() throws Exception {
super.testFromRestModel();
RestDefinition rest = context.getRestDefinitions().get(0);
assertEquals("hello", rest.getId());
assertEquals("Hello Service", rest.getDescriptionText());
assertEquals("get-say", rest.getVerbs().get(0).getId());
assertEquals("Says hello to you", rest.getVerbs().get(0).getDescriptionText());
RestDefinition rest2 = context.getRestDefinitions().get(1);
assertEquals("bye", rest2.getId());
assertEquals("Bye Service", rest2.getDescriptionText());
assertEquals("en", rest2.getDescription().getLang());
assertEquals("Says bye to you", rest2.getVerbs().get(0).getDescriptionText());
assertEquals("Updates the bye message", rest2.getVerbs().get(1).getDescriptionText());
}
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:FromRestIdAndDescriptionTest.java
示例7: testReaderRead
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
@Test
public void testReaderRead() throws Exception {
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
SwaggerConfig config = new SwaggerConfig();
config.setBasePath("http://localhost:8080/api");
RestSwaggerReader reader = new RestSwaggerReader();
Option<ApiListing> option = reader.read(rest, config);
assertNotNull(option);
ApiListing listing = option.get();
assertNotNull(listing);
String json = JsonSerializer.asJson(listing);
log.info(json);
assertTrue(json.contains("\"basePath\":\"http://localhost:8080/api\""));
assertTrue(json.contains("\"resourcePath\":\"/hello\""));
assertTrue(json.contains("\"method\":\"GET\""));
assertTrue(json.contains("\"nickname\":\"getHelloHi\""));
context.stop();
}
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:RestSwaggerReaderTest.java
示例8: testServlet
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
@Test
public void testServlet() throws Exception {
DefaultCamelSwaggerServlet servlet = new DefaultCamelSwaggerServlet();
Buffer<RestDefinition> list = servlet.getRestDefinitions(null);
assertEquals(1, list.size());
RestDefinition rest = list.iterator().next();
checkRestDefinition(rest);
// get the RestDefinition by using the camel context id
list = servlet.getRestDefinitions(context.getName());
assertEquals(1, list.size());
rest = list.iterator().next();
checkRestDefinition(rest);
RestDefinition rest2 = context.getRestDefinitions().get(0);
checkRestDefinition(rest2);
}
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:DefaultCamelSwaggerServletTest.java
示例9: testFromRestModel
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
@Test
public void testFromRestModel() throws Exception {
super.testFromRestModel();
RestDefinition rest = context.getRestDefinitions().get(0);
assertEquals("hello", rest.getId());
assertEquals("Hello Service", rest.getDescriptionText());
assertEquals("get-say", rest.getVerbs().get(0).getId());
assertEquals("Says hello to you", rest.getVerbs().get(0).getDescriptionText());
RestDefinition rest2 = context.getRestDefinitions().get(1);
assertEquals("bye", rest2.getId());
assertEquals("Bye Service", rest2.getDescriptionText());
assertEquals("en", rest2.getDescription().getLang());
assertEquals("Says bye to you", rest2.getVerbs().get(0).getDescriptionText());
assertEquals("Updates the bye message", rest2.getVerbs().get(1).getDescriptionText());
}
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:FromRestIdAndDescriptionTest.java
示例10: restContextBean
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
private SyntheticBean<?> restContextBean(RestContextDefinition definition, URL url) {
requireNonNull(definition.getId(),
() -> format("Missing [%s] attribute for imported bean [%s] from resource [%s]",
"id", "restContext", url));
return new SyntheticBean<>(manager,
new SyntheticAnnotated(List.class,
Stream.of(List.class, new ListParameterizedType(RestDefinition.class))
.collect(toSet()),
ANY, NamedLiteral.of(definition.getId())),
List.class,
new SyntheticInjectionTarget<>(definition::getRests), bean ->
"imported rest context with "
+ "id [" + definition.getId() + "] "
+ "from resource [" + url + "] "
+ "with qualifiers " + bean.getQualifiers());
}
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:XmlCdiBeanFactory.java
示例11: read
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
/**
* Read the REST-DSL definition's and parse that as a Swagger model representation
*
* @param rests the rest-dsl
* @param route optional route path to filter the rest-dsl to only include from the chose route
* @param config the swagger configuration
* @param classResolver class resolver to use
* @return the swagger model
*/
public Swagger read(List<RestDefinition> rests, String route, BeanConfig config, String camelContextId, ClassResolver classResolver) {
Swagger swagger = new Swagger();
for (RestDefinition rest : rests) {
if (ObjectHelper.isNotEmpty(route) && !route.equals("/")) {
// filter by route
if (!rest.getPath().equals(route)) {
continue;
}
}
parse(swagger, rest, camelContextId, classResolver);
}
// configure before returning
swagger = config.configure(swagger);
return swagger;
}
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:RestSwaggerReader.java
示例12: restContextBean
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
private SyntheticBean<?> restContextBean(RestContextDefinition definition, URL url) {
requireNonNull(definition.getId(),
() -> format("Missing [%s] attribute for imported bean [%s] from resource [%s]",
"id", "restContext", url));
return new SyntheticBean<>(manager,
new SyntheticAnnotated(List.class,
Stream.of(List.class, new UnaryParameterizedType(List.class, RestDefinition.class))
.collect(toSet()),
ANY, NamedLiteral.of(definition.getId())),
List.class,
new SyntheticInjectionTarget<>(definition::getRests),
bean -> "imported rest context with "
+ "id [" + definition.getId() + "] "
+ "from resource [" + url + "] "
+ "with qualifiers " + bean.getQualifiers());
}
开发者ID:astefanutti,项目名称:camel-cdi,代码行数:18,代码来源:XmlCdiBeanFactory.java
示例13: setBodyType
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
private static RestDefinition setBodyType(RestDefinition rd, Method method) {
//This route necessary for the RestBindings of camel
if (method.getParameters().length > 0) {
Class type = method.getParameters()[0].getType();
if (isMultipartBody(method)) {
rd.bindingMode(RestBindingMode.off);
rd.outType(method.getReturnType().getClass());
}
rd = rd.type(type);
}
return rd;
}
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:14,代码来源:RestHelper.java
示例14: endRest
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
/**
* Ends the current block and returns back to the {@link org.apache.camel.model.rest.RestDefinition rest()} DSL.
*
* @return the builder
*/
public RestDefinition endRest() {
ProcessorDefinition<?> def = this;
RouteDefinition route = ProcessorDefinitionHelper.getRoute(def);
if (route != null) {
return route.getRestDefinition();
}
throw new IllegalArgumentException("Cannot find RouteDefinition to allow endRest");
}
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:ProcessorDefinition.java
示例15: lookupRests
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
/**
* Lookup the rests from the {@link org.apache.camel.model.RestContextRefDefinition}.
* <p/>
* This implementation must be used to lookup the rests as it performs a deep clone of the rests
* as a {@link org.apache.camel.model.RestContextRefDefinition} can be re-used with multiple {@link org.apache.camel.model.ModelCamelContext} and each
* context should have their own instances of the routes. This is to ensure no side-effects and sharing
* of instances between the contexts. For example such as property placeholders may be context specific
* so the routes should not use placeholders from another {@link org.apache.camel.model.ModelCamelContext}.
*
* @param camelContext the CamelContext
* @param ref the id of the {@link org.apache.camel.model.RestContextRefDefinition} to lookup and get the routes.
* @return the rests.
*/
@SuppressWarnings("unchecked")
public static synchronized List<RestDefinition> lookupRests(ModelCamelContext camelContext, String ref) {
ObjectHelper.notNull(camelContext, "camelContext");
ObjectHelper.notNull(ref, "ref");
List<RestDefinition> answer = CamelContextHelper.lookup(camelContext, ref, List.class);
if (answer == null) {
throw new IllegalArgumentException("Cannot find RestContext with id " + ref);
}
// must clone the rest definitions as they can be reused with multiple CamelContexts
// and they would need their own instances of the definitions to not have side effects among
// the CamelContext - for example property placeholder resolutions etc.
List<RestDefinition> clones = new ArrayList<RestDefinition>(answer.size());
try {
JAXBContext jaxb = getOrCreateJAXBContext(camelContext);
for (RestDefinition def : answer) {
RestDefinition clone = cloneRestDefinition(jaxb, def);
if (clone != null) {
clones.add(clone);
}
}
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
return clones;
}
开发者ID:HydAu,项目名称:Camel,代码行数:42,代码来源:RestContextRefDefinitionHelper.java
示例16: addRestDefinitions
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
public void addRestDefinitions(Collection<RestDefinition> restDefinitions) throws Exception {
if (restDefinitions == null || restDefinitions.isEmpty()) {
return;
}
this.restDefinitions.addAll(restDefinitions);
}
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:DefaultCamelContext.java
示例17: rest
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
/**
* Creates a new REST service
*
* @return the builder
*/
public RestDefinition rest() {
getRestCollection().setCamelContext(getContext());
RestDefinition answer = getRestCollection().rest();
configureRest(answer);
return answer;
}
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:RouteBuilder.java
示例18: testParseSimpleRestXml
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
public void testParseSimpleRestXml() throws Exception {
RestDefinition rest = assertOneRest("simpleRest.xml");
assertEquals("/users", rest.getPath());
assertEquals(1, rest.getVerbs().size());
GetVerbDefinition get = (GetVerbDefinition) rest.getVerbs().get(0);
assertEquals("/view/{id}", get.getUri());
assertEquals("direct:getUser", get.getTo().getUri());
}
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:XmlRestParseTest.java
示例19: testParseSimpleRestXml
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
public void testParseSimpleRestXml() throws Exception {
RestDefinition rest = assertOneRest("simpleRestToD.xml");
assertEquals("/users", rest.getPath());
assertEquals(1, rest.getVerbs().size());
GetVerbDefinition get = (GetVerbDefinition) rest.getVerbs().get(0);
assertEquals("/view/{id}", get.getUri());
assertEquals("bean:getUser?id=${header.id}", get.getToD().getUri());
}
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:XmlRestParseToDTest.java
示例20: testLoadRestFromXml
import org.apache.camel.model.rest.RestDefinition; //导入依赖的package包/类
public void testLoadRestFromXml() throws Exception {
assertNotNull("Existing foo route should be there", context.getRoute("foo"));
assertEquals(2, context.getRoutes().size());
// test that existing route works
MockEndpoint foo = getMockEndpoint("mock:foo");
foo.expectedBodiesReceived("Hello World");
template.sendBody("direct:foo", "Hello World");
foo.assertIsSatisfied();
// load rest from XML and add them to the existing camel context
InputStream is = getClass().getResourceAsStream("barRest.xml");
RestsDefinition rests = context.loadRestsDefinition(is);
context.addRestDefinitions(rests.getRests());
for (final RestDefinition restDefinition : rests.getRests()) {
List<RouteDefinition> routeDefinitions = restDefinition.asRouteDefinition(context);
context.addRouteDefinitions(routeDefinitions);
}
assertNotNull("Loaded rest route should be there", context.getRoute("route1"));
assertEquals(3, context.getRoutes().size());
// test that loaded route works
MockEndpoint bar = getMockEndpoint("mock:bar");
bar.expectedBodiesReceived("Bye World");
template.sendBody("seda:get-say-hello-bar", "Bye World");
bar.assertIsSatisfied();
}
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:LoadRestFromXmlTest.java
注:本文中的org.apache.camel.model.rest.RestDefinition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论