I'm new in the server-side , and I'm trying to learn how to use play in rest api with java and restangular. I made a project for java in the intellij. I want the GET request to return an html page and not html.scala page.
how do I change this function that it will return the app/views/index.html instead the app/views/index.html.scala
also if someone have a good website to learn from, it will help a lot
the function in java :
package controllers;
import play.*;
import play.mvc.*;
import views.html.*;
public class Application extends Controller {
public static Result index() {
return ok(index.render("Your new application is ready."));
}
}
the routes page :
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
Play use twirl as a template engine. I am not sure if you can easely change it to some other template engine but I think you can. Any way, as I see you are looking for a way just output simple HTML file. You can do this with default Assets controller:
this string in your route
GET /assets/*file controllers.Assets.at(path="/public", file)
would handle any files in the public. So if you will add to the public directory the simple /html/hello.html file then Play will render it by the url /assets/html/hello.html. You can change URL as you like in the rote file
I found a similar question with good answer with a lot of examples.
you can find it here.
The easiest way is to make a GET request for the / and to send the destination also, like this:
# Home page
GET / controllers.Assets.at(path="/public",file="index.html")
Related
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();
}
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 come from a Java/Spring background and I've just recently moved to Python/Django. I'm working on a new project from scratch with Django. I was wondering how Django handles common String messages. Is there one single common file that can be called in a resources folder? For example, in Spring, we have a MessageSource is a key/value pair properties file that is global to most of the app. Is there something similar in Django? If so, how does it work for the normal app side and the unit tests side?
You could take a look over Django's messages framework.
Also, you can use key-value pairs in Python, with dicts:
# Upper case because it is constant
LOGIN_ERRROS = {
'login_error_message': 'message here',
...
}
You could put this in a file, you can even name it message_source.py, inside you app and import it when you need it:
For example, in your view:
# views.py
...
from myapp.message_source import LOGIN_ERRORS
Django uses the standard gettext + .po files for internationalization/translation. Check out the Translation docs for all the steps needed: https://docs.djangoproject.com/en/1.9/topics/i18n/translation/
Is it possible to crawl ajax-based web sites using Heritrix-3.2.0?
If you intend to make a "copy" of an ajax website, clearly no.
If you want to grab some data by analysing the content of the website, you can customize the crawler with an Extractor that would determine which URLs to follow. On most website you can easily guess the urls that are interesting for your case without having to interpret the javascript. Then the ajax callbacks would be crawled and given to the Processor chain. By default this would store the ajax callback answers in the archive files.
Making your own Extractor looks like that:
import org.archive.modules.extractor.ContentExtractor;
import org.archive.modules.extractor.LinkContext;
import org.archive.modules.extractor.Hop;
import org.archive.io.ReplayCharSequence;
import org.archive.modules.CrawlURI;
public class MyExtractor extends ContentExtractor {
#Override
protected boolean shouldExtract(CrawlURI uri) {
return true;
}
#Override
protected boolean innerExtract(CrawlURI curi) {
try {
ReplayCharSequence cs = curi.getRecorder().getContentReplayCharSequence();
// ... analyse the page content cs as a CharSequence ...
// decide you want to crawl some page with url [uri] :
addOutlink( curi, uri, LinkContext.NAVLINK_MISC, Hop.NAVLINK );
}
Compile, put the jar file in the heritrix/lib directory and insert a bean refering to MyExtractor in the fetchProcessors chain : basically, duplicate the extractorHtml line in the crawl job cxml file.