use of org.apache.cxf.jaxrs.model.UserOperation in project cxf by apache.
the class ResourceUtils method getOperationFromElement.
private static UserOperation getOperationFromElement(Element e) {
UserOperation op = new UserOperation();
op.setName(e.getAttribute("name"));
op.setVerb(e.getAttribute("verb"));
op.setPath(e.getAttribute("path"));
op.setOneway(Boolean.parseBoolean(e.getAttribute("oneway")));
op.setConsumes(e.getAttribute("consumes"));
op.setProduces(e.getAttribute("produces"));
List<Element> paramEls = DOMUtils.findAllElementsByTagNameNS(e, "http://cxf.apache.org/jaxrs", "param");
List<Parameter> params = new ArrayList<>(paramEls.size());
for (int i = 0; i < paramEls.size(); i++) {
Element paramEl = paramEls.get(i);
Parameter p = new Parameter(paramEl.getAttribute("type"), i, paramEl.getAttribute("name"));
p.setEncoded(Boolean.valueOf(paramEl.getAttribute("encoded")));
p.setDefaultValue(paramEl.getAttribute("defaultValue"));
String pClass = paramEl.getAttribute("class");
if (!StringUtils.isEmpty(pClass)) {
try {
p.setJavaType(ClassLoaderUtils.loadClass(pClass, ResourceUtils.class));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
params.add(p);
}
op.setParameters(params);
return op;
}
use of org.apache.cxf.jaxrs.model.UserOperation in project cxf by apache.
the class AbstractSwagger2ServiceDescriptionTest method doTestApiListingIsProperlyReturnedJSON.
protected static void doTestApiListingIsProperlyReturnedJSON(final WebClient client, boolean useXForwarded) throws Exception {
if (useXForwarded) {
client.header("USE_XFORWARDED", true);
}
try {
String swaggerJson = client.get(String.class);
UserApplication ap = SwaggerParseUtils.getUserApplicationFromJson(swaggerJson);
assertNotNull(ap);
assertEquals(useXForwarded ? "/reverse" : "/", ap.getBasePath());
List<UserResource> urs = ap.getResources();
assertNotNull(urs);
assertEquals(1, urs.size());
UserResource r = urs.get(0);
String basePath = "";
if (!"/".equals(r.getPath())) {
basePath = r.getPath();
}
Map<String, UserOperation> map = r.getOperationsAsMap();
assertEquals(3, map.size());
UserOperation getBooksOp = map.get("getBooks");
assertEquals(HttpMethod.GET, getBooksOp.getVerb());
assertEquals("/bookstore", basePath + getBooksOp.getPath());
assertEquals(MediaType.APPLICATION_JSON, getBooksOp.getProduces());
List<Parameter> getBooksOpParams = getBooksOp.getParameters();
assertEquals(1, getBooksOpParams.size());
assertEquals(ParameterType.QUERY, getBooksOpParams.get(0).getType());
UserOperation getBookOp = map.get("getBook");
assertEquals(HttpMethod.GET, getBookOp.getVerb());
assertEquals("/bookstore/{id}", basePath + getBookOp.getPath());
assertEquals(MediaType.APPLICATION_JSON, getBookOp.getProduces());
List<Parameter> getBookOpParams = getBookOp.getParameters();
assertEquals(1, getBookOpParams.size());
assertEquals(ParameterType.PATH, getBookOpParams.get(0).getType());
UserOperation deleteOp = map.get("delete");
assertEquals(HttpMethod.DELETE, deleteOp.getVerb());
assertEquals("/bookstore/{id}", basePath + deleteOp.getPath());
List<Parameter> delOpParams = deleteOp.getParameters();
assertEquals(1, delOpParams.size());
assertEquals(ParameterType.PATH, delOpParams.get(0).getType());
assertThat(swaggerJson, CoreMatchers.containsString(CONTACT));
assertThat(swaggerJson, CoreMatchers.containsString(TITLE));
assertThat(swaggerJson, CoreMatchers.containsString(DESCRIPTION));
assertThat(swaggerJson, CoreMatchers.containsString(LICENSE));
assertThat(swaggerJson, CoreMatchers.containsString(LICENSE_URL));
assertThat(swaggerJson, CoreMatchers.containsString(SECURITY_DEFINITION_NAME));
} finally {
client.close();
}
}
Aggregations