Maven plugin that runs a "web proxy" for integration tests - java

This might be confusing, so bear with me.
I am not interested in running maven behind a proxy. I understand how to configure maven, eclipse or the JVM itself to get web access via proxies.
However, in my project, I have a component that will retrieve the contents of a given URL and analyze it. It uses Apache Http Components underneath, coated with a little predefined configuration and error handling (really just a wrapper to hide boiler plate code). Since apache-httpcomponents itself can make use of proxies, my component will accept a proxy configuration that can be passed to apache-httpcomponents.
Does anyone know of any proxy plugin that allows this type of integration test, like "maven-simpleproxy-plugin" or anything like that?
I want to test the ability of my component to run well behind a proxy. I imagine that I would need to run some sort of plugin which will start up a dummy proxy server along with maven-embedded-glassfish-plugin. I can host a dummy content inside glassfish and make my component try to access it via this "maven-simpleproxy-plugin" instance... thus allowing me to test the component's ability to handle its proxy configuration correctly.
Does anything like that exist?

I would use maven exec plugin to start up the proxy server you want to test. Then write a script which is called at the post-integration-test phase that shuts the proxy server down. Then you are testing through the same proxy server type as your production environment.

I think you are looking for MockServer. It looks pretty active on github with 1.000+ stars and 25+ contributors and can do the following, as explained on their website:
MockServer Proxy can:
proxy all requests using any of the following proxying methods:
Port Forwarding
Web Proxying (i.e. HTTP proxy)
HTTPS Tunneling Proxying (using HTTP CONNECT)
SOCKS Proxying (i.e. dynamic port forwarding)
verify requests have been sent (i.e. in a test assertion)
record requests and responses to analyse how a system behaves
Regarding the different deployment/usage options you've been asking for, let me again copy from their website:
The MockServer and MockServer Proxy can be run:
via a Maven Plugin as part of a Maven build cycle
programmatically via a Java API in an #Before or #After method
using a JUnit #Rule via a #Rule annotated field in a JUnit test
from the command line as a stand-alone process in a test environment
as a deployable WAR to an existing application server
as a Grunt plugin as part of a Grunt build cycle
as a Node.js (npm) module from any Node.js code
as a Docker container in any Docker enabled environment
ps: I'm not affiliated in any way with the project

Related

setup proxy to docker containers from java application

Need help with technical solution.
I have java (spring boot) application which may start docker container. Application assign ID and port to each container. That port is used as separate UI. ID is used to stop container.
For now, application work with 443 secured port, while each container open it own port in a range 19000-19100.
Is it possible to setup something like proxy server in application, verify request and then forward it to container?
Let's say, instead of myhost.com:19000 I want to use myhost.com/container/{containerId}?
I'm thinking about rest template or feign client, but not sure how it will behave with websockets. Any thoughts? Existing tools or libraries?
Take a look at Spring Cloud Netflix Zuul.
I am working on a project where we use this to proxy requests from frontend to a service which handles persistence processes.
Maybe it will help you achieve what you are looking for.

How to verify that a spring-boot web server is running

I am writing an integration test for a spring-boot web server
I want to use junit-jupiter (junit5) to check if the server is running using Assumptions.assumeTrue so that the test do not fail if the server is not running...
There seems not to be any API support for such operation, but can it be achieved in some other way? Pinging the server?
You could make use of the actuator module in spring boot. It will provide you with a health check URL and you could make a call to this URL and verify that it returns healthy.
Now that that is out of the way, if you need the server to be running while running your tests, you should probably be using the spring boot test runner, instead of using the JUnit runner. In this case you could still mock some of your spring beans and achieve the same kind of test, but with a spring context running alongside your tests. The downside of this is the overhead of needing to spin up the spring context before running tests, but if you need to use the actual web server, then this is what you should be doing.

Use Jolokia to monitor JMX endpoint of webapp on same Tomcat server

