I am using spring boot 2.1.6.RELEASE and swagger 2.9.2, everything is fine except that I want to simplify the content.
First, I want to remove the base URL under title:
[ Base URL: localhost:7777/ ]
http://localhost:7777/v2/api-docs
And, I want the API blocks and Models block to be opened on visiting, not until I click the name.
And, I want the select a spec list on the top banner to be removed or hidden.
I don't know if there is a way to do these with java API, I can't find any solution other place.
The picture I tried to upload:
Seems that I am not allowed uploading picture yet, don't blame me if the picture above is unavailable.
here i find a class helping to configure swagger UI:
springfox.documentation.swagger.web.UiConfiguration
and here is my usage:
#Bean
public UiConfiguration uiConfig() {
return UiConfigurationBuilder.builder()
.deepLinking(false)
.displayOperationId(false)
.defaultModelsExpandDepth(1)
.defaultModelExpandDepth(1)
.defaultModelRendering(ModelRendering.MODEL)
.displayRequestDuration(true)
.docExpansion(DocExpansion.LIST)
.filter(false)
.maxDisplayedTags(null)
.operationsSorter(OperationsSorter.METHOD)
.showExtensions(false)
.tagsSorter(TagsSorter.ALPHA)
.validatorUrl(null)
.build();
}
Related
We have a web application comprising a client in Angular2 and a server in Play Framework 2.6. This application should allow users to upload their own images. Similarly to many users here, we faced the problem of not being able to access the images in public/assets in production mode, and so we tried the solutions that have been provided to those users, with no success.
We created the following route in the conf/routes file:
GET /files/*file controllers.AdminExerciseCtrl.serve(file)
leading to the following custom action:
public Result serve(String file) {
Boolean DEVELOPMENT = Boolean.parseBoolean(ConfigFactory.load().getString("development"));
String path;
if(DEVELOPMENT) path = "public/";
else path = ConfigFactory.load().getString("root/");
return ok(new java.io.File(path + file));
}
i.e., we are saving the uploaded images to root/files/images.
We tried two way of accessing this route:
Using #routes throws an error because of the # character
Using the route in the src field (where resource.resourcePath is a variable holding the path to the image file, e.g., images/pic.jpg), the route simply isn't found (404).
<img *ngIf="resource" class="thumbnail" [src]="'/files/' + resource.resourcePath">
We are starting to despair since this project is considerably large and uploading images is a core feature. Any ideas of what we could be missing? Anything we should be doing in the client regarding the routes?
Thanks in advance.
I can see all the urls in jhipster are having #, how to remove it properly, I don't want to show # in my application's urls, I created application in angular 4
We do have this tip in our docs although I have never tried it myself :
https://jhipster.github.io/tips/010_tip_configuring_html_5_mode.html
The tip is only for angularjs 1. You can try to combine it's advice with the official angular docs on routing : https://angular.io/guide/router
If you manage to make it work please do a PR on our website : https://github.com/jhipster/jhipster.github.io
I spent many hours to achieve this and finally has paid off. You can follow these steps:
Remove on angular app avery use of hash location strategy in every RouterModule.forRoot...:
{useHash: false}
Go to java app to the config folder and create a new java class to manage the error pages to redirect to index.html:
#Configuration
public class ErrorPageConfig implements ErrorPageRegistrar {
#Override
public void registerErrorPages(ErrorPageRegistry registry) {
registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/index.html"));
}
}
This page was very helpful
https://www.baeldung.com/spring-cloud-angular
I'm attempting to do a reverse lookup on a route I've created.
The route is defined as such in my routes file:
POST /login controllers.Web.Application.authenticate
However, when I try to do a reverse on it in a form I made, I can't seem to find it. I'm attempting to do a reverse like this:
#helper.form(action = routes.login())) {
rest of the form here...
}
However, the login appears in red in intellij and when attempting to run the program, I get the following error:
play.sbt.PlayExceptions$CompilationException: Compilation error[value login is not a member of object controllers.routes]
I've attempted recompiling the project multiple times and looking around the docs, but it's just not working... Any ideas?
So, an interesting thing happened recently and I found a way to point to the original structure properly. To do so, rather than writing:
routes.Web.Application.authenticate()
As Tyler suggested, I was supposed to write:
Web.routes.Application.authenticate()
Which is totally counter-intuitive and all, but that allows me to use the original package structure.
Edit:
As we discovered in the comments, the reverse router doesn't seem to like sub packages. You should remove the Web part of your package, and move everything up a level, then change the code to be this:
#helper.form(action = routes.Application.authenticate())) {
rest of the form here...
}
Original answer:
You need to refer to the controller function, and not the name of the route, so it should look something like this:
#helper.form(action = routes.Web.Application.authenticate())) {
rest of the form here...
}
I have been using Zuul in combination with other Netflix OSS softs like Eureka, Hystrix, etc. At first, I was able to create my own filter and make it work from the FileSystem. Then, I wanted to use ZuulFilterDAOCassandra API to be able to pull filters from a Cassandra database. The problem is that I'm not able to make it work.
I have translated the Java filter I used from the FileSystem to a Groovy filter, and added it to Cassandra using the ZuulFilterDAO.addFilter() method, and activate it using ZuulFilterDAO.setFilterActive().After that, I started the ZuulFilterPoller to start pulling the filters from the database, if it already had any. For the database table model, I assumed it by looking at the FilterInfo object and its attributes, and from the ZuulFilterDAOCassandra.addFilter()method.
Here's a more complete section of code :
ZuulFilterDAO dao = new ZuulFilterDAOCassandra(keyspace);
try {
FilterInfo fi = dao.addFilter(code, "pre", "testFilter", "false", "1");
dao.setFilterActive(fi.getFilterName(), 1); // 1 is the filter revision
ZuulFilterPoller.start(dao);
} catch (Exception e) {
// Logging
}
// Show every active filter
List<FilterInfo> allActiveFilters = dao.getAllActiveFilters();
for (FilterInfo fi : allActiveFilters) {
LOG.info("FilterName: " + fi.getFilterName()); // outputs : FilterName: testFilter
}
In the Zuul console, I also get the following :
adding filter to diskFilterInfo{filter_id='zuul-server:testFilter:pre',
filter_name='testFilter', filter_type='pre', revision=1, creationDate=/*date*/,
isActive=true, isCanary=false, application_name=zuul-server}
filter written testFilter.groovy
I can then edit the testFilter.groovy at the root of my project, which contains the code I have mentioned in the dao.addFilter() method. I know the code is working, since it worked when pulling filters from the FS. And, when adding a filter, there's a verification of the code done by FilterVerifier.
And when I send my http requests to my application, Zuul doesn't filter them anymore. Am I missing something ?
Try using the FilterFileManager. It's my understanding that ZuulFilterPoller saves the filters from Cassandra to disk, and the FilterFileManager puts them to work.
I want to write Java API code using playframework! (I'm using the Eclipse IDE.)
What would a sample API look like for insertion and selection?
How do I assign URLs in a routes file?
This answer applies to version 3 of the Play framework.
Here is a sample route file configuration to show a page. In this example, you can visit http://yoursite.com/1 , which will call controllers.Application.show("1").
# Extract the page parameter from the path.
# i.e. http://myserver.com/index
GET /:page controllers.Application.show(page)
SELECTION
Here is the corresponding show method definition in the controllers.Application controller:
public Result show(String page) {
String content = Page.getContentOf(page);
response().setContentType("text/html");
return ok(content);
}
INSERTION
For insertion, check out the "Form submission and validation" and "Working with JSON" sections of the documentation. There are examples there; sorry for not adding them here, but these are more complicated for this short format.
Source, and more information: https://www.playframework.com/documentation/3.0.x/JavaRouting