Know any embeddable NNTP servers? - java

I'm writing a bit of code that uses the Apache NNTP Client to fetch articles from an NNTP server. Once the code ships, we'll use an Apache James server to read the articles from. But to test the code, I'm looking for an embedded Java NNTP server, so I don't have to mock every server call. Are there any good ones I can use? Google seems to have failed me.
My requirements are as follows:
A server I can start from within the code.
Tests can be run out-of-the-box on different machines without additional setup. (Once I commit the code, a remote build machine needs to be able to run the test cases).
Any other inspired suggestions are also welcome.

There is sonews, which seems to be active and supports a suprising lot of database backends. I didn't look at it further, so I can't tell if you can embed it.

Related

Manage running Java apps remotely

We have several Java standalone applications (in form of Jar files) running on multiple servers. These applications mainly read and stream data between systems. We are using Java 8 mainly in our development. I was put in charge recently. My main function is to manage and maintain these apps.
Currently, I check these apps manually by accessing these servers, check if the app is running, and sometimes run some database queries to see if the app started pulling data. My problem is that in many cases, some of these apps fail and shutdown due to data issue or edge cases without anyone noticing. We need some monitoring and application recovery in place.
We don't have docker infrastructure in place. We plan to implement docker in the future, but for now this is not an option.
After research, the following are options I thought of or solutions I tried:
Have the apps create a socket client which sends a heartbeat to a monitoring app (which needs to be developed). I am keeping this as my last option.
I tried to use Eclipse Vertx to wrap the apps into Verticles. Then create a web view that can show me status and other info. After several tries, the apps fail to parse the data correctly (might be due to my lack of understanding to Vertx library).
Have a third party solution that does this, but I have no idea what solutions are out there. I am open for suggestions.
My requirements are:
Proper monitoring of the apps running and their status.
In case of failure, the app should start again while notifying the admin/developer.
I am willing to develop a solution or implement a third party one. I need you guidance on this.
Thank you.
You could use spring-boot-actuator (see health). It comes with a built-in endpoint that has some health checks(depending on your spring-boot project), but you can create your own as well.
Then, doing a http request to http://{host}:{port}/{context}/actuator/health (replace with yours), you could see those health checks status and also use the response status code to monitor your application.
Have you heard of Java Service Wrappers? Not a full management functionality, however it would monitor for JVM crashes and out of memory conditions and restart your application for sure. Alerting should also be possible.
There is a small comparison table here: https://yajsw.sourceforge.io/#mozTocId284533
So some basic monitoring and management is included already. If you need more, I suggest using JMX (https://www.oracle.com/java/technologies/javase/javamanagement.html) or Prometheus (https://prometheus.io/ and https://github.com/prometheus/client_java)

LDAP Server front-end Java library

I've been asked to look into adding an LDAP interface to an existing Java web application - that is, to make it possible for LDAP clients to connect to the application as if it's an LDAP server. I could write code to listen on a dedicated port and implement the LDAP protocol, and hook that into the existing database... but I'd have to understand the protocol first and then there are potential security issues if I write that from the ground up (not to mention the time it could take).
What I'm looking for is a library of existing code - something that handles the ports and protocols, and lets me focus on writing just the back end. There are plenty of client-side libraries out there, as you'd expect, but I've had no luck in finding something to help with server-side development. So the question is, does anyone here know of such a library that would help with this?
Yes you will most probably find many more client implementations than server, however LDAP is a request response protocol, so with a bit of playing around you should be able to use the same classes and their serialization capabilities. Instead of sending the request you would be receiving it, and responding with the response you would otherwise expect from the client.
You could look at the Apache Directory. https://directory.apache.org/api/
It has an embedded directory server project as part of it, which claims to be extensible and embeddable in your application. https://directory.apache.org/apacheds/
So maybe that could be the answer to your needs.

How to implement a socket for a Java EE application in Tomcat

I've a Python application for data analysis and a Java EE application for web monitoring. Now I need to establish a durable communication between them, in order to transfer the analysis result from python to java.
Since both of the applications are located at the same server, I want to implement a TCP socket. As for the data volume, there're about 10 sensors' data transferred per second. I'm using Tomcat 8.0 for Java EE and a simple script for python. So my questions are :
Is socket implementation a good idea ?
If yes, how to implement it, can somebody give me a tutorial or example ?
If not, what should I do next ?
Additional information
I saw a related question on StackOverflow How to serve a socket from a Java EE application, there're some propositions :
Implement a Connector (JCA). But I think the target runtime is JBoss rather than Tomcat.
Implement a Java Naming and Directory Interface (JNDI). That's what I'm trying as you can see as my previous question Why JNDI resource can only be called once in Tomcat? People use JNDI for using resources, e.g. db connection. So I'm not sure if it's a good way for realtime communication. And I've met many troubles by learning it.
I thought about web-socket. But does it mean I need a python server as well ?
I believe there is a hundred way to do it to share data between these technologies. But for Java you should keep it simple. In Tomcat you don't need to write a socket implementation, you just need a basic Servlet implementation. So basically for your questions.
Is socket implementation a good idea ?
Shortly NO.
If yes, how to implement it, can somebody give me a tutorial or
example ?
Already answered NO.
If not, what should I do next ?
Write a basic servlet application who listen an server url address. Your phyton script is just a client. In phyton site you just send a POST request to servlet url and in Java side get the request read your data and process it. You can start to learn Servlet from Mkyong.

Best Java supported server/client protocol?

I'm in the process of writing a client/server application which should work message based. I would like re-use as much as possible instead of writing another implementation and curious what others are using.
Features the library should offer:
client and server side functionality
should work message based
support multi-threading
should work behind load balancer / firewalls
I did several tests with HTTPCore, but the bottom line is that one has to implement both client and server, only the transport layer would be covered. RMI is not an option either due to the network related requirements.
Any ideas are highly appreciated.
Details
My idea is to implement a client/server wrapper which handles the client communication (including user/password validation) and writes incoming requests to a JMS queue:
#1 User --> Wrapper (Check for user/password) --> JMS --> "Server"
#2 User polls Wrapper which polls JMS
Separate processes will handle the requests and can reply via wrapper to the clients. I'd like to use JMS because:
it handles persistence quite well
load balancing - it's easy to handle peaks by adding additional servers as consumer
JMSTimeToLive comes in handy too
Unfortunately I don't see a way to use JMS on it's own, because clients should only have access to their messages and the setup of different users on JMS side doesn't sound feasible either.
Well, HTTP is probably the best supported in terms of client and server code implementing it - but it may well be completely inappropriate based on your requirements. We'll need to actually see some requirements (or at least a vague idea of what the application is like) before we can really advise you properly.
RMI works nicely for us. There are limitations, such as not being able to call back to the client unless you can connect directly to that computer (does not work if client is behind a firewall). You can also easily wrap your communication in SSL or tunnel it over HTTP which can be wrapped in SSL.
If you do end up using this remember to always set the serial version of a class that is distributed to the client. You can set it to 1L when you create it, or if the client already has the class use serialver.exe to discover the existing class's serial. Otherwise as soon as you change or add a public method or variable compatibility with existing clients will break.
static final long serialVersionUID = 1L
EDIT: Each RMI request that comes into the server gets its own thread. You don't have to handle this yourself.
EDIT: I think some details were added later in the question. You can tunnel RMI over HTTP, then you could use a load balancer with it.
I've recently started playing with Hessian and it shows a lot of promise. It natively uses HTTP which makes it simpler than RMI over HTTP and it's a binary protocol which means it's faster than all the XML-based protocols. It's very easy to get Hessian going. I recently did this by embedding Jetty in our app, configuring the Hessian Servlet and making it implement our API interface. The great thing about Hessian is it's simplicity... nothing like JMS or RMI over HTTP. There are also libraries for Hessian in other languages.
I'd say the best-supported, if not best-implemented, client/server communications package for Java is Sun's RMI (Remote Method Invocation). It's included with the standard Java class library, and gets the job done, even if it's not the fastest option out there. And, of course, it's supported by Sun. I implemented a turn-based gaming framework with it several years ago, and it was quite stable.
It is difficult to make a suggestion based on the information given but possibly the use of TemporaryQueues e.g. dynamically created PTP destinations on a per client basis might fit the problem?
Here is a reasonable overview.
Did you tried RMI or CORBA? With both of them you can distribute your logic and create Sessions
Use Spring....Then pick and choose the protocol.
We're standardizing on Adobe's AMF as we're using Adobe Flex/AIR in the client-tier and Java6/Tomcat6/BlazeDS/Spring-Framework2.5/iBATIS2.3.4/ActiveMQ-JMS5.2 in our middle-tier stack (Oracle 10g back-end).
Because we're standardizing on Flex client-side development, AMF and BlazeDS (now better coupled to Spring thanks to Adobe and SpringSource cooperating on the integration), are the most efficient and convenient means we can employ to interact with the server-side.
We also heavily build on JMS messaging in the data center - BlazeDS enables us to bridge our Flex clients as JMS topic subscribers. That is extremely powerful and effective.
Our Flex .swf and Java .class code is bundled into the same .jar file for deployment. That way the correct version of the client code will be deployed to interact with the corresponding middle-tier java code that will process client service calls (or messaging operations). That has always been a bane of client-server computing - making sure the correct versions of the respective tiers are hooked up to each other. We've effectively solved that age-old problem with our particular approach to packaging and deployment.
All of our client-server interactions work over HTTP/HTTPS ports 80 and 443. Even the server-side messaging push we do with BlazeDS bridged to our ActiveMQ JMS message broker.

Microsoft Reporting Services WebServices and Java

Has anyone successfully implemented a Java based solution that uses Microsoft SQL Server 2005 Reporting Services? Reporting Services comes with a set of Web Services that allow you to control the creation of a report, execution of a report, etc and I am just starting development on a POC of this integration. A couple of choices I have yet to make is whether I want to use Axis2 for the wsdl-to-java functionality or use WebLogic's clientgen (wsdl 2 java) solution. I guess I can also use JAX-WS and wsimport. Before I dive into this, I wanted to see if anyone was doing this successfully with one of the many options available.
In the past, I've had a few issues on how null/blank/empty's are handled between .NET and Java web-services and I just wanted to see if this had come up as an issue with SSRS and Java integration. Thanks
My experience with RS would lead me to suggest you go with just about anything else. I think the web services portion would work fine but I'd be concerned about how RS manages memory and how many reports you need to be running at once before making any decisions. I'm fighting with memory management problems today with RS and even on top of the line hardware it's hard to run large reports (large number of rows returned and a wide result set).
That being said if you think RS can handle your usage then it might be good. The development environment is sort of nice and it's easy to understand and lay out reports. The table layout paradigm it has is pretty good.
I just wanted to come back and answer my own question. I started with Axis2, Apache's implementation of SOAP. After generating the client using WSDL2Java, I was able to successfully invoke Microsoft Reporting Services WebService and generate reports, output in Excel, PDF, CSV and other formats. In my case, I also used Axis2 or HttpClient's NTML authentication mechanism to have my application automatically 'log-in' using credentials from Active Directory and generate and distribute reports to many users.
we've successfully implemented that: JBoss 5 -> IIS proxy -> MS Reporting Services 2008 (via webservice).
There are few pitfalls: MS RS 2008 does not support 'Anonymous' access anymore (2005 does), and does enforce using NTLM authentication. That is still a challenge in Java world, there is no good NTLM library available.
To overcome that, we've implemented trivial proxy (IIS7 + ashx) that does NTLM authentication on RS (user/password hardcoded) and allows Anonymous access for JBoss (by simply rewriting http response).
Works ok :)
Cheers
P

Categories