BUG Community

Welcome! Log In

Forums Applications SSL Rest Client

Subscribe to SSL Rest Client  30 posts, 8 voices , Tagged: SSL http REST

Log in to reply to this topic
 
Aug 16, 2011 1:54pm
User_img_not_found_03_med franklovec... 13 posts

Firstly, I already have a heavier Java REST client that I can’t seem to include correctly, as it is configured for SSL and basic auth, but I can’t seem to get thebug to not throw “ClassNotFound” exceptions.

In the MANIFEST.MF file I declare a package ‘com.isidorey.api’ after I have imported the .jar into path and put coded a sample request (https://github.com/isidorey/isidorey-sdk).  The Java checks out in the eclipse environment, but the MANIFEST throws an error requiring me to make com.isidorey.api “optional”, and I have to, as this is the only way I can remove the red x.  I’ve tried scp’ing the jar file as  a .bar genereated from BND tool over  to /usr/share/java/bundle (which didn’t work), but shouldn’t the IDE export the dependencies over to the bug?  

Secondly, does the simple rest client support SSL?  I can’t seem to find it in the javadoc.

Any help would be appreciated!

Aug 18, 2011 7:10pm
Medium Bug Labs team kgilmer 215 posts

Hi franklovechio,

You have three options with your rest client: embed the sources in your application, embed the jar in your application, or create a seperate bundle for the rest client.  It looks like you tried option #3 and it did not work.  For this to work, use the resultant bnd-generated jar in your Eclipse Target Platform.  You’ll need to rename that jar from the ”.bar” extension.  Once it’s in the target platform it should be recognized by PDE and your classes will be provided in the “Plug-in Dependencies” project classpath container.  For option #2, copy the jar into your project somewhere and add it in the Bundle-Classpath.

hope that helps,

ken

Aug 22, 2011 12:00pm
User_img_not_found_03_med franklovec... 13 posts

Hi Ken,

It helps, but I’m probably missing something.

I have my library in .jar format.  I exported to a .bar file using the BND tool.  I then renamed it to a .jar extension and copied it into my project (isidorey-api.jar):

created on: 08/22/11

The, I “Add Jars” in Eclipse to the project:

created on: 08/22/11

Then, I add it as a dependency, but need to chech Show non-exported packages>

created on: 08/22/11

This still requires me to mark the package as optional:

created on: 08/22/11

When I upload to the bug, I get the same “ClassNotFound” exception.

 

 

 

Aug 22, 2011 1:06pm
Medium Bug Labs team jconnolly 285 posts

Frank,

Well, you’re mixing two different approaches to classpath resolution in OSGi.  One is to put the jar in your classpath, (as you’ve done in the first 2 images).  You’ll also want to list the jar as in your classpath for your manifest:

Bundle-Classpath: .,isidorey-api.jar

That should handle it on the BUG-side, and adding it to your Java Build Path, as you’ve done, will handle it on the eclipse side.

To be sure that bnd hasn’t accidentally screwed up your jar (which can happen when the original jar contains strange path conventions, like /src/java/api/linux/com/buglabs/bug/....) .  BND likes to have the top-most directory correspond to the package namespace, like:

com/buglabs/bug/MyApp.class = com.buglabs.bug.MyApp.class.  Anyway, use your favorite compression tool like WinRAR ot zipinfo to ensure that the package naming isn’t screwed up in the isidorey-api.jar.  Or just dropbox the jar and I can help work it out for you ;D

Aug 22, 2011 1:45pm
User_img_not_found_03_med franklovec... 13 posts

There must be something BND path related, as when I add ”, isidorey-api.jar” into the the ClassPath in the Manifest, then upload to the bug, I get this error:

 

 ERROR  : An error occured while trying to start bundle: file:/usr/share/java/apps/BUGcamera+Hello+World.jar: Not found: bugcamera_hello_world.Activator

01/01 02:02.47 ERROR  : Nested Exception: bugcamera_hello_world.Activator not found by BUGcamera_Hello_World [51]

java.lang.ClassNotFoundException: bugcamera_hello_world.Activator not found by BUGcamera_Hello_World [51]

at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:780)

at org.apache.felix.framework.ModuleImpl.access$300(ModuleImpl.java:73)

at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1733)

at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

at org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:638)

at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3660)

at org.apache.felix.framework.Felix.activateBundle(Felix.java:1817)

at org.apache.felix.framework.Felix.startBundle(Felix.java:1739)

at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:922)

at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:909)

at com.buglabs.bug.program.UserAppManager.startApp(UserAppManager.java:155)

