flexiblepower / powermatcher

PowerMatcher - The Java implementation of the PowerMatcher, including the API, the core, a couple of examples, a remote implementation using websockets and a visualisation of the configuration.
http://www.powermatcher.org
Apache License 2.0
43 stars 25 forks source link

Support for jetty http client #207

Closed athukuria closed 8 years ago

athukuria commented 8 years ago

Hello All,

I am trying to add some example code in "net.powermatcher.examples" in my test file where http client request are made. below method is called from PVPanelAgent.java activate method.

private void testHttpGet() {
    CloseableHttpResponse response = null;
    CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    String uri = "http://localhost:7070/example";

    HttpGet get = new HttpGet(uri);
    try {
        response = httpClient.execute(get);
        int status = response.getStatusLine().getStatusCode();
        System.out.println("Got the Resonse status: " + status);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

Also updated net.powermatcher.examples.bnd.bnd file with jar files entry

-buildpath: \
    ${pm-buildpath},\
    net.powermatcher.core;version=latest,\
    org.apache.felix.http.servlet-api,\
    org.apache.httpcomponents.httpclient,\
    org.apache.httpcomponents.httpcore,\
    com.google.gson,\
    org.apache.commons.io
Bundle-Version: 2.0.1.${tstamp}
Private-Package:  net.powermatcher.examples*
Service-Component:  *

After this source is comping and when I run I see below error:

could not resolve the bundles: [net.powermatcher.examples-2.0.1.201605091244Unresolved constraint in bundle net.powermatcher.examples [8]: Unable to resolve 8.0: missing requirement [8.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.http)(version>=4.3.0)(!(version>=5.0.0))) ]

Failed to start bundle net.powermatcher.examples-2.0.1.201605091244, exception Unresolved constraint in bundle net.powermatcher.examples [8]: Unable to resolve 8.0: missing requirement [8.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.http)(version>=4.3.0)(!(version>=5.0.0)))

Not sure how to fix this. What is the right process to add new libraries in powermatcher source?

Thanks for the support.

wilcowijbrandi commented 8 years ago

Hi athukuria,

Thanks for getting in touch with us! For me it is not entirely clear what you are trying to achieve. You want to make a HTTP call from within your agent code? In that case it would make sense to use a library.

There are two ways to do that:

To include a JAR in your bundle:

Include-Resource: lib/yourlibrary.jar
-buildpath: \
    ${pm-buildpath},\
    lib/yourlibrary.jar;version=file

Hope this helps!

athukuria commented 8 years ago

@wilcowijbrandi thanks for the reply, I have solved the above problem with adding http Servlets and changing versions.

Now I am trying to add a sqlite-jdbc-3.7.2.jar library in net.powermatcher.remote.websockets\lib

here is my bnd.bnd file:

-buildpath: \ ${pm-buildpath},\ net.powermatcher.core;version=latest,\ com.google.gson,\ org.apache.felix.http.servlet-api;version=latest,\ org.apache.felix.http.jetty;version=latest,\ lib/sqlite-jdbc-3.7.2.jar;version=file -includeresource: \ {OSGI-INF/permissions.perm=permissions.perm},\ lib/sqlite-jdbc-3.7.2.jar,\ ../cnf/gradle/LICENSE.txt Include-Resource: lib/sqlite-jdbc-3.7.2.jar

-sub: *.bnd

Even after this I see below exception:

java.lang.ClassNotFoundException: org.sqlite.JDBC not found by net.powermatcher.remote.websockets.client [11] java.lang.ClassNotFoundException: org.sqlite.JDBC not found by net.powermatcher.remote.websockets.client [11]

Do I need to add different library !? This library works in normal Java application.

Thanks for the support.

athukuria commented 8 years ago

I have taken sqlite-jdbc-3.8.11.2.jar which is a osgi bundle. added in bndtools release repositories and added bunlde in demo.bndrun and client.bnd customized imports (org.sqlite). That's it worked.