Forum Stats

  • 3,815,264 Users
  • 2,258,987 Discussions
  • 7,893,019 Comments

Discussions

Problem in connect to a REST service

2701258
2701258 Member Posts: 6
edited Jan 2, 2018 11:02AM in Java Cloud Service

Hi,

I'm new working with JCS SX.

I need to connect to REST service of our Saas (CRM).

The basic thing that I'm trying is using the following code:

import com.sun.jersey.api.client.WebResource;

import com.sun.jersey.api.client.Client;

import com.sun.jersey.api.client.ClientResponse;

import com.sun.jersey.api.client.config.ClientConfig;

import com.sun.jersey.api.client.config.DefaultClientConfig;

import com.sun.jersey.api.client.filter.ClientFilter;

import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;

import com.sun.jersey.api.client.filter.LoggingFilter;

import com.sun.jersey.client.urlconnection.HTTPSProperties;

import javax.net.ssl.SSLContext;

public String doRestAPI_Click() {
  
    try {
        SSLContext sslContext = SSLContext.getDefault();
        ClientConfig def = new DefaultClientConfig();
        String response = "";
      
        System.out.println("start - RESP API");
      
        def.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,new HTTPSProperties(null, sslContext));
      
        Client c = Client.create(def);
        c.addFilter(new HTTPBasicAuthFilter("USER", "Passwd"));
        WebResource webResource = c.resource("https://our_server/fscmRestApi/resources/11.13.0.0/items");
      
        System.out.println("before end - RESP API");
      
        response = webResource.get(String.class);
      
        System.out.println("end - RESP API");
      
    }
    catch(Exception e){
        System.out.println(e.getMessage());
    }
  
  
    return null;
}

but I'm receiving this error:

javax.net.ssl.SSLKeyException: FATAL Alert:BAD_CERTIFICATE - A corrupt or unuseable certificate was received.

<oracle.adf.view> <CellGatherCallback> <_ensureValidInlineStyle> <PANEL_GRID_LAYOUT_INVALID_CELL_STYLE>

<oracle.adf.view> <CellGatherCallback> <_ensureValidInlineStyle> <PANEL_GRID_LAYOUT_INVALID_CELL_STYLE>

Can any one tell me what is missing or what I'm doing wrong.

I have check several examples, and the code seems to be similar.

Thanks,

Jose Pedro

Answers

This discussion has been closed.