at com.buglabs.bug.program.UserAppManager.processQueue(UserAppManager.java:135)

at com.buglabs.bug.program.UserAppManager.run(UserAppManager.java:110)

at com.buglabs.bug.program.ProgramServlet.doPost(ProgramServlet.java:142)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:706)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:788)

at com.buglabs.osgi.http.HttpServer.processRequest(HttpServer.java:433)

at com.buglabs.osgi.http.HttpServer.process(HttpServer.java:254)

at com.buglabs.osgi.http.HttpServer.run(HttpServer.java:94)

 

01/01 02:02.47 ERROR  : Exception thrown when starting app file:/usr/share/java/apps/BUGcamera+Hello+World.jar.  Ignoring application.

org.osgi.framework.BundleException: Not found: bugcamera_hello_world.Activator

at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3664)

at org.apache.felix.framework.Felix.activateBundle(Felix.java:1817)

at org.apache.felix.framework.Felix.startBundle(Felix.java:1739)

at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:922)

at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:909)

at com.buglabs.bug.program.UserAppManager.startApp(UserAppManager.java:155)

at com.buglabs.bug.program.UserAppManager.processQueue(UserAppManager.java:135)

at com.buglabs.bug.program.UserAppManager.run(UserAppManager.java:110)

at com.buglabs.bug.program.ProgramServlet.doPost(ProgramServlet.java:142)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:706)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:788)

at com.buglabs.osgi.http.HttpServer.processRequest(HttpServer.java:433)

at com.buglabs.osgi.http.HttpServer.process(HttpServer.java:254)

at com.buglabs.osgi.http.HttpServer.run(HttpServer.java:94)

Caused by: java.lang.ClassNotFoundException: bugcamera_hello_world.Activator not found by BUGcamera_Hello_World [51]

at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:780)

at org.apache.felix.framework.ModuleImpl.access$300(ModuleImpl.java:73)

at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1733)

at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

at org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:638)

at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3660)

... 13 more

 

The public link to the BND genereated bar, renamed to jar extension, is here:

http://dl.dropbox.com/u/32085996/isidorey-api.jar

 

I would love to know how to fix this in the future—I kind of understand your class explanation, as ours looks something like:

src / main / java / com / isidorey / api/...

 

Thanks!

Aug 22, 2011 2:00pm
Medium Bug Labs team jconnolly 285 posts

Well, these look unrelated.  The fact that you get Activator not found exceptions means that the Activator.class, at the path specified in your MANIFEST.MF, doesn’t exist:

/bugcamera_hello_world.Activator.class

On the bug, do:

zipinfo /usr/share/java/apps/BUGcamera+Hello+World.jar | grep Activator

and pastebin.  In the meantime I’ll look at the isidorey jar.

 

Aug 22, 2011 2:09pm
User_img_not_found_03_med franklovec... 13 posts

Weird.  Debugging led me to believe they were related, as the inclusion of the jar in the ClassPath made the app not work, where it previously did work (stock example BugCamera hello world)

When the app did work:

 

-rw——    2.0 fat     1320 bl defN 16-May-11 11:09 bugcamera_hello_world/Activator.java

h-rw——    2.0 fat     2424 bl defN 22-Aug-11 11:23 bugcamera_hello_world/Activator.class

 

After including the jar in ClassPath and trying to deploy:

 

-rw——    2.0 fat     1320 bl defN 16-May-11 11:09 bugcamera_hello_world/Activator.java

h-rw——    2.0 fat     2424 bl defN 22-Aug-11 11:23 bugcamera_hello_world/Activator.class

 

 

Aug 22, 2011 2:13pm
Medium Bug Labs team jconnolly 285 posts

Try:

cd /tmp

unzip /usr/share/java/apps/BUGcamera+Hello+World.jar

cat META-INF/MANIFEST.MF

and paste

Aug 22, 2011 2:15pm
User_img_not_found_03_med franklovec... 13 posts

No such folder “apps” exists, just lots of jar files.

Aug 22, 2011 2:18pm
Medium Bug Labs team jconnolly 285 posts

Wait, what?

01/01 02:02.47 ERROR : Exception thrown when starting app file:/usr/share/java/apps/BUGcamera+Hello+World.jar. Ignoring application.
seems to indicate that apps exists…

Aug 22, 2011 2:20pm
User_img_not_found_03_med franklovec... 13 posts

Oh man, woops—wrong terminal window :)  So much for the brain being able to multi-task.  

 

Manifest-Version: 1.0

Bug-Bundle-Type: Application

Bundle-Vendor: jedahan

