Using Eureka with Ribbon doesn't send custom header - spring-cloud

Current project uses spring-cloud-starter-eureka version 1.0.0.RELEASE.
I am using Ribbon to connect to some other services and require a custom header.
#Autowired
private RestTemplate restTemplate;
. . .
ResponseEntity result = this.restTemplate.exchange("https://FooServices/foos/daily",
HttpMethod.GET,
new HttpEntity(getSpecialHeaders()),
FooView[].class,
new Object[0]);
The code works fine for Spring Cloud version 1.0.0. However, when I move to 1.0.1 or 1.0.2, the custom header is no longer sent.
Is there a security reason this was changed or is this a defect?

It's a bug that has been fixed. It just needs to be released.

Related

Jasper : How to keep HTTP header in datasource from Jaspersoft Studio to server?

Consider the following :
I have a PHP web application. This application is protected from any intrusion via a middleware that looks for the correct credentials everytime a call to a route is done. If your are logged in correctly, the page is displayed. If not, you are kicked out. Simple and easy.
Now, this application provides me with links that return JSON. This JSON is generated for the sole purpose of reporting. In Jaspersoft Studio, I created a JSON data adapter and used the provided links as the URL.
But that was not it yet. Since a middleware is checking every link calls in the application, I needed to add an exception for my reports. I decided that passing an encrypted token in the HTTP header was the solution. I then added the option into our data adapter.
It worked like a charm!
Now, to the problem :
Using the information provided on the Jaspersoft website, I exported my Data Adapter to the server. The thing is, the HTTP Header is not considered anymore when calling the data source from the server. Of course, my report does not work anymore. I then tested with a link hosted on another platform and it worked, even without the HTTP header.
So, my question is how do I keep the HTTP header in my datasource from Jaspersoft Studio to the server?
Edit 1: Jaspersoft Studio Version : 6.4.0, JasperSoft Server Version: 6.3.0
Those HTTP options were added in JasperReports 6.3.1. The closest Server version to support those features should be 6.4.0.

Rest Web Service not working on TomEE web profile 1.7.2

I want to add a web service to an already existing web application. This application runs on a specific version of Apache TomEE (apache-tomee-web-profile-1.7.2) and an upgrade is not possible.
I'm trying to deploy this sample application on this TomEE, just to try it. I see no errors in the logs
I manage to see the home page of the application :
This is the code for the ressource :
#Path("/pojo")
public class SimpleRESTPojo {
#GET
public String pojo() {
return "pojo ok # " + new Date().toString();
}
}
And the code of the rest application :
#ApplicationPath("/rest-prefix")
public class ApplicationConfig extends Application {
#Override
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>(Arrays.asList(SimpleRESTPojo.class, SimpleRESTEJB.class));
}
}
So far I've tried :
base/rest-prefix/pojo,
base/rest-prefix/pojo/pojo, base/pojo all giving me 404 errors
base is the url where I manage to see the home page
I managed to find a solution which I'm quite happy with. Turns out what I wanted to do is pretty much impossible. As mentionned in
this other stackoverflow post Web Profile is a subset of Java EE that usually does not contains the required libraries to create a REST WS.
I ran the Rest Sample application on a TomEE jaxrs version and it works as expected. I then copied the few libs that are included in TomEE-jaxrs and not in TomEE-webprofile into my original server lib folder.

Websphere problems when setting up Http Connection Pool for RestTemplate

