IBM WebSphere deploy Angular 5 application and getting 404 on refresh - java

I build full stack applications with Angular (currently version 5) Usually the backend is Windows Server and it uses IIS , so thus I know to deploy a web.config file with the rewrite module code.
Problem is that the site is a SPA , and it needs to always point at index.html, no matter what the URL says...
As I said, I'm used to windows , but the backend is Java with IBM Websphere
Anyone know what I need to have done in order to have a properly working Angular application?
Example, the configuration for WINDOWS is a web.config like this below, but this is Websphere with a Java application and I assume the backend is Linux/unix
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/MyApp/" />
<!--<action type="Rewrite" url="/" />-->
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

You'll need to add the following to web.xml, which is packaged in the WEB_INF directory within the .war file of your app:
<error-page>
<error-code>404</error-code>
<location>/</location>
</error-page>
Which tells the app server to show the resource at the application's context root when issuing a 404 error.

Related

Can't run Core Java web application into Azure Web app

I have written a core java web application using maven-archetype-webapp and trying to deploy the jar file and web.config in a azure windows based webapp but not able to access the url. I only have home page inside my application. and following below steps. I am able to run it in my local system and can see the homepage.
azure-webapp-maven-plugin added in POM and build with mvn azure-webapp:config, then inside configuration tag I added below tag.
<appSettings>
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>
Created a web app in Windowsusing Java 8 and Tomcat 8.5
Deployed jar file and web.config file inside wwwroot directory
Web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\TestWebApp.jar"">
</httpPlatform>
</system.webServer>
</configuration>
Folder Structure
Azure directory structure
Local system Output:
Thanks #soumen for the solution.
Deployed the war file inside wwwroot -> webapps folder in azure
webapp. Before deploying deleted the Root folder inside webapps, after
my deployment new root folder was automatically generated, now I can
access the url.
I take it as an answer, hoping to help other members.

tomcat running but 404 returns without errors

I am trying to run my project in tomcat server through tomcat maven plugin.
In my pom xml:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
I am running the project through this command in Eclipse:
-e clean tomcat:run
the server started without errors or warning, but after pasting the url in web browser's address bar 404 error occurring(without no errors or warning's in eclipse console).
How can I solve this issue? If you need anything more on it just mention it in comments.
index page is not present in write location that is the reason of 404 not found error. please create index.jsp or index.html into /src/main/webapp or WebContent folder.
1.In eclipse tomcat configuration check the "deploy path" basically it is the path path where it will look for war file for deployment
and if required use custom location and configure the server path .
2.Please check tomcat-users.xml which I think you have already configured. if not please add below configuration to tomcat-users.xml
<role rolename="manager-gui" />
<role rolename="manager-script" />
<user username="admin" password="admin" roles="manager-gui,manager-script" />

How to install maven on microsoft Azure (app servies)

I have an app service, hosted on Azure.
The code for our service is on bitbucket and it is a maven based Java project. The process adopted by developers to deploy WAR files is to build them on local and FTP it to Azure which obviously isn't recommended.
Let's say I don't have the liberty and resource for hosting a CI tool like Jenkins, I am trying to do the following:
Sync the code from bitbucket.org to Azure by using 'Deployment Options' in Azure. Every time I do a git push, Azure automatically picks up the code from the specified branch and copies/updates/deletes the files modified (and places them under wwwroot by default)
I want to modify the deployment.cmd file in Azure so that I can add my custom steps post #1.
Where am I stuck?
I have FTPed maven and unpacked maven under D:\home\maven folder. I have set the correct environment variables by using a XDT file (attached). Yet, when I do mvn -version, I get the following error:
java.lang.NoClassDefFoundError:
org/apache/maven/exception/ExceptionHandler
..
..
caused by ClassNotFound ..
I don't have the complete trace handy. This class is there in maven-core which is there under the lib folder (I verified).
Could it be because of permissions? Cloud is cloudy to me o_O
After I get this to work, I need to add custom steps to deployment.cmd. Is there any specific language which I need to use or windows commands?
XDT file content for env variables (JAVA_HOME is already set)
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document- Transform">
<system.webServer>
<runtime xdt:Transform="InsertIfMissing">
<environmentVariables xdt:Transform="InsertIfMissing">
<add name="M2_HOME" value="D:\home\maven\apache-maven-3.3.9" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
<add name="MAVEN_HOME" value="D:\home\maven\apache-maven-3.3.9" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
<add name="Path" value="%Path%%JAVA_HOME%\bin;%M2_HOME%\bin;" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</environmentVariables>
</runtime>
</system.webServer>
I tried to reproduce the issue, but failed. According to the kudu wiki page for Xdt transform samples, the environment variables seems not support reference each other which had been defined above the current environment varable.
So please change the XDT file content like below that works fine after I test on an Azure Web App instance for Java.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<runtime xdt:Transform="InsertIfMissing">
<environmentVariables xdt:Transform="InsertIfMissing">
<add name="M2_HOME" value="D:\home\maven\apache-maven-3.3.9" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
<add name="MAVEN_HOME" value="D:\home\maven\apache-maven-3.3.9" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
<add name="PATH" value="%PATH%;D:\home\maven\apache-maven-3.3.9\bin" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</environmentVariables>
</runtime>
</system.webServer>
</configuration>
Then I ran the command mvn -version on Kudu CMD tool, it works fine.

JRebel do not detect web resource changes over multiple webapp folders