Bundle-ClassPath: bugcamera.jar, isidorey-api.jar

Bundle-Version: 1.0.0

BUG-API-Version: 2.0.2

Bundle-Name: BUGcamera Hello World

Bundle-Activator: bugcamera_hello_world.Activator

Bundle-ManifestVersion: 2

Bundle-Description: Hello World code for BUGcamera

Import-Package: com.buglabs.application,com.buglabs.bug.module.lcd.pub

 ,com.buglabs.bug.module.camera.pub,com.buglabs.util,com.buglabs.devic

 e,javax.swing,javax.imageio,org.osgi.framework,org.osgi.util.tracker

@h@Bundle-SymbolicName: BUGcamera_Hello_World

Aug 22, 2011 2:22pm
Medium Bug Labs team jconnolly 285 posts

hmm, why is bugcamera.jar in your classpath?  

Bundle-ClassPath: bugcamera.jar, isidorey-api.jar

should be

Bundle-ClassPath: .,isidorey-api.jar

Do that in the SDK, and before sending it to BUG, do:

/etc/init.d/felix stop

rm -fr /var/volatile/felix-cache

/etc/init.d/felix start && tail -f /var/log/felix.log, then send the app over to BUG

Aug 22, 2011 3:04pm
User_img_not_found_03_med franklovec... 13 posts

That was the default setting when downloading the app to Eclipse—thought that the ., was just an append!

So far so good, but looks like the Open JDK Zero VM may be causing issues? 

Nested Exception: javax/net/ssl/HostnameVerifier

java.lang.NoClassDefFoundError: javax/net/ssl/HostnameVerifier

at com.isidorey.api.IsidoreyAPI.<init>(IsidoreyAPI.java:65)

 

 

Aug 22, 2011 3:06pm
User_img_not_found_03_med franklovec... 13 posts

It may be that there is a missing package as well?  Ubuntu requires an apt-get libbcprov-java I think, not sure about Angstrom.

Aug 22, 2011 3:14pm
Medium Bug Labs team jconnolly 285 posts

hmmm, well it exists:

root@bug20:~# zipinfo /usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar | grep HostnameVerifier -rw---- 1.0 fat 272 b- stor 31-May-11 11:47 com/sun/net/ssl/HostnameVerifier.class -rw---- 1.0 fat 194 b- stor 31-May-11 11:43 javax/net/ssl/HostnameVerifier.class -rw---- 1.0 fat 909 b- stor 31-May-11 11:43 javax/net/ssl/HttpsURLConnection$DefaultHostnameVerifier.class -rw---- 1.0 fat 594 b- stor 31-May-11 11:43 sun/net/www/protocol/https/DefaultHostnameVerifier.class

I just now got an opportunity to open that isidorey jar up, few minutes and I’ll see what I can figure out.

Aug 22, 2011 3:19pm
User_img_not_found_03_med franklovec... 13 posts

OK , thanks!—I actually just updated the jar to include built dependencies like GSON and commons— http://dl.dropbox.com/u/32085996/isidorey-api.jar  is the new listing.

Aug 22, 2011 3:23pm
Medium Bug Labs team jconnolly 285 posts

Ok great, and what’s the line of code you’re using to get that exception?

Aug 22, 2011 3:28pm
User_img_not_found_03_med franklovec... 13 posts

Where these are included:

import com.isidorey.api.APIConstants;


import com.isidorey.api.PublishAPI;


import com.isidorey.api.exception.APIException;

 

Code:

PublishAPI api = new PublishAPI(APIConstants.API_URL, “username”,


“password”);


 


Map<String, String> keyValueMap = new HashMap<String, String>();


keyValueMap.put(“key”, “value”);


try {


System.out.println(“TRYING TO PUBLISH);


api.publish(“00728”, “P-000728”, “bug”, “labs”, “hub”, keyValueMap);


} catch (APIException e) {


System.out.println(“FAILING TO PUBLISH);


e.printStackTrace();


}

Aug 22, 2011 3:48pm
Medium Bug Labs team jconnolly 285 posts

Got it to work ;D

TRYING TO PUBLISH Aug 22, 2011 8:46:48 PM com.isidorey.api.IsidoreyAPI constructAPIUrl INFO: API URL: <a href="https://api.isidorey.net/v0.9/PUBLISH/00728/P-000728/bug/labs">https://api.isidorey.net/v0.9/PUBLISH/00728/P-0...</a> Aug 22, 2011 8:46:51 PM com.isidorey.api.PublishAPI publish INFO: JSON RESPONSE; {"message":"Unauthorized","status":"401","detail":"Invalid API Key Supplied","ttl":0}

