Alright, this might look like a duplicate question but I have struggled a lot but haven't found a proper solution. Closest match I found is this: JaxWS application URL in Tomcat
But this is using something different.
I am using Glassfish 3 and developing in Netbeans 7.4 along with Spring, Spring MVC. I have developed my webservice using following code:
#WebService(serviceName = "FooService")
public class FooWS {
#WebMethod(operationName="getHelloWorld")
public String getHelloWorld() {
return "Hi";
}
}
Now the problem is that, it start listening at this address http://localhost:8080/myapp/FooService
But I want it to listen at http://localhost:8080/myapp/ws/FooService.
I do not have any xml in my project for configuring web services. I only have following xmls in WEB-INF
applicationContext.xml
dispatcherServlet.xml
glassfish-web.xml
spring-security.xml
web.xml
Except glassfish-web.xml netbeans haven't generated any code for my webservice in any other xml file. And also in this file there is no source, just there is a section for Web Services which shows this web service, I am attaching image for the same.
Does anybody knows where should I make changes to change listening url? Or any annotation that might help?
I found this answer https://stackoverflow.com/a/8975619/601168 but I guess this is for clients only.
Related
I'm a relatively new Java developer that is working on a Java 8 Spring Boot project. I am trying to learn and understand WebSockets so I have created a basic Websocket server that appears to be up and running correctly.
I wanted to use the Static folder to render a basic HTML page with a JS file and CSS. From what I have researched, it should use it automatically, but I'm getting a standard whitepage error when I use the browser to connect when my research seems to indicate it should render by default?
I've heard that Thymeleaf is used to render templates, but I have also read that I can connect a basic HTML file from the Static folder instead. When I try to connect to the main server, it gives me the following logs from my different attempts to see the index.......
No mapping for GET /
No mapping for GET /index
No mapping for GET /index.html
I'm not sure what the problem could be and my Google-Fu is turning up no solutions. I feel like I must be missing something fundamental here, but I'm not sure how to properly map that route. I have Spring Web dependencies installed so I could create a RestController mapping to that route, but how would I properly return those static files?
You need to create the endpoint for the default entry page of your application. Something like this:
#Controller
public class HomeController {
#GetMapping("/")
public String index() {
return "index";
}
}
Your index.html goes inside this path "src/main/resources/templates/".
The solution I found through another source on Discord..
Part of the problem was I was using #RestController instead of #Controller.
The other issue was I had my index.html in the public folder instead of Templates.
And the final error was I had the incorrect Thymeleaf dependency. I needed the Thymeleaf Starter and I had accidentally added a different one from Maven Repo.
I'm trying to build a Java service that other services could call.
This service is not a WS, but is calling a RestfulWS.
I'm really just building a wrapper around this call. This would find the correct data it needs, set up the JSON for the call. Get a response and send it back up.
Was told to use Jersey for this. Trying to set up all the pom.xml to use Jersey.
Building code works fine, it is when the deploy to the server happens that things fail.
I get the error -- "JBAS011232: Only one JAX-RS Application Class allowed. "
I don't have a web.xml, which I guess is used to skip some ResetEasy files.
I do have exclusions in pom.xml and jboss-deployment-structure.xml.
I still get the error when deploy happens. Not really sure what else to check.
It looks like you have a problem with JAX-RS dependencies. JBoss already has its own implementation of JAX-RS and probably that’s causing the issue. Some solutions are already suggested here Jboss error: Only one JAX-RS Application Class allowed
I have a working web-application that I built, successfully deployed to Heroku, and is functioning well. However, I'm trying to tune the server/servlet config, and that's when I realized that I don't know what my application is actually doing.
For glassfish, this is the config that's needed.
However, for Jetty, this is the config that's needed.
I realized I have no idea which of the above my application is actually using, so I started digging in my code and found the following:
The main method being called by Heroku is instantiating the following Jetty server/webappcontext.
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
However, the jetty config seems to rely on a number of files (such as etc/jetty.xml, webapps folder or war files) which my project does not have at all.
In addition, my web.xml file defines the following servlet:
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
The fact that my application is defining a Jetty server but Glassfish servlet concerned me quite a bit. In an effort to standardize everything around Jetty, I tried adding the jetty servlet to my pom.xml dependencies and changed the above to:
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
However, this change caused my application to break. It still compiles successfully and all my jerset-test based integration tests still succeed locally. But when I actually run the server, none of the routes work.
Some questions:
Is it a ill-advised to use a Jetty server along with a Glassfish servlet (container)?
If yes, what servlet (container?) should I replace Glassfish with, and what do I need to do to get the new Jetty servlet working?
If no, what config should I be using for my current setup? Should I be implementing the Glassfish config or the Jersey config?
I've spent many hours trying to read through various documentations, tutorials and stack-overflow threads, but they all either assume prior knowledge about servlets, JavaEE and related topics (none of which I'm familiar with), or they are oriented towards building brand new hello-world apps from scratch (as opposed to porting an existing working app over, which is what I'm trying to do). Any explanations you could give, without assuming prior knowledge, relevant to the context described above, would be much appreciated.
Edit: I think I'm starting to understand now that a Servlet is the code that generates the response for a request, and the ServletContainer is what provides the infrastructure for the Servlet. I've never had to deal with Servlets directly in building my web-app. Here's an example of what a route looks like in my app:
#Path(Ping.REST_PREFIX)
public class Ping {
static final String REST_PREFIX = "/ping";
#GET
public static Response get(#DefaultValue("getPing") #QueryParam("param") String param) {
return Response.ok().entity(param).build();
}
#Path("/pong")
#GET
public static Response getPong(#DefaultValue("getPong") #QueryParam("param") String param) {
return Response.ok().entity(param).build();
}
}
How can I port code like the above into a Jetty ServletContainer, without rewriting vast sections of my application?
You are not using a "Glassfish Servlet Container", you are using a "Jersey Servlet Container".
Jersey is the project you are using.
Glassfish was the umbrella organization (sometimes called "a forge") that helps manage/maintain the Jersey project (along with dozens of other projects).
Difference com.sun.jersey and org.glassfish.jersey
The Jersey project can now be found at the java.net organization.
https://jersey.java.net/
I am creating a REST based web application and using the latest version of Jersey and embedded Jetty. Descriptor-less deployment for Servlet 3.0 allows the exclusion of web.xml. However, I am having trouble understanding how you can serve static content in this case (.html, .css, .js and image files)? As the application is using embedded Jetty, I am not deploying this in a standalone servlet container, so the resulting file is a shaded .jar. Perhaps, I need to use the WAR plugin to make this possible? If so, where exactly do I have to place the aforementioned files? Is it still possible with packaging into .jar only as well?
The only way I have been able to serve static content so far, was with direct filesystem access, like this (Jersey's JAX-RS part):
#GET
#Path("manager/preview/img/loader.gif")
#Produces("image/gif")
public final Response preview() throws Exception
{
final byte[] b = Files.readAllBytes(Paths.get("manager/preview/img/loader.gif"));
return Response.ok().entity(b).build();
}
This definitely does not seem like the appropriate way. I'd be thankful, if someone could point me in the right direction.
I am trying to figure out what the following url does.
http://server/abc/testmodule/runtest.do?action=edit&id=123
I am new to jboss/jsp but I am very familiar with .net.
When I see this url, I expect to see the physical folder called "abc" and subfolder called "testmodule" and a physical file "runtest". am i wrong? what does runtest.do? is "runtest" class and "do" is a method within it?
It could be anything--URLs can map to arbitrary resources. It might be a Struts action, it might be a servlet, it might be a Spring controller, etc.
You'd need to check your web.xml file and/or any framework configuration files, or provide more information.
(Also, JBoss isn't a framework, it's a Java EE container :)
The /abc entry is the name of the context in which the application is running. If it's a web app, deployed in a WAR file, that would be the name of the WAR that's deployed (abc.war).
The .do extension suggests a Struts or JSF action mapping.
There are two parameters passed in the GET: action, with value edit, and id, with value 123. Looks like a REST-ful API to me.