I have a modular web project and thus I am allowing modules to be a war archive including webapp folder. Using the following rebel.xml works fine on detecting class changes over all modules. But for some reason jrebel does not move when a html or js is changed.
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
<!-- appserver -->
<dir name="/home/xx/data/appserver/target/classes/main"/>
<dir name="/home/xx/data/appserver/target/resources/main"/>
<!-- module -->
<dir name="/home/xx/data/as.module.core/target/classes/main"/>
<dir name="/home/xx/data/as.module.core/target/resources/main"/>
<dir name="/home/xx/data/as.module.mqlcore/target/classes/main"/>
<dir name="/home/xx/data/as.module.mqlcore/target/resources/main"/>
</classpath>
<!-- web>
<link target="/">
<dir name="/home/xx/data/appserver/src/main/webapp"/>
<dir name="/home/xx/data/as.module.core/src/main/webapp"/>
<dir name="/home/xx/data/as.module.mqlcore/src/main/webapp"/>
</link>
</web -->
<web>
<link target="/">
<dirset dir="/home/xx/data">
<include name="**/src/main/webapp"/>
</dirset>
</link>
</web>
</application>
EDIT:
Interesting fact is. When I use the commented part of web configuration all three webapp folders are in the log and will be monitored for changes. But the application server can not find all of the webapp files. When I use the second <web> configuration all files are seen by the application server but are not observed by jrebel. I think it is not possible to have multiple directories linked to "/"
Each of the modules eg .war or .jar files need to have their own rebel.xml files. Otherwise all of them will reload same resources and when having different classloaders all kind of weird things can happen.
It is possible to check which instance of the file JRebel actually uses by searching "found resource" from jrebel.log. It should be written something like this
sun.misc.Launcher$AppClassLoader#184be29 found resource: 'cfg/log4j.xml' from 'file:/C:/Projects/testproject/Trunk/edm/target/cfg/log4j.xml'.
It is also seen which of the file changed by loking up lines with Event like this:
[IntelliJFSNotify] Event 'CHANGE' on: 'C:/Projects/testproject/Trunk/edm/target/cfg/log4j.xml'
Usually found resource and changed file paths do not match if the file is not reloaded. If they do match then it is recommended to send absolute path of the file and jrebel.log to support#zeroturnaround.com for investigation.
Ok, the answer is: indeed it is not possible to configure more than one directory under the <web><link target="/"></link></web> configuration. I have now a folder ./target/all-webapp where I smylink (cp -sR) all files via gradle task ... not nice but works ... and thank god jrebel is following symlinks!

Flex AMF Data/Services Error

After stumbling my way through setting up a BlazeDS service, I was finally able to get the list of services through the Flex Builder Data/Services Wizzard. However when testing any of the services, I get the Error popup of
> "InvocationTargetException:There was an error while invoking the
> operation. Check your operation inputs or server code and try invoking
> the operation again.
>
> Reason: java.io.FileNotFoundException:
> http://127.0.0.1:8080/portlets-0.0.1-SNAPSHOT/messagebroker/amf/
I could not find anyone else with a similar issue, and am unfamiliar with services setup. Below are my configurations. Any help would be greatly appreciated.
I can post config files if it will help, i was getting improper code format errors trying to insert them in this single post.
This service I am testing does not reach the function in the server, it is throwing this error before getting that far...
I have also noticed that I cannot run the flex application through a web browser using the standard run configuration in eclipse as it tries to target:
[http://127.0.0.1:8080/portlets-0.0.1-SNAPSHOT/messagebroker/amf/FlexMissionsOverview/MissionsPortlet.html][1]
Which throws a 404 error on tomcat since the file does not exist there. Are these possibly connected?
Any help would be greatly appreciated.
Added Details based on feedback:
Yes, the project name is "FlexMissionsOverview" with a Base Flex Application Called "MissionsPortlet"(.mxml).
The webapp is deployed to "webapps/portlets-0.0.1-SNAPSHOT/"
Compiler settings below:
-services "C:\liferay\liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\webapps\portlets-0.0.1-SNAPSHOT\WEB-INF\flex\services-config.xml" -locale en_US
-show-deprecation-warnings=false
-show-binding-warnings=false
Note: I am setting my project back up to where I had gotten to by the time of this post, if anything changes I will make another edit.
services-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<service-include file-path="remoting-config.xml" />
<service-include file-path="proxy-config.xml" />
<service-include file-path="messaging-config.xml" />
</services>
<factories>
<factory id="spring" class="flex.samples.factories.SpringFactory"/>
</factories>
<services>
<service id="remoting-service" class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition id="java-object"
class="flex.messaging.services.remoting.adapters.JavaAdapter"
default="true" />
</adapters>
<default-channels>
<channel ref="my-amf" />
</default-channels>
</service>
</services>
<channels>
<channel-definition id="my-amf"
class="mx.messaging.channels.AMFChannel">
<endpoint
url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf"
class="flex.messaging.endpoints.AMFEndpoint" />
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
</channels>
<logging>
<!-- You may also use flex.messaging.log.ServletLogTarget -->
<target class="flex.messaging.log.ConsoleTarget" level="Error">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>false</includeDate>
<includeTime>false</includeTime>
<includeLevel>true</includeLevel>
<includeCategory>false</includeCategory>
</properties>
<filters>
<pattern>Endpoint.</pattern>
<pattern>Service.</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging>
</services-config>
Pointing to the file directly on the tomcat server seems to work fine for testing the Flex Application via Eclipse, but I am still getting the same "FileNotFoundException" When trying to test the BlazeDS Services in the Data/Services Wizard in FlashBuilder.
Is there any indication of what the FileNotFoundException is coming from when trying to test the services? It may be some of the config information, but I am not positive, since I am used to these Exceptions saying what file it could not find.
The only class that I have in my project that is referenced above is the two listener classes, the other classes I believe come from my maven dependencies.

Categories