Add  javax.net.ssl to your Import-Package declaration in your manifest.  Then on bug, do, 

echo “org.osgi.framework.system.packages.extra=sun.misc” >> /usr/share/java/conf/config.properties

then /etc/init.d/felix stop; rm -fr /var/volatile/felix-cache; /etc/init.d/felix start && tail -f /var/log/felix.log

and send over your app.

References: http://dev.eclipse.org/mhonarc/lists/equinox-dev/msg04328.html and  http://felix.apache.org/site/apache-felix-framework-configuration-properties.html

Aug 22, 2011 5:27pm
User_img_not_found_03_med franklovec... 13 posts

AWESOME.  I noticed that if I wanted to do something inside the Activator class (let’s say keep track of start/stop), I get an unknown host exception  (not a big deal, just wondering if this is bundle related). 

 

Thanks!

Aug 22, 2011 5:41pm
Medium Bug Labs team jconnolly 285 posts

No, it’s likely that your /etc/hosts doesn’t have a valid DNS, or your network setup isn’t right…  sanity-check and ping 4.2.2.2, and ping google.com.  If can resolve google.com you should be ok, assuming the server you’re trying to connect to is in DNS

Aug 23, 2011 11:41am
User_img_not_found_03_med franklovec... 13 posts

I did a sanity test, it appears to be client related (something with netty).  I also have a few more questions regarding the application you’ve written called BUGcam_helloworld.  

I’ve got a pub/sub client working, and was trying to take a picture on a specific received message.  I start the client inside of initServices(), and created a method called takePicture() (that essentially is the same code inside of your doStart() method)—I noticed that doStart() never gets called for some reason in the stock application, and when I use that code to take the picture, I get a message that states the camera is not available (even though it’s plugged into the bug, and it’s been maybe 20 seconds since initServices() was called).   I must be missing something?  My little modified code looks like:

 

 

public void initServices() { System.out.println("INIT SERVICES"); /** * Attempt pub/sub connection */ pubsub(); // services to control the camera flash, LEDs getServices().add( "com.buglabs.bug.module.camera.pub.ICameraModuleControl"); // service to snap a picture getServices().add("com.buglabs.bug.module.camera.pub.ICameraDevice"); } public void pubsub() { // Make a connection // Subscribe on a topic, and when it comes in, call the method takePicture() } private void takePicture() { camera = (ICameraDevice) super.getService(ICameraDevice.class); camControl = (ICameraModuleControl) super.getService(ICameraModuleControl.class); try { camControl.setFlashBeamIntensity(0); camControl.setLEDFlash(true); FileOutputStream fos = new FileOutputStream(new File( "/tmp/image.jpeg")); fos.write(camera.getImage()); System.out.println("Picture written to file at /tmp/image.jpeg"); camControl.setLEDFlash(false); } catch (IOException e) { System.err .println("Bugcam_helloworld error: Camera control is not accessible."); e.printStackTrace(); } }.

Aug 23, 2011 12:46pm
Medium Bug Labs team jconnolly 285 posts

Hey Frank, do you have a stacktrace of specifically what the exception looks like?  And the full code for the file containing the java code above?

Aug 23, 2011 2:28pm
User_img_not_found_03_med franklovec... 13 posts

I’ve put up the code on github, https://github.com/franklovecchio/pub-sub-bug, and also e-mailed you the project with working credentials.  

The error I’m seeing is:  Caught exception: java.lang.NoClassDefFoundError: com/buglabs/bug/module/camera/pub/ICameraDevice, even though it looks like it was declared in the manifest.

 

Also, if you get a netty connection error that resembles “java.nio.channels.UnresolvedAddressException”, just stop/start felix again (trying to figure out what the problem is there).

 

Thanks!

Jun 28, 2012 2:22am
User_img_not_found_03_med louis 38 posts

http://www.louisvuittonusauks.co.uk/ louis vuitton bags

http://www.louisvuittonpurses-outlets.net/ louis vuitton Handbags Outlet

http://www.greatlouisvuittonbags.com/ louis vuitton purses

http://www.louisvuittonpursebags.net/ Louis Vuitton Purses

http://www.louisvuittononlineshops.org/ Cheap Louis Vuitton

http://www.officiallouisvuittonzone.net/ louis vuitton outlet

http://www.hermesoutletus.org/ hermes Purses

http://www.cheap-suprashoes.org/ cheap supra shoes

Log in to reply to this topic
Forums Applications SSL Rest Client

Powered by Community Engine

Top
Login