I'm working with Spring 4.0.3.RELEASE version. I'm able to make restful calls successfully. However, I learnt that HTTP connections are expensive and thought of using connection pool. I read few articles like this and this. Everything is fine when I include the dependency with Maven3 and compile. The problems arise during runtime.
With this code, I get class not found exception for PoolingHttpClientConnectionManager.
public RestTemplate restTemplate(){
HttpHost host = new HttpHost("localhost", 9081);
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
// Increase max total connection to 200
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(50);
cm.setMaxPerRoute(new HttpRoute(host), 20);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setConnectionManager(cm);
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
httpClientBuilder.build());
return new RestTemplate(requestFactory);
}
And with this code, I get class not found exception for HttpClients.
public RestTemplate restTemplate(){
RestTemplate restTemplate = new RestTemplate();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setConnectTimeout(20000);
requestFactory.setReadTimeout(20000);
restTemplate.setRequestFactory(requestFactory);
return restTemplate;
}
I'm deploying on Websphere 8.5. And I tried different versions of httpclient from 4.0.1 to 4.5.2 with different scope (provided, compile) with no luck.
Thanks in advance for any hint in the right direction.
So, it's basically a problem with Websphere 8+ versions including httpclient with their jvm library. Luckily, our Enterprise Websphere are all 7.5.x version. So, if we bundle the httpclient with the ear, it does not cause any issue in production or pre-production.
For those, who have to use Websphere 8.x versions, please use the shared isolated library approach as defined here. I used that for my local 8.5 Websphere and it works pretty neat.
you should stop the application and then go to manage module tab in websphere and
and on "Class loader order" combo box choose "parent last" item
and then start application. problem solved...

Several REST and EJB problems

I'm trying to deploy a Java EE web application with RESTful web services and an EJB connexion to another Java EE application.
I'm experiencing several problems and I fail to write down every specific question, so I have no choice but tell you all in a row.
1) First, I am using Tomcat to run the app and I cannot get EJB connexion to work. No matter what, I get a JNDI error : NamingContextFactory class not found. Why ?
My JNDI connexion is as follows :
String hostname = "localhost";
String port = "1099";
String url = "jnp://" + hostname + ":" + port + "/";
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
h.put(Context.PROVIDER_URL, url);
h.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
initialContext = new InitialContext(h);
2) Therefore, as the server used is not relevant, and as the app I'm trying to connect to is using JBoss (4.4.2.GA), I tried to deploy my app under the same JBoss. I cannot get it to deploy, I have a REST problem: ClassNotFoundException: javax.ws.rs.core.ApplicationConfig at deploy time.
2.1) I am compiling with Netbeans and the ApplicationConfig.class is not part of the 1.1 version of the JAX-RS api jsr311-api-1.1.jar I'm using at compile time. The implementation of the library was changed since 0.8 version, which I was using before, but I had to upgrade the jar because it didn't include #FormParam. Until now, I had found a workaround using com.sun.jersey.api.representation.FormParam instead but Jersey is not compatible with JBoss as far as I understand.
Why is the server looking for ApplicationConfig while it's not used in the war?
2.2) I understood I had to use RESTEasy, and JBoss 4 does not include it, so have to install it manually. But the RESTEasy doc suggest that I thoroughly modify my project my adding a lot of jars, servlets etc. From my point of view, I simply need a RESTful implementation on the server libs to which my JAX-RS API, which is only an interface, will refer once the app is deployed. I may have some serious misconceptions about how Java EE libraries linking work. Please help.
So I know there are several different problems here but I couldn't manage to separate them. I have lost so much time on this that I'm worried for my project. Thanks in advance.

Define WADL resources base in Jersey

I am using Jersey 1.9 and it is generating my WADL perfectly except I need to redefine the resources base URI.
I'm running Jetty 7 sitting behind Apache using mod_proxy as a reverse proxy to route REST requests back to Jetty / Jersey. So Jersey generates the resources base URI as
http://localhost:8080/testRestAPI/rest/
when I need something like
http://mydomain.com/rest/
I found this from Google but it is not working: http://jersey.576304.n2.nabble.com/Changing-baseURI-when-generating-WADL-td6169703.html
unfortunately, you've found a bug in Jersey implementation. Please file a new issue as stated on mailing list - jira link: http://java.net/jira/browse/JERSEY
What you can do for now is downgrade to Jersey 1.8, which should not be affected by latest changes in this area. Thanks and sorry for inconvenience!
EDIT: issue link: http://java.net/jira/browse/JERSEY-773
it is already fixed, so you should be able to use this feature in Jersey 1.10-b02 and newer.