Jolokia is uncharted territory for me, and after having read the documentation, I'm still not sure if it'll work with the scenario I have in mind.
Setup:
Tomcat application server (version ranges from 6.x to 7.x), usually on a Windows platform, occasionally a flavour of Linux.
Deployed third-party Java web application (SAP BusinessObjects) with JMX monitoring enabled (accessible through RMI).
Possible gotcha's:
The Java web application to be monitored is commercial and closed source, so modifications are not possible. The only thing that can be changed is the JMX port number
The JMX endpoint is a custom one, thus not the default jmxrmi endpoint.
The JMX connection requires authentication.
Goal:
What I'd like to do is to deploy the Jolokia WAR file onto the Tomcat server and then configure it so that I can read the MBean attributes from the other web application.
I would code the client myself using Python (version 3) and the Requests HTTP library.
I've been reading through the Jolokia documentation (again, I'm a complete newbie at this point), but can't figure out if this would be possible or not (as I can't seem to find where to enter the JMX/RMI url or the authentication information).
Questions:
Can I use the WAR agent for this setup?
If not, can you please explain why (so I can understand, not because I don't believe you). Also, is there another agent that's more suited for this scenario?
If yes, can you point me in the right direction how to configure the Jolokia to the web application to connect to?
First of all, Jolokia by passes the JSR-160 connector stuff completely, so there is no need for any JMX/RMI authentication. The whole purpose of Jolokia is to provide a bridge over HTTP/JSON to the internal JMX subsystem. Depending on the agent, you can secure Jolokia quite easily. For the WAR agent, securing is the same as for any Java EE web app: Setup some roles and users for tomcat (e.g. in tomcat-users.xml) and reference the role in the security contstraints within the jolokia.war's /WEB-INF/web.xml.
To your questions:
Yes, you can. If you don't have any specific authentication needs, simply drop the jolokia.war into tomcat's /webapps directory. I suggest to try this first before adding security. For deinstalling the agent, simply remove the war.
As an alternative, you could also use the JVM agent, which opens an own HTTP server on an extra port (default: 8778). More on this in the reference manual
There is no need for a dedicated connection to the web app since MBeans are registered globally and are accesible from anywhere in the JVM. A webapp should of course select carefully the management information it exposes. So, there is no extra step needed and you can access the MBeans for the WEB app directly (except when it does something unusual with Java security, but I don't think so).
To test the installation, simply connect to the Tomcat with your browser and the context /jolokia (e.g. "http://localhost:8080/jolokia"). You should see the version information about the agent itself.
The next step would be to explore the JMX namespace, either with the browser (and operation "list" like in http://localhost:8080/jolokia/list , but that's tedious) or with a client like j4psh or hawt.io. Hopefully you will find the MBeans of your webapp you are looking for.

Automated deployment of JavaScript project for different environments

I was looking for similar problems and, of course, there exists many but I would like to know if someone uses a similar project like us and how you have deal with it.
We are working on a project where:
- Client side is completely based on JavaScript, with Dojo Toolkit framework, which makes AJAX request to our server side.
- Server side based on Java+Spring+Hibernate which implements some REST API.
We are managin the two parts as different projects, that is, for the server side we are using maven and for each change our CI server runs tests.
The important step here is we can configura maven with profiles so the CI can create a package ready for pre-production or production environments using different property files.
The client side is a bunch (with a nice structure) of HTML, CSS and JavaScript files. Like the server side, on the client side we have property file to point the client to the right place (like the development server side).
The question is: which could be the best way on this scenario to automate the client side?development? I mean, run JavaScript tests on CI and autodeploy to the right environment using the appropriate property file.
Thanks.
While someone gives you a proper and complete answer you might want to have a look at a similar question I did. Javascript web app and Java server, build all in Maven or use Grunt for web app?
I am trying different options out there but most probably we will finish using Grunt for the client side. Maven exec to call it and build everything (client + server) with different profiles.

Reflection Difference Between Straight Java and Grails

I'm using a set of APIs developed internally by my company to communicate with some common central services in the organization. The APIs can be configured dynamically by runtime configuration to use several transport protocols as needed by the system.
The collection of internal APIs are coupled to the IBM WebService thinclient.jar to configure and call all the necessary web services. I got the standalone prototype working smoothly, but need to integrate the functionality into several other services that are being developed in Grails.
This is where things fell apart. In the code that I've written, we just call a factory method and use that to get a client session and then proceed with our business logic. Simple. Using the debugger and digging into the API getClient() call, I can see that this gets a generic transport configuration and then binds it to a SOAP transport configuration. From here, the path differs whether it is the pure standalone Java service or the service running in the Grails app.
In the pure Java standalone, this then is bound to a
com.ibm.ws.webservice.engine.client.Service where the
initService() method is called and things work as expected.
In the Grails app, with the same Java code included, the same place
in the code calls to
com.springsource.loaded.ri.ReflectiveIntercepter and then after a
lot of back and forth in the spring-loaded API, it finally throws a
java.lang.reflect.InvocationTargetException.
Does any one have any tips or ideas on how to get the reflection in Grails to behave the same as in the straight Java?
I've tried a lot of variations to get to this point and I'm nearing the end of my rope. Ideally, it would be easiest to manage the Grails service that manages our business logic and the Java code that talks to these internal systems together, so I would prefer to get everything (Grails and my Java service code) working together. I briefly tried building a standalone JAR of my service code and all it's dependencies, but had chained dependency conflicts when trying to use that in Grails. My final option will be to stand my Java service up separately from the business logic in the Grails service and just make the calls from the Grails service to the Java service. This is less than ideal.
It's easy when you stumble into the answer... ;-)
The Grails service runs as expected if I set the run configuration in IDEA to use -noreloading option.
grails -noreloading run-app
This stops Grails/IDEA from leaving in the hooks to reload classes on the fly.
Are there any thoughts on whether this is a bug in Grails or the SpringSource Loader classes?

Categories