Why my jaxrs APIs has the application name as application path? - java

I created a simple version API with rest-easy and wildfly, everything should works but the application path has the name of my project:
My version API return the version number from my pom.xml: The URI should be http://localhost:8080/version
but to acces it this is http://localhost:8080/projectName/version.
To acces to the open api file : The URI should be http://localhost:8080/openapi
but this is http://localhost:8080/projectName/openapi
I tried to extend Application to set the #ApplicationPath("/") but it's not working, it just allowed me to add element on the application path
example: http://localhost:8080/projectName/test/....
How can I set the application path to the root (/) and remove the projectName ?
JaxRSActivator class:
#ApplicationPath("/")
public class JaxRSActivator extends Application {
public JaxRSActivator()
{
super();
}
}
VersionFacade class:
#Path("/version")
#Tags
public interface VersionFacade {
#GET
#Produces(TEXT_PLAIN)
#Operation(summary = "Application version",
responses = {
#ApiResponse(responseCode = "200",
description = "Version number",
content = #Content(mediaType = TEXT_PLAIN, schema = #Schema(implementation = String.class)))})
String getVersion();
}
web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<!-- public API -->
<security-constraint>
<web-resource-collection>
<web-resource-name>public</web-resource-name>
<url-pattern>/openapi.json</url-pattern>
<url-pattern>/version</url-pattern>
</web-resource-collection>
</security-constraint>
<context-param>
<param-name>resteasy.role.based.security</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
openapi-configuration.yaml file
openapi: 3.0.0
prettyPrint: true
cacheTTL: 0
openAPI:
info:
version: '0.0.1'
title: API config file

Jboss wildfly use the Web module name (projectName.war) as default context root. To set it you need to:
Add the WEB-INF/jboss-web.xml file in your Web module:
(if you don't package your app in an EAR file)
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<!-- Set context root to / -->
<context-root>/</context-root>
</jboss-web>
Or add the META-INF/application.xml file in your EAR:
(if you package your app in an EAR file)
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_8.xsd" version="8">
<display-name>projectName-ear</display-name>
<module>
<web>
<!--My Web module -->
<web-uri>projectName-ws.war</web-uri>
<!-- Set context root to / -->
<context-root>/</context-root>
</web>
</module>
<module>
<!-- other EJB module -->
<ejb>projectName-core.jar</ejb>
</module>
</application>
If you use Eclipse, careful it sometimes don't publish your application.xml so you need to put it manually in your Wildfly standalone/deployments folder.

Related

How to change context-root for enterprise application (.ear) in weblogic

We have third party web based enterprise application, which is deployed on weblogic server and can be accessible using
http://hostname:port/myApp
But, due to some reason, we wanted to change context-root for this application, so that it must be ONLY accessible using
http://hostname:port/newApp
So, to achieve this, we tried changing application.xml
<?xml version = '1.0' encoding = 'utf-8'?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4">
<display-name>myApp</display-name>
<module>
<web>
<web-uri>myApp.war</web-uri>
<context-root>newApp</context-root> // changed from myApp to newApp
</web>
</module>
</application>
But, while deploying this application on weblogic server, we are getting following error.
weblogic.management.DeploymentException: The application myApp contains a SubDeploymentMBean with a name myApp however there is no module in the application with that URI or context-root.
On the other hand, if we keep both context-root as shown below application.xml file, then it gets deployed successfully and also able to access application using both context-root.
<?xml version = '1.0' encoding = 'utf-8'?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4">
<display-name>myApp</display-name>
<module>
<web>
<web-uri>myApp.war</web-uri>
<context-root>newApp</context-root> // changed from myApp to newApp
</web>
</module>
<module>
<web>
<web-uri>myApp.war</web-uri>
<context-root>myApp</context-root>
</web>
</module>
</application>
Can anyone help me to resolve this issue ? Let me know, if additional information required.
==Edited==
I have added weblogic.xml file, but not sure, what I suppose to change in this file as pointed by #Hououin Kyouma in his/her answer.
<?xml version = '1.0' encoding = 'US-ASCII'?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<session-descriptor>
<cookie-path>/myApp</cookie-path>
</session-descriptor>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
You cannot define a context root with a differently named war file in the application.xml
<module>
<web>
<web-uri>myApp.war</web-uri>
<context-root>newApp</context-root> // changed from myApp to newApp
</web>
</module>
You must change above to
<module>
<web>
<web-uri>newApp.war</web-uri> // changed from myApp to newApp
<context-root>newApp</context-root>
</web>
</module>
You need to create the war with the new name. You will still need to change the weblogic.xml in the new war file, but as long as this question goes, above is what you need to do.
Have you tried setting the context root in the weblogic.xml?
https://docs.oracle.com/cd/E13222_01/wls/docs90/webapp/weblogic_xml.html#1073750
EDIT
Trying adding it like mentioned in this
https://community.oracle.com/thread/747158
<?xml version = '1.0' encoding = 'US-ASCII'?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<context-root>/newApp</context-root>
<session-descriptor>
<cookie-path>/newApp</cookie-path>
</session-descriptor>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>

How to deploy war file in root(/) context to Wildfly ver 8.1.0.Final and remove welcome-content

I'm trying to put my application on the root context to wildfly.
I put this files jboss-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>/</context-root>
</jboss-web>
and the empty file bean.xml at WEB-INF/
The welcome-content is still working at localhost:8080
If you put localhost:8080/index.xhtml my application appears.
I tried renaming the direcctory welcome-content but no works.
SOLVED: REFRESH CACHE OF THE BROWSER

JNDI name not found - how to use JNDI in WCM workflow plugin?

I'm using Rational Application Developer 8.5 to develop a custom workflow action plugin for IBM Web Content Manager (WCM) in WebSphere Portal 7.0.
The plugin needs to get a JDBC data source with JNDI, but all my attempts to do so produce this error:
javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
A data source named "jdbc/wcmbulletins" is defined in the WebSphere Application Server.
Here's the java code to get the data source:
javax.naming.InitialContext ctx=new javax.naming.InitialContext();
javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/wcmbulletins");
The RAD project contains the following XML files only. There's no "persistence.xml" or any other files I've seen mentioned in similar SO questions.
There are also some JSP files referenced by WCM JSP components. The JSP files have no connection with the plugin and don't use JNDI or JDBC.
ibm-web-bnd.xml:
<web-bnd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
version="1.0">
<virtual-host name="default_host"/>
<resource-ref name="jdbc/wcmbulletins" binding-name="jdbc/wcmbulletins"/>
</web-bnd>
ibm-web-ext.xml:
<web-ext
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
version="1.0">
<jsp-attribute name="reloadEnabled" value="false"/>
<jsp-attribute name="reloadInterval" value="10"/>
<reload-interval value="3"/>
<enable-directory-browsing value="false"/>
<enable-file-serving value="true"/>
<enable-reloading value="true"/>
<enable-serving-servlets-by-class-name value="true"/>
</web-ext>
plugin.xml:
<plugin id="com.company.wcm.CompanyWCMPlugins"
name="Company WCM Plugins"
version="1.0.0"
provider-name="Company Name Australia">
<extension
point="com.ibm.workplace.wcm.api.CustomWorkflowActionFactory"
id="CompanyWorkflowActionFactory">
<provider class="com.company.wcm.workflow.CompanyWorkflowActionFactory"/>
</extension>
</plugin>
web.xml:
<web-app id="WebApp_ID" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>CompanyWCM_JSPs</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<resource-ref id="ResourceRef_1377568155870">
<description/>
<res-ref-name>jdbc/wcmbulletins</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
What do I need to make the JNDI lookup work?
What happens if you change the code to bypass the resource reference and use the name jdbc/wcmbulletins instead?
Also - at what scope is the DS defined? If at cluster level try the name cell/persistent/jdbc/wcmbulletins and see what you get.
Lastly - there is always the WebSphere naming trace. You can enable them via Naming=all, re-run your app, and check trace.log for insight as to what might be going on.
Hope this helps,
ScottH
From my experience, wcm plugins are somewhat independent from the web-application they are contained in (they are more related to OSGI or so). For example during server startup plugins are instantiated, before the web-application itself is, so it might not even be possible to reliably lookup resources from the web-app.

issues deploying a JAVA application to weblogic 11g

I have a simple JSP/Servlets application. The app is already deployed to the server and is running at say URL http://www.servername:7001/myapp1/jsp/login.jsp. I have made some substantial changes to the code and I redeployed it as myapp2 in the server. However if I try to access it at this URL,,say http://www.servername:7001/myapp2/jsp/login.jsp, this gives me a "resource not found error". Is the URL mapped to the application somewhere? What do I need to do to access the newly deployed project. I do not want to remove the old project till I am sure the new one works properly
You probably need to specify a context root. There are a couple of places this might appear.
1) Inside your EAR file in META-INF/application.xml, e.g.:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
id="Application_ID" version="5">
<display-name>myapp2</display-name>
<module>
<web>
<web-uri>myapp2.war</web-uri>
<context-root>/myapp2</context-root>
</web>
</module>
</application>
2) In the WAR file, in WEB-INF/weblogic.xml, e.g.:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<wls:weblogic-version>10.3.2</wls:weblogic-version>
<wls:context-root>myapp2</wls:context-root>
</wls:weblogic-web-app>

