taskadapter / redmine-java-api

Redmine Java API
Apache License 2.0
269 stars 162 forks source link

Requestproblem while trying to get Issues #302

Closed vanStelln closed 6 years ago

vanStelln commented 6 years ago

Hi guys,

I'm relatively new to the redmine java api and I'm stucking now. At first the environment: Java8u144 Redmine Server version: 3.2.2 Redmine-Java-Api version: 3.0.0 Server used a self signed certificate, that is implementet in "cacerts". The Server should allow the Rest api. I'm working with Eclipse IDE Oxygen 4.7.1

Because of the self signed certificate I had to use a HttpClient, when I want to connect to the redmineserver, if you follow this instruction: https://github.com/taskadapter/redmine-java-api/wiki/HowToUseSelfSignedCertificates

The problem was, that the RedmineApi and Apache httpcomponents-client-4.2.6 throws a Exception: Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.client.utils.URIBuilder.addParameters(Ljava/util/List;)Lorg/apache/http/client/utils/URIBuilder;

cause of one methode "addParameters"(URIConfiguratorclass) that isn't implementet until in Apache httpcomponents-client-4.3. In Apache httpcomponents-client-4.3 the "DefaultHttpClient" ist deprecated, which is used to create a instance of httpclient.

So I tried to use Apache httpcomponents-client-4.5.4. The problem here is, that the RedmineApi was not updated for 4.5.4 and the RedmineManagerFactory couldnt work, cause so much imported classes where deprecated. I tried myself to fix the deprecated classes. And it looks like it works in the first moment, but I'm still missing something.

so here is some code:

static String uri = "https://AAA.BBB.CC.DDD:port/";

static String apiAccessKey = "my own apiAccessKey";

KeyStore ks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream(" filepath to cacerts"), "changeit".toCharArray());

Collection trustStores = new ArrayList(); trustStores.add(ks);

System.setProperty("http.proxyHost", "AAA.BBB.CC.DDD"); System.setProperty("http.proxyPort","port"); System.setProperty("http.proxyUser",user); System.setProperty("http.proxyPassword",password);

HttpClientConnectionManager ccManager = RedmineManagerFactory.createConnectionManagerWithExtraTrust(trustStores);

HttpClient lClient = RedmineManagerFactory.getNewHttpClient(ccManager);
RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri, apiAccessKey, lClient);

List issues = mgr.getIssueManager().getIssues("5",null,Include.attachments); for(Issue i:issues) { System.out.println(i); }

I get the Exception org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] ... cause the response i get is formed like

unbenannt

and the RedmineJSONParser coudnt convert this so the exception is throwing..

I' was giving me out the request that was send:

https://AAA.BBB.CC.DDD:port/issues.json?project_id=5&include=attachments&limi=25&offset=0&key=myApiAccessKey HTTP/1.1

I copied this link in my browser and there a Popupwindow was showing and asking me for my Authentification. I tried to login with my Username and password but with no success. Then I tried to use the link without the "HTTP/1.1" and as result i got the Jsonobject. I know that the HTTP/1.1 is the protocollversion. So i think that the mistake is produced anywhere in the creation of the request.

Maybe the mistake is produced in the HttpClient.

In the Redmineapi 3.0.1 The HttpClient

public static HttpClient getNewHttpClient(ClientConnectionManager connectionManager) { try { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); final DefaultHttpClient result = new DefaultHttpClient( connectionManager, params); ... gets the Protocollversion on this way.

In my updated Version of the Redmineapi I couldnt find a way to give the HttpClient the Protocollversion. There are diffrent configurations, that you can give to it, but I couldnt find any way to give a protocolversion to the HttpClient. (It is possible to give the protocolversoin to a HttpPost)

So does anybody know what I can do or is there a new version of the RedmineApi, that i dont found?

vanStelln commented 6 years ago

The client sends only the URI so without HTTP/1.1. The HttpResponse looks like HttpResponseProxy{HTTP/1.1 400 Bad Request [Server: nginx, Date: Thu, 14 Dec 2017 14:22:17 GMT, Content-Type: text/html, Content-Length: 166, Connection: close] But I dont know what to do with this.

alexeyOnGitHub commented 6 years ago

this library is built and tested with

 compile ('org.apache.httpcomponents:httpclient:4.5.1',

also, I just verified that all tests also pass with version 4.5.4, so I am not sure what you mean when you say it does not work with 4.5.4.

it may or may not work with httpclient older than 4.5.1. there is no point in trying to maintain compatibility with all possible legacy versions of httpclient, it would be too much extra work.

I suggest using HttpClient 4.5.1 or newer, if possible.

vanStelln commented 6 years ago

Thank you for your answer :)

I could solve the problem with the request. The mistake was triggered by the ssl certificate I used. I wasn't able to answer cause of holydays :)

IT look's like, I couldn't find my mistake in the versions of Redmineapi and httpclient I use. Here some screenshots:

The libs I installed:

githubbeispiel2

This was my main problem:

githubbeispiel

When using HttpClient 4.5.4 I get this:

githubbeispiel4

So I was looking in the class of RedmineManagerFactory

githubbeispiel3

I build the RedmineManager like this:

RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri, apiAccessKey, HttpClient);

That's why I changed the RedmineApi a litte bit. I thought that I have some wrong versions of the diffrent Jars in the user-libary "apache_http" or the wrong redmine api. But that api I used for the Screenshot was the one from 19.12. Maybe I'm to dump to use the right methods.

alexeyOnGitHub commented 6 years ago

if everything works now, let's close this request.

dfavaro commented 6 years ago

Hi, same problem here. My enviroment

When I try to do this

HttpClient httpClient = new DefaultHttpClient();
RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri, apiAccessKey, httpClient);

ProjectManager projectManager = mgr.getProjectManager();
IssueManager issueManager = mgr.getIssueManager();

List<Project> projects = new ArrayList<Project>();
try {
    projects = projectManager.getProjects();

i cath this exception

org.jboss.resteasy.spi.UnhandledException: java.lang.NoSuchMethodError: org.apache.http.client.utils.URIBuilder.addParameters(Ljava/util/List;)Lorg/apache/http/client/utils/URIBuilder;

Any suggest?

dfavaro commented 6 years ago

I noticed that I use

org.jboss.resteasy v2.3.2.Final

, which import into my project an old version of org.apache.httpcomponents. This oldest libraries of org.apache.httpcomponents doesn't have those addParameters methods.

So the question is, how can I say to Redmine to use latest version of org.apache.httpcomponents?