ClientProtocolException

I have been experimenting with binding development and I’m getting this error:

Caused by: java.lang.ClassNotFoundException:
org.apache.http.client.ClientProtocolException cannot be found by org.openhab.binding.

I know why I’m getting a ClientProtocolException (testing an error path) but I don’t know why java can’t find the class.
I’m new to java and only somewhat familiar with Eclipse. I think it’s just a configuration issue but I’m not able to find it.

Any help will be appreciated.

Thanks,
Steve

Without seing your code, it is hard to help

As I said, I think that this is a configuration issue and not a code issue. To narrow this down, I created a new binding called TestBinging (sp! argh!!) using the ./create_openhab_binding_skeleton.sh script, then imported it.

Next I added one line to the initialize function and 2 imports

import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;

@Override
public void initialize() {
config = getConfigAs(TestBingingConfiguration.class);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
updateStatus(ThingStatus.ONLINE);
}

Then I added org.apache.httpcomponents.httpclient_4.5.2.v20170210-0925.jar to the buildpath as an external archive. Now the project builds OK.

Now, and this is where I think I’m going wrong, I added a runtime dependency on hhttpclient to the POM which now looks like this:

<modelVersion>4.0.0</modelVersion>
<parent>
  <artifactId>pom</artifactId>
  <groupId>org.openhab.binding</groupId>
  <version>2.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.testbinging</artifactId>
<packaging>eclipse-plugin</packaging>

<name>TestBinging Binding</name>

<dependencies>
	<dependency>
		<groupId>org.apache.httpcomponent</groupId>
		<artifactId>httpclient</artifactId>
		<version>4.5.2</version>
		<scope>runtime</scope>
	</dependency>
</dependencies>

Next I update the run configuration to add my new binding. I’m testing with PaperUI and when I add a TestBinding thing I get this error:

2018-05-19 12:59:09.570 [ERROR] [.i.c.AbstractInvocationHandler:101 ] - An error occurred while calling method ‘ThingHandler.initialize()’ on ‘org.openhab.binding.testbinging.internal.TestBingingHandler@3bf6a8bb’: org/apache/http/impl/client/BasicCredentialsProviderjava.lang.NoClassDefFoundError: org/apache/http/impl/client/BasicCredentialsProvider

so it looks like the runtime does not know where to get the httpclient jars.

Thansk,
Steve

Well it tool me a week (seems longer) but I’ve figured out one way to do it. I doubt its the best way but until I get a better answer, it will have to do.

It seems that even though openHAB is a Maven project, it doesn’t use Maven to build so I wasted a lot of time trying to add dependencies to the pom.

In the end I found another binding had created a directory under the main binding folder. I created a folder, copied the jars needed into that directory, added that directory to the build.properties file in the “bin.includes:” list, add the jars to the MANIFEST.MF file under “Bundle-Classpath:” entry and finally add the jars to the build path,.

Not exactly intuitive. I’m not going to mark this as solved because I am holding out hope that someone will tell me the openHAB way to do this.

Steve

2 Likes