use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class JAXRSParameterNameProvider method getParameterNames.
@Override
public List<String> getParameterNames(final Method method) {
final List<Parameter> parameters = ResourceUtils.getParameters(method);
final List<String> parameterNames = new ArrayList<String>();
for (int i = 0; i < parameters.size(); ++i) {
final StringBuilder sb = new StringBuilder();
sb.append("arg" + i);
sb.append("(");
Parameter parameter = parameters.get(i);
if (parameter.getName() != null) {
sb.append(parameter.getType().toString());
sb.append("(\"" + parameter.getName() + "\")");
sb.append(" ");
}
sb.append(method.getParameterTypes()[i].getSimpleName());
sb.append(")");
parameterNames.add(sb.toString());
}
return parameterNames;
}
use of org.apache.cxf.jaxrs.model.Parameter 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();
}
}
use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class JAXRSServiceImpl method getServiceInfos.
public List<ServiceInfo> getServiceInfos() {
if (!createServiceModel) {
return Collections.emptyList();
}
// try to convert to WSDL-centric model so that CXF DataBindings can get initialized
// might become useful too if we support wsdl2
// make databindings to use databinding-specific information
// like @XmlRootElement for ex to select a namespace
this.put("org.apache.cxf.databinding.namespace", "true");
List<ServiceInfo> infos = new ArrayList<>();
for (ClassResourceInfo cri : classResourceInfos) {
ServiceInfo si = new ServiceInfo();
infos.add(si);
QName qname = JAXRSUtils.getClassQName(cri.getServiceClass());
si.setName(qname);
InterfaceInfo inf = new InterfaceInfo(si, qname);
si.setInterface(inf);
for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) {
Method m = ori.getMethodToInvoke();
QName oname = new QName(qname.getNamespaceURI(), m.getName());
OperationInfo oi = inf.addOperation(oname);
createMessagePartInfo(oi, m.getReturnType(), qname, m, false);
for (Parameter pm : ori.getParameters()) {
if (pm.getType() == ParameterType.REQUEST_BODY) {
createMessagePartInfo(oi, ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()], qname, m, true);
}
}
}
}
return infos;
}
Aggregations