I created a tutorial that incorporates various components of J2EE in them. The app is an ear module that has an ejb project and a web project.
the project structure is
john-app
john-ear
john-ejb
john-web
the ejb project has a couple dao that perform basic crud operations using jpa. I'm trying to learn/understand jax-rs to gain a better understanding of json and handling json objects. the project is loosly based on
this project:
http://www.developer.com/java/creating-restful-web-services-with-jax-rs.html
so, i created my BookResource here and made it a stateless ejb. i have everything compiling and deploying without any obvious errors - other parts of the app work (the jpa stuff) but i can't get the jax-rs stuff to
work. i have a couple of"Books" that I created in my database and am wanting to test this by making a rest call through the browser.
so i deploy my .ear file in wildfly (v10) with no obvious errors, I see JNDI mappings for my EJB's...etc
initially, i'd like to be able to test this through my browser, but am not certain what url to use -- the class i have extending javax.ws.rs.core.Application has an application path of /rest and my
BookResource has a path of /library, and for getting all books from the library, the sub-resource is books. I've tried every combination of the url below,
http://localhost:8080/john-[app|ear|ejb|web]/rest/library/books
all to no avail. every call results in a 404 error, and the only time i got ANYTHING is when i tried john-web combination, it threw some ugly exception in the browser. so the questions is with a rest service living inside an ejb module within an ear, what should the url be given the above information. nothing i've tried
seems to work!??
I've not included any code samples to try and keep the explanation short -- i didn't want to include every java file in my little project, but can add anything as requested.
Thanks,
JG
Related
I have a WebAPI .NET Framework 4.8 application which needs to make a RESTful GET request to another, third-party web service using a specific cipher. I found a code sample using the CurlThin NuGet packages in a response to this question, and then perused the little documentation on CurlThin I could find, along with taking a peek at the open source library code on GitHub. All examples and documentation talk about the need for an initial call to
CurlResources.Init();
This call only needs to be made a single time at the initialization stage to copy the appropriate DLLs to the application output folder.
I placed this call in my web app's Application_Start method, but cannot get past a NullReferenceException:
I fully expect that I am overlooking something simple that's been staring back at me for hours. Any guidance would be much appreciated.
I am doing the following:
porting several legacy applications from WebLogic to JBoss EAP 7. Some of the components being ported are EJBs. Others are servlet apps that invoke these EJBs. These EJBs are deployed in ejb-jars. I know that I could wrap this whole thing into a big EAR file but we don't want to do that. The servlets and the EJB jars need to be separately deployable components.
Then there is the logging setup. We are using log4j2 and we want to keep independent of the JBoss logging setup. I have created a JBoss module that contains all the log4j2 jars with the proper dependencies, and logging works.
The servlet runs and logs, invokes the EJBs and they work.
The only problem is how to configure the EJB's logging. In a Web App like the servlet, it's easy, just specify the log4j logging configuration file in web.xml. What's the analog for an ejb jar? I couldn't think of a way.
I tried the following: Add a logger/appender to the configuration of the servlet app for the EJB package and specify a new file. It doesn't work. The new logfile does get created but nothing gets written to the logfile. There should be output, but there isn't, so evidently when the EJB runs, its LogManager is not using the configuration specified in the servlet.
What is the right way for specifying a log4j2 configuration in an EJB deployed in an EJB jar on JBoss EAP7?
I had previously posted in this space a solution involving use of the #postConstruct and #preDestroy methods to initialize and shut down LoggerContext objects.
This plan fell apart when I tried to extend it to stateless session beans. It worked okay for Stateful Beans. Or so I thought. Eventually I found an Oracle document on EJB Restrictions which exposed the weaknesses in what I was doing. My "solution" included a non-final static LoggerContext member of the EJB class. I found a way to make it final, which did allow the stateless case to work. But I was increasingly dissatisfied with my approach. Even in the stateful case, I found issues that might bite me later in a clustered environment.
What I now come to believe is that I should not do what I was trying to do.
I can't even imagine the complexity of what a static final LoggerContext would look like if an EJB were distributed to another machine in the cluster. Objects like LoggerContext don't belong as members, static or not, of container-managed objects like EJBs.
It's not even clear that EJBs are the right implementation technology for what I am trying to build. My use cases are not really transactional so the case for EJB implementation is not strong so one possible path leads away from EJBs altogether.
The real message is that if EJBs or other container-managed components are indicated, it's probably best to use the container-provided logging system. I like log4j2, but until JBoss supports it, it's best to stick with container-provided log4j1 or some other framework.
I have a large number of services that my team are building and the auto-generated metadata is getting a bit unmanageable. To combat this, I created a project as a nested site (or sub-site) of the root. This works fine on my IIS local, but doesn't seem to work on a server-based IIS. Is it possible to get URLs like the following:
- http://server/WebServices [Root Project]
- http://server/WebServices/Project1 [Sub Project 1]
- http://server/WebServices/Project2 [Sub Project 2]
I know that using the routes in the AppHost I can get this effect but the resulting metadata is starting to get huge as they're all in one site. What I want is to be able to manage separate services in separate projects and have them come out in a hierarchy similar to above.
Look into the implementation of Routes.AddFromAssembly() extension method which goes through all the services are registers routes with the following conventions:
/{requestDto}
/{requestDto}/{Id}
On each of the HTTP Verbs that are implemented.
You should be able to implement your own conventions using a similar approach.
My company is redoing our website over the next few months, going from a ColdFusion website to one written in Java. I am just learning Java and I am curious as to how I can set application scope variables in a Java web application. ColdFusion has the application.cfm file that holds variables that are accessible by all ColdFusion pages/components within the app. Java obviously does not have a direct equivalent to that file, so I was wondering how to recreate something similar in Java. I want to have one central place that all jsp pages, servlets, classes, etc. in the webapp can access.
So what is the best way to do something like that?
Does anyone have any examples of something similar that they did?
Should application scope variables be placed in a class? an xml file? a jsp page? something else?
Is it even feasible to have application scope variables a in java webapp?
Example:
It would be a place that holds say the path to an images folder, so in individual JSP pages or classes or whatever would need acces to that images folder, you could reference the application scope variable for that path instead of writing it out in each place. Then if for some reason we needed to move the location of that images folder, we would just change the path variable in the one location and not have to update 20 places that reference that images folder.
I have had trouble finding any information on this type of thing in my research online, which is why I am asking about it here. I know it is a lot to ask for an explanation to this type of thing, but I figured I would ask and see what type of responses I could get.
Thank you for any help you can provide about this topic.
The equivalent is probably the ServletContext
In your controller servlet:
ServletContext context = request.getSession().getServletContext();
Just like in the session object you can store attributes in the servlet context as well
context.setAttribute("someValue", "aValue");
Object attribute = context.getAttribute("someValue");
If you're starting out with Java and you have a non-trivial application to build, I would recommend using a popular framework like Spring or Struts
We have some Modules which have their own remote objects configured in remoting-config.xml. Each is packaged and deployed as separate web archives (WAR). For ex. Module1.war, Module2.war.
We are trying to integrate them in a flex application which is deployed in a separate web app. For ex. MainApp.war.
The remote objects work fine when invoked from within Module1.war and Module2.war. But the java remote objects are not getting invoked when called from the main flex application MainApp.war.
I have looked at Flex Developers guide and flexcoders Yahoo group.
How are you configuring your remote objects? Are you passing the path to services-config.xml in the "-services" compiler flag? If you are, I would avoid doing this, since it doesn't give you much flexibility in the location of your services endpoints.
Christophe Coenraets has a great article on best practices for configuring RemoteObject and other data access classes in Flex. The general idea is to externalize the URLs into an XML configuration file, load that with an HTTPService when the application starts up, then use the URLs to configure your Channel/ChannelSet which are binded into the RemoteObject. Full article is here:
http://coenraets.org/blog/2009/03/externalizing-service-configuration-using-blazeds-and-lcds/