Stop one of Http method Online - java

I have a couple of http methods in my application which is hosted in JBoss.
And Now I am trying to find some kind of hot-way to disable one of them,like click a button in a certain of page or calling a certain of http method. What i means of 'disable it' is making any web client which intends to send get/post request to it will go to failure . Maybe we can say the web client will got a http 404 response.
Can anybody give me some solutions? Thanks.

I think JMX would be appropriate for this situation.
You can pretty easily create an MBean (Managed Bean, a component of JMX) with Managed Attributes corresponding to boolean's for each of the endpoints you want to be disable-able. Registering it is the hard part, but there are libraries out there that make working with JMX easier. Spring has good support for setting up and working with MBeans.
As far as a JMX client goes, I usually use VisualVM, which ships with the JDK. From it, you can invoke methods on your MBeans at runtime, or even change their properties.

Related

How can I identify the client or caller of an EJB within the request?

I have a system where several (20 or so) web app servers (hosting a website) talk to the same 2 - 4 EJB servers (through a VIP). I'd like to know if it is possible to identify which one of those app servers generated a specific request.
For example: Website example.com works by sending HTTP requests to any of 20 app servers to handle the request. These servers are named (internally) app01 through app20. It is ensured that all requests with the same session ID will be routed to the same app server, thus enabling us to logically track all requests from a single user. Some requests will need some extra data not available directly, for which there is an EJB (2.1) application on another cluster of 3 servers, named ejb01 to ejb03. Connections to the EJB servers are made through a VIP (ejb00), which routes the requests round-robin style to the three EJB serves.
Within the logging (we use Apache Log4J) of the EJB servers, it would be really nice if I could identify which of the 20 app servers a request originated from. The alternative is checking the logs on each server separately - but I don't have a good way to grep through the logs on 20 different boxes.
My question is: is this possible within Standard EJB? I'd be willing to do something non-standard, if there was nothing else, but it's gotta be reliable and work on my system. We use Weblogic 11g, both for the web-app and the EJB servers.
I've seen suggestions to pass the identity of the caller as a parameter, but that would mean an extra parameter for each of 20+ EJB methods, and that's rather unwieldy.
Any solutions, anyone?
There is no standard solution. There was a proposal in JSR 149, but it was withdrawn. Adding an extra parameter to the remote methods is probably your best option. If you're using RMI remote, you might be able to write an ORB interceptor to add a custom context on the client side, receive it on the server side, and set a thread local around the method invocation on the server.
WebSphere Application Server has a non-standard solution called work areas, which does work for remote EJB.
I am not familiar with WebLogic, so I don't know if they have a similar solution. Searching for similar terms finds a WorkContextMap that looks similar, but I don't know if it works for remote EJB since all the examples I can find are for webservices.

2 Tomcat Instances - Communication between 2 applications

I have one webserver with 2 instances of tomcat running. On each tomcat instance I have multiple web apps or web services.
What is the best way to call a function (or trigger some event with parameters) from a webapp of the first tomcat server on a webapp running on the second tomcat server. If it's for example a call using a url with parameters then this call should be secure and not accessible from outside the server.
I've read something about getting the servlet context but is this possible on different tomcat instances? Im thinking that this is only possible with webapps running in the same instance.
I dont want to use CORBA, RMI or SOAP because this is a bit oversized for my problem ... that is what Im thinking :)
Code examples are welcome. Thank you!
The ServletContext is only valid within the same container and can't be shared between two JVMs. The simplest method to do what you're asking is to just use some variety of RPC between the two containers, and RMI doesn't seem like particular overkill. The other usual approach would be a simple HTTP Web service (note the lowercase "s") that invokes your logic in the receiving container.
Spring's HTTPInvoker is great for this. You can use a Java interface, and your code on each instance doesn't need to know the call is remote - it just calls Java methods.
For security, you can use the Sun HTTP server on a different port (instead of using a servlet within Tomcat) and listen only on localhost.
Have a look here
http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/remoting.html#remoting-httpinvoker
Use Simple REST services , not that much secured .

Embedded Jetty 9 HTML form sending data to application

I have created a simple login form using a servlet receiving information via HTTP POST trough an SSL connection on an embedded Jetty 9 server. The servlet receives the information as it's supposed to but I've been unable to find out how the servlet should communicate with the application jetty is running in.
The documentation for using Jetty in embedded mode seems to be very lacking and I havn't had any success doing a general search on the subject either. In short:
How do I get information from an HTML login form hosted on an embedded Jetty 9 server to the application Jetty is running in?
For the embedded mode examples, see the git repository.
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/examples/embedded/
For communicating out from the servlet to your application, you have many options, but they all wind up being event driven at the application side.
2 Example Options (there are many ways to accomplish this, this is just two quick examples):
Simply call methods in MyApplication singleton.
Put a reference to the MyApplication object into a static MyServlet.app field.
Call your app.somethingHappened() in the servlet when you want to communicate what has happened.
Listener metaphor.
Create MyServletListener with the methods representing the events you want the application to know about
Make MyApplication implement MyServletListener
In MyServlet.init() grab a reference to MyApplication
In the various MyServlet.doGet() or MyServlet.doPost() style handling calls, call the appropriate MyServletListener events for the action you want to communicate.
Note: these are naive examples, and don't deal with threads and threading.
But that's another topic entirely.