CDI injection in JAX-WS endpoint does not work, results in NPE

Why doesn't the following CDI work in JAX-WS endpoints in glassfish 3.x.x? I get an NPE when accessing the service from the endpoint.
#WebService
public class JaxWsTestEndpoint {
#Inject
private MyService service;
#WebMethod
public String sayHello(String name) {
System.out.println("injected service:" + service);
service.callService();
return "Hello, " + name + ".";
}
}
Where the class "service" is defined as follows:
#Named("myService")
public class MyService {
public MyService() {
System.out.println("init myService.");
}
public void callService() {
System.out.println("calling Service.");
}
}
I have an empty beans.xml file in WEB-INF. I tried it with complete empty content, and with an empty
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
tag. But somehow, the service field in the JAX-WS endpoint is still NULL after deployment and during receiving a web service request, resulting in a NPE when calling the service. What am i missing here?
You can try to remove sun-jaxws.xml from WEB-INF directory. This way has helped me!
Yes I got it working by removing sun-jaxws.xml and modifying web.xml pointing my webservice directly instead of WSServlet.
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- This listener parses a sun specific configuration file (sun-jaxws.xml), which provides the web service
endpoints and connects the WSServlet instance to the services' implementation classes -->
<!--<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener> -->
<!-- Delegate requests whose URLs end with the path '/StakeholderWebService' to a WSServlet instance provided by container, which in turn is linked to the JWS runtime -->
<servlet>
<servlet-name>StakeholderWebService</servlet-name>
<!-- <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> -->
<servlet-class>com.werner.stakeholder.webservices.StakeholderWebServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StakeholderWebService</servlet-name>
<url-pattern>/stakeholderWebService</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>

Categories

Resources