How to run Spring Boot Application without manual activation? - html

I have this web application that heavily relies on API endpoints for its functionality. When I try opening the HTML file that displays the login/registration page and attempts to log in a returning user or register for a new account, this error is shown:
POST http://localhost:8080/Login net::ERR_CONNECTION_REFUSED
The application will only work if the spring boot application is running in IntelliJ:
#SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
Is there a way for my web application to properly connect with the API, without manually having to run the code shown above every time in IntelliJ?

Related

html to #RestController redirecting problem -On External linux Server -But working fine on local SpringToolSuite

Please help me in solving :
My application running good in spring tool suite , but when i deploy onto external Linux server- initially is was fine,
But after adding below line in my html page(in template folder)
1.<td > <a th:href="#{/generateAndGetInvoicePDF(invoiceNo=${invoiceList.invoiceNo})}" style="text-decoration: none;" th:text="${invoiceList.invoiceNo}"></a>
--
It is working fine in my local machine (Spring tool Suite-localhost:8080)
--
But in my Linux server i am getting below error
**Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Jun 14 08:23:32 UTC 2022
There was an unexpected error (type=Bad Request, status=400).**
my controller method
#GetMapping("/generateAndGetInvoicePDF")
public ModelAndView getInvoicePdf(#RequestParam("invoiceNo") String invoiceNo) {
ModelAndView mav = new ModelAndView();
System.out.println(invoiceNo);
List<Invoice> findByInvNo = IINservice.findAllByInvNo(invoiceNo);
mav.setViewName("invoicePDF");
return mav;
}
this is my address bar
**http://localhost:8080/generateAndGetInvoicePDF?invoiceNo=INV2022/01**
i am using
spring tool suite 4
spring boot
spring security
spring data Jpa
Regards,
Arun
For me the issue was because of Case sensitivity. I was using ~
{templates/invoicePDF} instead of ~{templates/InvoicePDF} (The name of the file was InvoicePDF.html) --'I' is in upperCase
My development environment was windows but the server hosting the application was Linux so I was not seeing this issue during development since windows' paths are not case sensitive.

How do I get POCO SecureSMTPClientSession class to work, using NetSSL_Win module?

I have built Poco 1.11 and am unable to get secure SMTP connections, or HTTPS connections in general, to work, with the NetSSL_Win module (i.e. using Windows Schannel rather than OpenSSL). There is a sample in the distribution at NetSSL_Win\samples\Mail\src :
SecureSMTPClientSession session(mailhost);
session.login();
session.startTLS(pContext);
if ( !username.empty() )
{
session.login(SMTPClientSession::AUTH_LOGIN, username, password);
}
session.sendMessage(message);
session.close();
When I run it, the second login() call, after the startTLS() call, throws this error:
SSL Exception: Failed to decode data: The specified data could not be decrypted
The server in this case was smtp.gmail.com, on port 587.
I get the same error message for any other HTTPS client code I try to run as well.
Is anyone successfully using Poco 1.11 for HTTPS connections, using Windows Schannel?

PupeeteerSharp Does Not Work in ServiceFabric Stateless Service

I am developing web crawler which could render Javascript websites and so I decided to use PupeeteerSharp, a .NET port of popular Node.JS headless Chrome browser Pupeeteer API. I am running Service Fabric's local development cluster on Windows 10 development machine and have one stateless service in my solution.
I've created Data folder under Service project's PackageRoot folder and put .local-chromium folder contents there (contains chrome.exe executable) so it deploys as independent data package of service.
I've also placed this XML config line in ServiceManifest.xml file:
<DataPackage Name="Data" Version="1.0.0" />
So far it looks good and headless browser content is copied to SFCluster Data package directory properly.
Then in my Stateless Service code I try to call Pupeeteer chromium executable as follows:
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath = _chromiumPath // #$"{context.CodePackageActivationContext.GetDataPackageObject("Data").Path}\.local-chromium\Win64-706915\chrome-win\chrome.exe"
});
using (var page = (await browser.NewPageAsync()))
{
Response renderResponse;
try
{
renderResponse = await page.GoToAsync(webPage.AbsoluteUri, timeout);
if (renderResponse.Status != System.Net.HttpStatusCode.OK)
{
return new RenderResult(RenderStatus.OtherFailure);
}
// other code
}
catch (TimeoutException)
{
return new RenderResult(RenderStatus.Timeouted);
}
In this line: using (var page = (await browser.NewPageAsync())) my code (Thread) simply hangs without returning, in Debug console I see many thread exits, but no exception occurs. I was previously getting System.IO.FileNotFoundException when I was fixing some other errors regarding appropriate copying of chromium folder contents, but now these errors are gone so it seems that code find .exe but somehow cannot start headless mode of PupeeterSharp.
Does that mean that I cannot simply run external .exe chromium binary with Service Fabric's Native Application Model? Should I use Docker and Linux containers instead?

Debugging web application in service fabric - View error returns 404

I'm developing a web application (ASP.Net Core) in a servicefabric cluster, but every time I get an error in a razor view (for example a variable not set) I get a 404 error and not the well known error page which tells me what is wrong.
I have no clue as to why it does that or how I should solve it and can't find anything online. Can anyone point me in the right direction?
The project used to run outside the cluster and debugging worked there but since it's in the cluster it doesn't.
Visual Studio is currently not able to set the ASPNETCORE_ENVIRONMENT for Service Fabric Services.
You can workaround this problem by changing this code in the default Configuration method in your Startup.cs file to this:
//if (env.IsDevelopment())
if (env.ContentRootPath.Contains("SfDevCluster"))
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
That should be a fairly safe assumption that you are running the application in a OneBox Service Fabric cluster.

On some machines my app fails reading a JSON feed from a web Address

I have a UWP app using C#. I use HttpClient to retrieve a JSON file from the server. On some machines however it fails with a "unable to connect to the remote server". The server is accessible through the browser though. Any ideas?
The HttpClient has a Timeout property. Set that to the timeout you want and handle the TimeoutException to do specific things on the timeout.
HttpClient client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(5);
HttpResponseMessage response = null;
try
{
response = await client.GetAsync(url);
}
catch (TimeoutException)
{
// handle the timeout, e.g. return false
return false;
}
catch (Exception ex)
{
// handle the other errors, e.g. throw it
throw (ex);
}