Best architecture for applications in GWT

I'm starting to study GWT now, and have a very general question, I could maybe teach myself with a little more experience, but I don't want to start it wrong, so I decided to ask you.
I always develop using JSF, having separate packages for beans, controllers and managedbeans.
However, as the GWT uses RPC, I will not have managedbeans, right?
So, GWT automatically handles user session for me, or do I have to do it myself?
What is the best package structure for the project?
It is best to use RPC, or create a webservice and access the webservice in GWT?
It's hard to host the application on a tomcat server?
Is there a test saying which server is faster for GWT?
Thank you.
However, as the GWT uses RPC, I will not have managedbeans, right?
True, GWT RPC uses POJOs.
So, GWT automatically handles user session for me, or do I have to do it myself?
GWT is pure AJAX APP - client code (normally) runs in one browser window (similar to gmail) and does not reload the web page. This means that the application state is always there - no need for sessions (as a means of saving state). You still might need sessions for user authentication, but this is usually handled by servlet container.
What is the best package structure for the project?
Three packages: client, server and shared. Client for GWT client code, server for server (also RPC) code and shared for POJOs that are used by both client and server.
It is best to use RPC, or create a webservice and access the webservice in GWT?
Go with GWT-RPC or (better, newer) with RequestFactory.
It's hard to host the application on a tomcat server?
It's straightforward: GWT client code is compiled to JS/html and is hosted as any static content. RPC server code is just Servlets - normal web.xml registration.
Is there a test saying which server is faster for GWT?
No clue, but IMHO does not matter, because most of the latency will come from database and network.
Also have a look at http://code.google.com/p/gwt-platform/
This framework is really great and follow all suggested best practices(e.g. MVP) by google and give you as well great support for gin, gwt dispatcher, website crawling, history with tokens, code splitting via gwt async etc.
If you want to set up a good project structure try to use the maven gwt plugin(http://mojo.codehaus.org/gwt-maven-plugin/) it helps you a lot with setting up an initial structure and manage your build process.

Java HTTP Proxy

I am working on a project where we'd like to pull content from one of our legacy applications, BUT, we'd like to avoid showing the "waiting for www.somehostname.com/someproduct/..." to the user.
We can easily add another domain that points to the same server, but we still have the problem of the someproduct context root in the url. Simply changing the context root is not an option since there are hundreds of hard coded bits in the legacy app that refer to the existing context root.
What I'd like to do is be able to send a request to a different context root (Say /foo/bar.do), and have it actually go to /someproduct/bar.do, (but without a redirect, so the browser still shows /foo/bar.do).
I've found a few URL rewriting options that do something similar, but so far they seem to all be restricted to catching/forwarding requests only to/from the same context root.
Is there any project out there that handles this type of thing? We are using weblogic 10.3 (on legacy app it is weblogic 8). Ideally we could host this as part of the new app, but if we had to, we could also add something to the old app.
Or, is there some completely different solution that would work better that we haven't though of?
Update: I should mention that we already originally suggested using apace with mod_rewrite or something similar, but management/hosting are giving the thumbs down to this solution. :/
Update 2 More information:
The places where the user is able to see the old url / context root have to do with pages/workflows that are loaded from the old app into an iframe in the new app.
So there is really nothing special about the communication between the two apps that client could see, it's plain old HTTPS handled by the browser.
I think you should be able to do this using a fairly simple custom servlet.
At a high level, you'd:
Map the servlet to a mapping like /foo/*
In the servlet's implementation, simply take the request's pathInfo, and use that to make a request to the legacy site (using HttpUrlConnection or the Apache Commons equivalent).
Pipe the response to the client (some processing may be necessary to handle the headers).
Why not front weblogic with Apache.
This is a very standard setup and will bring lots of other advantages also. URL rewriting in apache is extremely well supported and the documentation is excellent.
Don't be put off by the setup it's fairly simple and you can run apache on the same box if necessary.
Using Restlet would allow you to do this. The Redirector object can be used. See here and here for example.
If you instead serve out a JSP page you can use the tag to do the request server side.
Then the user will not even know that the resource was external.
http://java.sun.com/products/jsp/syntax/1.2/syntaxref1214.html
a bit more context for the API the client is working against would help here to give a solution that could work. Are you trying to provide a complete new API totally different from the legacy Java EE app? What artifact is serving the API (Servlet, EJB, REST service)?
If you have the API provided by a different enterprise application then I suppose you simply use a Pojo class to work as a gateway to the legacy app wich of cause can then be reachable via another context root than the new service app. This solution would assume you know all legacy API methods and can map them to the calls for the new API.
For a generic solution where you don't have to worry about what methods are called. I am curious if the proxy approach could really work. Would the user credentials also be served correctly to the legacy system by URL re-writing? Would you have to switch to a different user for the legacy calls instead of using the origin caller? Is that possible with URL re-writing. Not sure if that could work in a secure context.
Maybe you can provide a bit more information here.

Categories