How to run JAX-RS in Maven project of JAVA EE? - maven

This is what I did on NetBeans.
New Project -> Maven -> Web Application
and gave my project name
And, created new RESTFUL Web services from patterns
selected Simple Root Resource
Assigned path "foo"
and hit finish
And now, I tried to access it from browser as
localhost:8084/context/webresources/foo
And, it shows 404 resources not found error.
I checked if it works with non-maven based projects, and it does. Accessing the resource was possible on those but, not on maven based.
I must have missed something.
I also tried to see if it is accessible from netbeans by doing right-click on the RESTful Web Services and clicking TestResource Uri,
It shows error
Unable to open resource url.
the uri of the rest location
Make sure project has been deployed successfully and the server is running.
While both have been done!!

Related

FF4J with Spring Boot in IBM WebSphere 8.5.11 server giving Error 500( SESN0008E) while accessing static resources(css,img)

I am using FF4J-Web as a maven jar dependency in my Spring Boot application. I am able to run the application in local environment without any issues( embedded tomcat and IBM Liberty Servers). However I am facing some issues in rendering view components when I promote the changes to development environment server(IBM WebSphere 8.5.X) which seems to be due to authorization issue. Please find below responses I got while accessing static contents.
Response Code 200: https://dummyserverlink.com/rootcontext/ff4j-web-console/static/js/jquery.dataTables.min.js
Response Code 500: https://dummyserverlink.com/rootcontext/ff4j-web-console/static/css/bootstrap.min.css
Response Code 500: https://dummyserverlink.com/rootcontext/ff4j-web-console/static/png/ff4j.png
As you can see above, .js files are downloading without any issues. But .css and .img files are not authorized and accessible in the browser(Error Code Status 500). But all resources are present under static folder only. Please note that since I have added FF4J as a maven dependency all the static contents are present inside WEB-INF/lib folder
So if I try to access the .css/.png resource directly from browser, I am getting error ‘Error 500: SESN0008E: A user authenticated as anonymous has attempted to access a session owned by loggedUserName.’
Disabling the security configuration in Websphere is not an option we can go with as the same server is used for multiple applications. Also I am using third party login API for authentication at server level.
Is there any other way that you can share you expertise to bypass the authorization error for static resources(css,img) that are inside the WEBINF folder?
Regards
Dinesh

No response when trying to publish the project on to the WAS Server

I have imported a project into the eclipse and it has different modules like
Audit
AuditEJB
Common
CommonLoginConsumer
Core
Db2Integration
EJB
InitWeb
Integration EAR
MDMIntegration
PrepackagedApps
Properties
SchedulerEJB
ScreensWeb
WebServiceConsumer
WebServiceProvider
Provider
CCWSTest (Gradle module)
CTest
CUiWeb
UtilityTestEAR
UtilityTestWeb
Configured build Path, solved all the Java Problems. In the company that I'm working to configure WAS Server 8.0, we need to configure DSC which has all the deployment frameworks.
In Servers (Right click)> Add and Remove, I have IntegrationEAR and UtilityTestEAR
UtilityTestEAR contains Properties, and UtilityTestWeb
Integration EAR has apsclient-source.jar, Adit, AuditEJB, Common, CommonLoginConsumer, Core, Db2Integration, EJB, InitWeb, MDMIntegration, Properties, SchedulerEJB, ScreensWeb, WebServiceConsumer, WebServiceProvider, Provider, org.apache.soap.encoding61.jar
When I added UtilityTestEAR to the WAS Server, Server started Successfully and when I try to publish there was no response.
When I added IntegrationEAR to the WAS Server, when I started the server, there was an error saying:
The publish encountered some problems and the application may not have been installed or it may have been successfully installed but was unable to start.
The application contains validation errors. Correct the errors in the Problems view before publishing the application on the server.
If you want to allow applications containing errors to be published on the server, enable the Allow applications containing errors to be published on a server check box (Windows > Preferences > Servers > WebSphere).
CHKJ2802E: class com.ford.mss.cdr.cib.mdb.CdrAuditLogMDB, or one of its supertypes, cannot be reflected. Check the classpath.
I am trying to deploy to my localhost.
Please Suggest

