You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@karaf.apache.org by abhilashb <ab...@in.bosch.com> on 2015/10/28 07:44:28 UTC

Karaf Issue - Web services not getting called (not working as expected)

Hello,

I am trying to call a web service which has been exposed by another
application.

When the below line gets executed 

int response = httpClient.executeMethod(method);

I wont get any response back instead it just goes back to the calling method
and starts executing the next lines.

There is no response and also no error as well.

When i run this web service locally, I get the response with status 200 but
some issue with Karaf.

Please let me know if i m missing something here and if anything needs to be
deployed in karaf to run this?

Regards,
Abhilash B.



--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Chandan,

the SyncopeLoginModule is there:

https://github.com/apache/karaf/blob/master/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModule.java

You can see in the code:

CloseableHttpResponse response = client.execute(get);

You can also see the OSGi headers statements there:

https://github.com/apache/karaf/blob/master/jaas/modules/pom.xml

Especially:

                         <Private-Package>
                             org.apache.karaf.jaas.modules.impl,
                             org.apache.felix.utils.properties,
                             org.apache.karaf.util,
                             org.apache.http*,
                             org.apache.commons.codec*
                         </Private-Package>

Regards
JB

On 10/29/2015 04:20 AM, Chandan wrote:
> Syncope login module. Where I can have a look @it?
> if you provide me a url/example I can have a look at it right away.
>
> Regards,
> Chandan
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195p4043212.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
No problem ;)

Regards
JB

On 10/29/2015 07:46 AM, abhilashb wrote:
> Hello All,
>
> Thanks JB and cschneider for helping me out. It worked.!!!!!
> I used Http instead of Https
>
> Regards,
> Abhilash
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195p4043229.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by abhilashb <ab...@in.bosch.com>.
Hello All,

Thanks JB and cschneider for helping me out. It worked.!!!!!
I used Http instead of Https

Regards,
Abhilash



--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195p4043229.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

it looks like you access to https URL, and you have an issue during the 
SSL handshake (when dealing with the certificate).

Don't your service use mutual authentication ? In that case you need a 
truststore.

Regards
JB

On 10/29/2015 07:01 AM, Chandan wrote:
> We have logged the exception.
>
> Here is the exception
>
> javax.net.ssl.SSLHandshakeException:
> sun.security.validator.ValidatorException: PKIX path building failed:
> sun.security.provider.certpath.SunCertPathBuilderException: unable to find
> valid certification path to requested target
>          at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
>          at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1884)
>          at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)
>          at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)
>          at
> sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341)
>          at
> sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
>          at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
>          at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
>          at
> sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
>          at
> sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
>          at
> sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:702)
>          at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
>          at
> java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
>          at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
>          at
> org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:828)
>          at
> org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2116)
>          at
> org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
>          at
> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
>          at
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
>          at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
>          at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
>          at
> com.bosch.service.SdomEndPoint.fetchVersionDetails(SdomEndPoint.java:451)
>          at com.bosch.service.SdomEndPoint.parseXML(SdomEndPoint.java:95)
>          at
> com.bosch.service.MServiceManager.execute(MServiceManager.java:95)
>          at com.bosch.manager.MManager.onDataResponse(MManager.java:68)
>          at com.bosch.redis.MRedis.onDataResponse(MRedis.java:134)
>          at
> com.bosch.redis.MRedisSubscriber.onMessage(MRedisSubscriber.java:24)
>          at redis.clients.jedis.JedisPubSub.process(JedisPubSub.java:113)
>          at redis.clients.jedis.JedisPubSub.proceed(JedisPubSub.java:83)
>          at redis.clients.jedis.Jedis.subscribe(Jedis.java:1974)
>          at
> com.bosch.redis.MRedisSubscribeWorker.run(MRedisSubscribeWorker.java:43)
>          at java.lang.Thread.run(Thread.java:745)
>          at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>          at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>          at java.lang.Thread.run(Thread.java:745)
> Caused by: sun.security.validator.ValidatorException: PKIX path building
> failed: sun.security.provider.certpath.SunCertPathBuilderException: unable
> to find valid certification path to requested target
>          at
> sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385)
>          at
> sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
>          at sun.security.validator.Validator.validate(Validator.java:260)
>          at
> sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)
>          at
> sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
>          at
> sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
>          at
> sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1323)
>          ... 30 more
> Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
> unable to find valid certification path to requested target
>          at
> sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196)
>          at
> java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)
>          at
> sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
>          ... 36 more
>
>
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195p4043222.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by Chandan <ch...@in.bosch.com>.
We have logged the exception.

