2016-05-06 3 views
0

Я создаю приложение, используя Libemy для Linux, для подключения Cloudant. Я каждый день обнаружил RuntimeException, подключившись к моему RESTful API. Тем не менее, я должен перезапустить свое приложение каждый день, чтобы решить эту проблему.Связь между Liberty для Bluemix для Java и броском заливки RuntimeError daily

ошибка отображается следующим образом:

Exception thrown by application class 'org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage:116' 
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: Error retrieving server response 
at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116) 
at [internal classes] 
Caused by: org.apache.cxf.interceptor.Fault: Error retrieving server response 
at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:163) 
... 1 more 
Caused by: com.cloudant.client.org.lightcouch.CouchDbException: Error retrieving server response 
at com.cloudant.client.org.lightcouch.CouchDbClient.execute(CouchDbClient.java:501) 
at com.cloudant.client.org.lightcouch.CouchDbClient.executeToInputStream(CouchDbClient.java:515) 
at com.cloudant.client.api.Database.findByIndex(Database.java:361) 
at com.cloudant.client.api.Database.findByIndex(Database.java:321) 
at th.co.gosoft.rest.TopicService.getHotTopicList(TopicService.java:82) 
at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at com.ibm.ws.jaxrs20.server.LibertyJaxRsServerFactoryBean.performInvocation(LibertyJaxRsServerFactoryBean.java:636) 
... 1 more 
Caused by: java.net.ProtocolException: Server rejected operation 
at sun.net.www.protocol.http.HttpURLConnection.expect100Continue(Unknown Source) 
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source) 
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source) 
at com.ibm.net.ssl.www2.protocol.https.b.getOutputStream(Unknown Source) 
at com.cloudant.http.HttpConnection.execute(HttpConnection.java:231) 
at com.cloudant.client.org.lightcouch.CouchDbClient.execute(CouchDbClient.java:466) 
... 9 more 

Я использую этот CloudantClientMgr следующим образом:

package th.co.gosoft.util; 

import java.net.MalformedURLException; 
import java.net.URL; 
import java.util.Map.Entry; 
import java.util.Set; 

import com.cloudant.client.api.ClientBuilder; 
import com.cloudant.client.api.CloudantClient; 
import com.cloudant.client.api.Database; 
import com.google.gson.JsonArray; 
import com.google.gson.JsonElement; 
import com.google.gson.JsonObject; 
import com.google.gson.JsonParser; 

public class CloudantClientMgr { 

    private static CloudantClient cloudant = null; 
    private static Database db = null; 

    private static String databaseName = "go10_db"; 

    private static String url = "https://xxxxxxxxxx-bluemix.cloudant.com"; 
    private static String user = "xxxxxxxxxx-bluemix"; 
    private static String password = "password"; 

    private static void initClient() { 
     if (cloudant == null) { 
      synchronized (CloudantClientMgr.class) { 
       if (cloudant != null) { 
        return; 
       } 
       try { 
        cloudant = createClient(); 
       } catch (MalformedURLException e) { 
        throw new RuntimeException(e.getMessage(), e); 
       } 
       System.out.println("cloudant : " + cloudant.serverVersion()); 

      } 
     } 
    } 

    private static CloudantClient createClient() throws MalformedURLException { 
     String VCAP_SERVICES = System.getenv("VCAP_SERVICES"); 
     String serviceName = null; 
     CloudantClient client; 

     if (VCAP_SERVICES != null) { 
      System.out.println("VCAP_SERVICE"); 
      JsonObject obj = (JsonObject) new JsonParser().parse(VCAP_SERVICES); 
      Entry<String, JsonElement> dbEntry = null; 
      Set<Entry<String, JsonElement>> entries = obj.entrySet(); 
      for (Entry<String, JsonElement> eachEntry : entries) { 
       if (eachEntry.getKey().toLowerCase().contains("cloudant")) { 
        dbEntry = eachEntry; 
        break; 
       } 
      } 
      if (dbEntry == null) { 
       throw new RuntimeException("Could not find cloudantNoSQLDB key in VCAP_SERVICES env variable"); 
      } 

      obj = (JsonObject) ((JsonArray) dbEntry.getValue()).get(0); 
      serviceName = (String) dbEntry.getKey(); 
      System.out.println("Service Name - " + serviceName); 

      obj = (JsonObject) obj.get("credentials"); 

      user = obj.get("username").getAsString(); 
      password = obj.get("password").getAsString(); 

      client = ClientBuilder.account(user) 
        .username(user) 
        .password(password) 
        .build(); 

     } else { 
      System.out.println("LOCAL"); 
      client = ClientBuilder.url(new URL(url)) 
        .username(user) 
        .password(password) 
        .build(); 
     } 

     return client; 

    } 

    public static Database getDB() { 
     if (cloudant == null) { 
      initClient(); 
     } 

     if (db == null) { 
      try { 
       db = cloudant.database(databaseName, true); 
      } catch (Exception e) { 
       throw new RuntimeException("DB Not found", e); 
      } 
     } 
     return db; 
    } 

    private CloudantClientMgr() { 
    } 
} 

Я использую этот код для подключения CloudantClientMgr следующим образом:

@Path("topic") 
public class TopicService { 

    @POST 
    @Path("/post") 
    @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8") 
    public Response createTopic(TopicModel topicModel) { 

     Database db = CloudantClientMgr.getDB(); 

     com.cloudant.client.api.model.Response response = db.save(topicModel); 

     String result = response.getId(); 

     return Response.status(201).entity(result).build(); 
    } 
} 

Версия для облаков - 2.4.2

<dependency> 
    <groupId>com.cloudant</groupId> 
    <artifactId>cloudant-client</artifactId> 
    <version>2.4.2</version> 
</dependency> 

Если кто-нибудь использовал эту проблему, сообщите мне лучшее решение, чем мне нужно перезагрузить приложение каждый день.

ответ

0

Проблема, которую вы описываете, звучит идентично той, которая была разрешена в version 2.4.1.

Я бы установил, что у вас нет нескольких версий облачного клиента, включенного в приложение или путь к классам, и что ваше приложение действительно использует версию 2.4.2. Номера строк в трассировке стека, которые вы предоставляете, не соответствуют источнику для 2.4.2.

Смежные вопросы