@Override public String getApplicationToken(String persistenceUnit, String externalProperties) { String applicationToken; try { log.debug("\n\nGetting Application Token..."); WebResource.Builder atBuilder = webResource.path(Constants.KUNDERA_API_PATH + "/application/" + persistenceUnit).accept(mediaType) .type(mediaType); StringBuffer sb = new StringBuffer().append(externalProperties); ClientResponse insertResponse = (ClientResponse) atBuilder.post(ClientResponse.class, sb.toString()); InputStream is = insertResponse.getEntityInputStream(); applicationToken = StreamUtils.toString(is); log.debug("Application Token:" + applicationToken); } catch (UniformInterfaceException e) { log.error("Error during getApplicationToken, Caused by:" + e.getMessage() + ", returning null"); return null; } catch (ClientHandlerException e) { log.error("Error during getApplicationToken, Caused by:" + e.getMessage() + ", returning null"); return null; } return applicationToken; }
@Override public void run() { if (methodName != null) { Class<?> c = this.getClass(); Method method; try { method = c.getDeclaredMethod(methodName, parameterTypes); method.invoke(this, parameters); } catch (IllegalAccessException | NoSuchMethodException e) { LOG.error("Could not find method {} in class", methodName); return; } catch (InvocationTargetException e) { LOG.error("Invocation target exception: {}", e.getMessage()); return; } catch (UniformInterfaceException e) { LOG.error("REST Server error. Message: {}", e.getMessage()); return; } catch (ClientHandlerException e) { LOG.error("Could not communicate with REST Server: {} ", e.getMessage()); return; } } } }
Client client = Client.create(); WebResource webResource = client .resource("http://localhost:8080/activiti-rest/service/login"); LoginInfo loginInfo = new LoginInfo(); loginInfo.userId = "kermit"; loginInfo.password = "kermit"; ClientResponse response; try { response = webResource.type("application/json").post(ClientResponse.class, loginInfo); System.out.print(response.toString()); } catch (UniformInterfaceException ue) { System.out.print(ue.getMessage()); }
/** * The handled exception indicates a technical problem while processing the call on the server side and should * therefore be logged with error. * <p> * This method will be invoked only in a limited number of scenarios because of the following reasons: * <ul> * <li>The {@link com.bosch.im.client.rest.filter.ImExceptionMappingFilter} is able to map IM specific error * responses and throw the corresponding IM API exceptions. * <li>The creation of invalid requests should be impossible as the API methods typically validate the content before * it will be send (e.g. it is not possible to create an ICreateEntityCommand for a user without giving a user name). * <li>Exceptions which are unknown on client side will result in an * {@link com.bosch.im.exception.OutdatedClientVersionException} (also handled by * {@link com.bosch.im.client.rest.filter.ImExceptionMappingFilter}). * </ul> * * @param ex the exception of the failed request */ private static void handleException(final UniformInterfaceException ex) { LOGGER.error("Request failed: statusCode={}, message={}", ex.getResponse().getStatus(), ex.getMessage()); // throw MissingServerConnectionException although it is not really the cause. Just to wrap any Jersey specific // exception with an API exception. throw MissingServerConnectionException.createForRequestProcessingFailed(ex.getMessage()); } }
/** Returns an EmoClientException with a thin wrapper around the Jersey exception response. */ private EmoClientException asEmoClientException(UniformInterfaceException e) throws EmoClientException { throw new EmoClientException(e.getMessage(), e, toEmoResponse(e.getResponse())); }
/** Returns an EmoClientException with a thin wrapper around the Jersey exception response. */ private EmoClientException asEmoClientException(UniformInterfaceException e) throws EmoClientException { throw new EmoClientException(e.getMessage(), e, toEmoResponse(e.getResponse())); }
/** Returns an EmoClientException with a thin wrapper around the Jersey exception response. */ private EmoClientException asEmoClientException(UniformInterfaceException e) throws EmoClientException { throw new EmoClientException(e.getMessage(), e, toEmoResponse(e.getResponse())); }
} catch (UniformInterfaceException e) { LOG.error("REST Server error. Message: {}", e.getMessage()); } catch (ClientHandlerException e) { if (e.getCause() instanceof ConnectException) { clientRemoteResponse = wrb.post(ClientResponse.class, json); } catch (UniformInterfaceException e) { LOG.error("REST Server error. Message: {}", e.getMessage()); } catch (ClientHandlerException e) { if (e.getCause() instanceof ConnectException) { clientRemoteResponse = wrb.delete(ClientResponse.class); } catch (UniformInterfaceException e) { LOG.error("REST Server error. Message: {}", e.getMessage()); } catch (ClientHandlerException e) { if (e.getCause() instanceof ConnectException) {
throw new BuildException("Nexus base URL does not point to a valid Nexus location: " + e.getMessage(), e);