Here is the exception

javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find
valid certification path to requested target
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1884)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)
        at
sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341)
        at
sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
        at
sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
        at
sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
        at
sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:702)
        at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
        at
java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at
org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:828)
        at
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2116)
        at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
        at
com.bosch.service.SdomEndPoint.fetchVersionDetails(SdomEndPoint.java:451)
        at com.bosch.service.SdomEndPoint.parseXML(SdomEndPoint.java:95)
        at
com.bosch.service.MServiceManager.execute(MServiceManager.java:95)
        at com.bosch.manager.MManager.onDataResponse(MManager.java:68)
        at com.bosch.redis.MRedis.onDataResponse(MRedis.java:134)
        at
com.bosch.redis.MRedisSubscriber.onMessage(MRedisSubscriber.java:24)
        at redis.clients.jedis.JedisPubSub.process(JedisPubSub.java:113)
        at redis.clients.jedis.JedisPubSub.proceed(JedisPubSub.java:83)
        at redis.clients.jedis.Jedis.subscribe(Jedis.java:1974)
        at
com.bosch.redis.MRedisSubscribeWorker.run(MRedisSubscribeWorker.java:43)
        at java.lang.Thread.run(Thread.java:745)
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: sun.security.validator.ValidatorException: PKIX path building
failed: sun.security.provider.certpath.SunCertPathBuilderException: unable
to find valid certification path to requested target
        at
sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385)
        at
sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
        at sun.security.validator.Validator.validate(Validator.java:260)
        at
sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)
        at
sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
        at
sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
        at
sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1323)
        ... 30 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
        at
sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196)
        at
java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)
        at
sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
        ... 36 more





--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195p4043222.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by Chandan <ch...@in.bosch.com>.
Syncope login module. Where I can have a look @it?
if you provide me a url/example I can have a look at it right away.

Regards,
Chandan



--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195p4043212.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

if you take a look on the SyncopeLoginModule, you will see a bundle that 
does exactly the same. For convenience, the SyncopeLoginModule embeds 
httpClient dependency.

Regards
JB

On 10/28/2015 07:44 AM, abhilashb wrote:
> Hello,
>
> I am trying to call a web service which has been exposed by another
> application.
>
> When the below line gets executed
>
> int response = httpClient.executeMethod(method);
>
> I wont get any response back instead it just goes back to the calling method
> and starts executing the next lines.
>
> There is no response and also no error as well.
>
> When i run this web service locally, I get the response with status 200 but
> some issue with Karaf.
>
> Please let me know if i m missing something here and if anything needs to be
> deployed in karaf to run this?
>
> Regards,
> Abhilash B.
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by Chandan <ch...@in.bosch.com>.
Hello Abhilash,

Even I am facing the same issue, Not able to call web service via Karaf.

Could anybody help me as well? 


Regards,
Chandan.



--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195p4043198.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by Christian Schneider <ch...@die-schneider.net>.
If the control goes to the caller method in the mid of a method then 
this is a clear sign that an exception happens.
So add a try catch and log the exception.

Especially in an BundleActivator.start method I made the experience that 
exceptions are not logged by default by the framework.

Christian