Tomcat Context Root - Tiles Exception when deploy a Spring app to Tomcat

I have a Spring MVC 4 application deployed in tomcat. It works fine. I have to clone this app to have several applications with same behaviour but different configurations: database instance and folders for file management. Each for different customers. When I deploy de original application to Linux Tomcat it works fine (https://hostname:8443/app1).
Then I change the db connection settings (database name, username, and folders to manage some generated files) and change the name of the artefact to customername. But when I get into the application, it shows the login page right, but when login into the app, I'm getting the following error:
Status HTTP 500 - Request processing failed; nested exception is org.apache.tiles.request.render.CannotRenderException: java.io.IOException: JSPException including path '/WEB-INF/layout/header.jsp'
javax.servlet.ServletException: File [/WEB-INF/layout/header.jsp] not found
when accessing to https://hostname:8443/customername, which it's part of tiles template. Files exist in the deployed application, It's able to reach the login page, so it seems to be resolved the tiles config, but I don't know why is not able to reach the jsp files. It's working fine in local windows without secure Tomcat (port 8080).
EDITED
If I change the name of customername.war to app1.war it's working fine. Anybody knows where the war file keep a reference to the base application app1? It seems that there a reference to app1 in somewhere that makes that If I change the application name (artifact id) it does not reference to customername path.
Seems that it's a context root issue. I have changed it in STS (Project > Properties > Web Project Settings > Context root), deployed on Tomcat but still not working. It's supposed that only with changing the war file name, the context root of the application should be updated, but it's not working.
Upgrading Tomcat from 8.0 to 8.5.5 solves the issue. I don't know why, but there's an issue in 8.0 because no way to force context root for an application, not context.xml application file neither other configuration.
Just upgrade to 8.5.5 and deploy applications without context issue.
BR

How to debug a Spring Boot Web Application in STS?

I am new to the Spring Framework and so I started with the Spring Boot projects.
In particular, I took the https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-secure-jdbc project and modified the pom.xml so that it becomes self contained (replaced spring-boot-samples with spring-boot-starter-parent in the parent->artifactId tag, removed properties node, added in repositories and pluginRepositories from http://docs.spring.io/spring-boot/docs/1.2.2.BUILD-SNAPSHOT/reference/htmlsingle/#getting-started-maven-installation).
I successfully built and ran this application outside of STS first with 'mvn spring-boot:run', then imported the Maven project into STS and it builds and runs there successfully.
I am able debug this application by right-clicking on the project folder and choosing Run->Debug As ...->Spring Boot App and the debugger does stop at the breakpoints I've set in the ApplicationSecurity class methods. However, the browser window does not automatically pop-up in STS nor the system browser (which I expect - is this correct?).
When I browse to localhost (port 8080) using the 'Internal Web Browser' within STS/Eclipse the HTML pages render out but the breakpoints that I've set in the #RequestMapping("/") methods do not get hit (I suspect that this is probably due to the fact that the browser is in a separate process to the debugger).
So, how do I debug #RequestMapping methods within STS - this would help me to understand the Spring framework better.
I have limited knowledge of Eclipse/STS, so could there be a problem with my installation?
You don't need to use the embedded browser to debug a server (the browser is a separate process). If your #RequestMapping breakpoints are not hit then I suspect Spring didn't dispatch to those routes for whatever reason (maybe security?).

Setting up home page in spring

I am new to spring environment. I have created small test spring project through STS.
Project name: SPTest
base package name: uk.co.ifTest
When I run and open this project browser through Eclipse. It work fine, but url, it put in the browser is xx.xx.xx.xx:8080/ifTest/, instead of //xx.xx.xx.xx:8080/SPTest/.
I guess, it is adding base package name.
Is there any way I can open project with http://xx.xx.xx.xx:8080/SPTest/.
Thanks
ish
You need to change your context path for the server to point from ifTest to SPTest.
This answer will help you identify how to do it:
Changing Tomcat context path of web project in Eclipse

Resources