Is there a way I can query the list of deployed applications in a Jetty 8 server in code? For instance, can I inject the DeploymentManager and query it?
From a handler, you should have a reference to the Server object so you should be able to dig around for it from there, or just pass in reference to it when you create it and are knitting things together. Handlers are simple to write and wire up. Look at the StatisticsHandler usage as an example if you like.
From a servlet that is not really appropriate since there is a webapp classloader and webapps are classloader isolated for a reason.
Related
with the CN1 web service wizard, I created a working server project that I run on my local Tomcat installation. in addition, the CN1 project has the webserviceproxy.java class that I use to call the web services. so far so good.
During development, there now is the need to create a new function within the webservice that I did not previously think of. So instead of recreating my whole server using the wizard, I thought I simply add some code into the files that were created.
On the client side:
WebServiceProxy.java - add WebServiceProxyCall.WSDefinition and add the function call in sync and async fashion. the arguments and return type matches the definition.
On the server side:
WebServiceProxyServer.java
- add the function definition with the required functionality (this works as I have it debugged it locally on the server side).
CN1WebServiceServlet.java - add definition and add the if statement matching the service name.
when debugging the server and calling the service from the client, it does not reach the breakpoint of the doPost method, so something is terribly off.
What else do I need to change when manually adding a new webservice function? Or is this so complicated that I should better use the web service wizard, create the new server from scratch and copy all the other functionality from my old server to the new one?
Thanks and best regards
There is currently no way to do this seamlessly since the generated protocol is binary for fastest protocol performance.
The solution is to generate a new class we usually use the notion V2, V3 onward. That way the first webservice is still 100% compatible to devices in production and you can create a new "more correct" protocol for the newer devices. The implementation classes can derive from one another to increase code reuse.
I have a web application mostly written by others based on JSF 2, Mybatis, Spring 3 and tens of other libraries, running on Weblogic, it works and now I have to create a distinct command line application to schedule the running of some tasks already present in the web app.
I added a class with a main method in order to maintain only one codebase with a different build process to generate an executable JAR instead of a WAR. Using Spring's ClassPathXmlApplicationContext I managed to recreate the web application context, access the database beans and use them, but I'm stuck with a WSRR call which fails.
The commands:
GraphQuery graphQuery =
(GraphQuery)DataFactory.INSTANCE.create(TypeConstants.SR_URI, TypeConstants.TYPE_GRAPHQUERY);
graphQuery.setQueryExpression("/WSRR/GenericObject[#CFT_APPLIC='DS" + param + "']");
fail with a long stack, having the root exception
Caused by: java.lang.NullPointerException
at java.util.ResourceBundle.getBundle(ResourceBundle.java:960)
at com.ibm.ws.webservices.engine.resources.ProjectResourceBundle$Context.loadBundle(ProjectResourceBundle.java:474)
at com.ibm.ws.webservices.engine.resources.ProjectResourceBundle.getBundle(ProjectResourceBundle.java:372)
at com.ibm.ws.webservices.engine.resources.ProjectResourceBundle.getBundle(ProjectResourceBundle.java:341)
at com.ibm.ws.webservices.engine.resources.MessagesConstants.<clinit>(MessagesConstants.java:93)
I found that some classes and configurations are provided at runtime by the application server, and have no idea about how to replace them outside the application server.
The IBM redbook says (pages 120-121) that is possible to access a web service using a Java client, but requires a suitable EJB runtime.
How can I replicate needed EJB parameters outside the application server? I tried to use the Eclipse debugger to follow the execution of the application and extract them, but it fails, probably because the classes are loaded by Weblogic classloader.
I'm developing a web service in Java EE using Apache Tomcat and so far I have written some basic server side methods and a test client. I can successfully invoke methods and get results but every time I invoke a method, the server constructor gets called again, and I also can't modify the instance variables of the server using the set methods. Is there a particular way to make my server stateful without using JAX-WS or EJB #Stateful tags?
This is a little bit of misconception here. The stateful EJB would maintain session between one client and server, so still the EJB state wouldn't be shared between various clients.
You can expose only stateless and singleton EJBs as a JAX-WS web service.
The best option is to use database for storing all bids and when the auction is finished choose the winning one.
If you want to use a file it is fine, as long as you like to play with issues like:
synchronizing access to that file from many clients
handling transactional reads and writes
resolve file corruption problems
a bunch of other problems that might happen if you are sufficiently unlucky
Sounds like a lot of work, which can be done by any sane database engine.
I have a clojure/ring project that has two distinct app/handlers running on different ports (one for an api and one for a web frontend). They share a lot of code, but each has its own namespace where it does all the work particular to that interface. Now I want to deploy this as a servlet running in tomcat or something similar (really it needs to work in any servlet container). I am having trouble though because it seems like lein-ring makes the assumption that there will be only one handler in the servlet. For instance, in my project.clj I have this line:
:ring {:handler caribou.api/app
:servlet-name "caribou"
:init caribou.api/init}
This is great for the api, but now what about the frontend? Do I need to make another project that includes this one so that it can have its own handler and servlet? Does a servlet always run on one port?
There are two things I'm not sure about basically: I am not coming from a java background so I'm not sure what is going on with the servlet approach and what limitations it has, and I am unclear on how exactly clojure translates into the servlet paradigm enough to structure this project in a general way.
Any help is appreciated, thanks!
All servlets in the same container are being served from the same server and therefore the same port. Usually you identify different servlets by giving them different URI prefixes such as /servlet1 or /my/servlet.
I don't know if there is anything preventing you from creating separate servlets with Ring, but in general it doesn't seem like a good idea if your entire app is Clojure-based. At the very least, as you have pointed out, the lein-ring plugin enforces that only one servlet is used for the web application.
One thing you could do is create a parent handler that delegates to either the app or API handlers based on the URI. This essentially gives you control with out needing to delegate the logic to the Servlet API.
How can I configure jetty6 to start a non web application (not a servlet)? My Java app is a rabbitmq consumer listening for ampq messages over tcp. I could have jetty init() call my Main entry point. Is there a better way to do this?
Why not provide a trivial servlet that provides an init() method and invoke your application from within there ? i.e. wrap it within a servlet wrapper that does next to nothing.
It doesn't have to respond to GETs/POSTs etc. Although you'd probably find that useful and report application status via a simple HTML page.
You'll need to provide a little more info if you want a complete answer but there are a few approaches I could suggest, that will give different behaviours (you'll need to pick the right one for your use case)
1. Just put the right code in your jetty.xml file. The XML file is a pretty complete execution language, so you can simply call methods on objects. An appropriate static method, along with a <call> tag should do the trick
The downside, is that you're not really getting any thing from Jetty - you just tying your startup method into the same startup process that Jetty uses.
2. Build a component that implements the Jetty LifeCycle interface (your best option is to extend AbstractLifeCycle), and then call Server.addLifeCycle()
That will allow you to open your port when Jetty starts up, shutdown cleanly when Jetty, stops, etc.
But all you get is that lifecycle. You don't get anything around deployment.
3. Same as option 1, but put it in jetty-web.xml (or jetty-env.xml), which allows you to tie it into the deployment of a WAR file.
It doesn't buy you much over option 1, but if you're trying to deploy an application to an existing Jetty setup, it might help.
4. Same as option 1, but using jetty-web.xml. I'm not sure how well that would work, since I don't think you can attach a LifeCycle to a WebAppContext, but it might work OK - you'd need to do more investigation on that.
5. As per Brian's solution, simply write a servlet with an init() method, and initialise-on-startup, then don't map it to any URLs. Put a call to your entry method inside that init.