On 28.10.2015 14:47, abhilashb wrote:
> Hello,
>
> Thank you for the reply.
>
> Below is the sample code that i am using -
> 	
> import org.apache.commons.httpclient.Credentials;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpMethod;
> import org.apache.commons.httpclient.UsernamePasswordCredentials;
> import org.apache.commons.httpclient.auth.AuthScope;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.methods.PutMethod;
> 		
>    	public static void main(String[] args) {
> 				
> 		   		private static HttpClient httpClient;
>
> 		   		httpClient = getHttpSesssion(); // Getting the authentication for the
> application by using username/password
> 		   		StringBuffer fetchURL = new StringBuffer(ConnectionConstants.SCHEME);
> 		   		fetchURL.append(HOST);
> 		   		fetchURL.append(REPOSITORY);
> 		   		fetchURL.append(QUESTIONMARK);		   		
> 		   		fetchURL.append("oslc.where=domain:=DOMAIN . . . .);
>
> // Forming the web service url to be called (fetchURL)
>
> 		   		HttpMethod method = new GetMethod(fetchURL.toString());
> 		   				   		try {
> 		   				   			System.out.println("Setting header info...");
> 		   				   			method.addRequestHeader("Accept", "application/json");
> 		   				   			method.addRequestHeader("OSLC-Core-Version", "2.0");
> 		   				   			
> 		   				   			executeMethod = httpClient.executeMethod(method);
> 		   				   			
> 		   				   			System.out.println("Response Code :::" +
> method.getStatusCode());
>
> 		   				   			String response = method.getResponseBodyAsString();
> 		   				   			
> 		   				   			
> 		   				   		
> 		   				   		}catch(Exception e){
> 		   				   			//Wrap the exception					
> 		   				   		}finally{
> 		   				   			
> 		   				   		}
>
> 		   		
> 			}
> 		   	
>
>
> When the control reaches " executeMethod =
> httpClient.executeMethod(method);"
>
> It doesnt goahead and instead it stops/ goes back to the caller method
> without any response.
>
> In Karaf, i have installed httpClient -
>
> 103 | Active    |  50 | 3.1.0.7  | Apache ServiceMix :: Bundles ::
> commons-httpclient
>
> My manifest import statement -
>
> Import-Package:
> org.osgi.framework,org.apache.camel,org.apache.commons.httpclient,org.apache.commons.httpclient.auth
>
> Anything is missing?
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195p4043200.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com


Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by abhilashb <ab...@in.bosch.com>.
Hello,

Thank you for the reply.

Below is the sample code that i am using - 
	   
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PutMethod;
		
  	public static void main(String[] args) {
				
		   		private static HttpClient httpClient;

		   		httpClient = getHttpSesssion(); // Getting the authentication for the
application by using username/password
		   		StringBuffer fetchURL = new StringBuffer(ConnectionConstants.SCHEME);
		   		fetchURL.append(HOST);
		   		fetchURL.append(REPOSITORY);
		   		fetchURL.append(QUESTIONMARK);		   		
		   		fetchURL.append("oslc.where=domain:=DOMAIN . . . .);

// Forming the web service url to be called (fetchURL)

		   		HttpMethod method = new GetMethod(fetchURL.toString());
		   				   		try {
		   				   			System.out.println("Setting header info...");
		   				   			method.addRequestHeader("Accept", "application/json");
		   				   			method.addRequestHeader("OSLC-Core-Version", "2.0");
		   				   			
		   				   			executeMethod = httpClient.executeMethod(method);
		   				   			
		   				   			System.out.println("Response Code :::" +
method.getStatusCode());

		   				   			String response = method.getResponseBodyAsString();
		   				   			
		   				   			
		   				   		
		   				   		}catch(Exception e){
		   				   			//Wrap the exception					  
		   				   		}finally{
		   				   			
		   				   		}

		   		
			}
		   	


When the control reaches " executeMethod =
httpClient.executeMethod(method);"

It doesnt goahead and instead it stops/ goes back to the caller method
without any response.

In Karaf, i have installed httpClient -

103 | Active    |  50 | 3.1.0.7  | Apache ServiceMix :: Bundles ::
commons-httpclient

My manifest import statement - 

Import-Package:
org.osgi.framework,org.apache.camel,org.apache.commons.httpclient,org.apache.commons.httpclient.auth

Anything is missing? 



--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195p4043200.html
Sent from the Karaf - Dev mailing list archive at Nabble.com.

Re: Karaf Issue - Web services not getting called (not working as expected)

Posted by Christian Schneider <ch...@die-schneider.net>.
It is almost impossible to spot the problem with just one line of code 
that does not even state the
exact type of httpClient.

I have used Soap as well as Rest services in karaf without problems 
using CXF.
If you need some examples see:
https://github.com/cschneider/Karaf-Tutorial/tree/master/cxf

If you can create a small example project that shows your problem and 
put it to github or similar then we might also be able to help with your 
exact problem.

Christian

On 28.10.2015 07:44, abhilashb wrote:
> Hello,
>
> I am trying to call a web service which has been exposed by another
> application.
>
> When the below line gets executed
>
> int response = httpClient.executeMethod(method);
>
> I wont get any response back instead it just goes back to the calling method
> and starts executing the next lines.
>
> There is no response and also no error as well.
>
> When i run this web service locally, I get the response with status 200 but
> some issue with Karaf.
>
> Please let me know if i m missing something here and if anything needs to be
> deployed in karaf to run this?
>
> Regards,
> Abhilash B.
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Issue-Web-services-not-getting-called-not-working-as-expected-tp4043195.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com