jersey-client

How to use mockito for testing Database connection

纵然是瞬间 提交于 2019-11-27 03:35:17
问题 I am using Junit to test my jersey api. I want to test DAO without a database. I tried using Mockito but still not able to use mock object to test the DAO which contains Hibernate calls to DB. I want to write Junit for my Helper class which calls the DAO.Can anyone provide a solution with some sample code to mock the DB Connections in DAO. EDIT : Status.java @GET @Produces(MediaType.TEXT_PLAIN) public String getDBValue() throws SQLException { DatabaseConnectionDAO dbConnectiondao = new

How to add a http proxy for Jersey2 Client

为君一笑 提交于 2019-11-27 02:09:55
问题 It's easy to set a proxy for client on Jersey1.x: config.getProperties().put(ApacheHttpClientConfig.PROPERTY_PROXY_URI, proxyUrl); But how to add a http proxy for Jersey2.x client? I checked the source code and didn't find the implementation does that in: org.glassfish.jersey.client.HttpUrlConnector Thanks! 回答1: thanks @feuyeux, the solution is work for me, ps, the code below is works in the proxy with http basic auth: ClientConfig config = new ClientConfig(); config.connectorProvider(new

How to resolve MessageBodyWriter not found for media type=multipart/form-data error

六月ゝ 毕业季﹏ 提交于 2019-11-26 21:48:28
问题 How to configure provider for simple multi-form post. Any suggestions/pointers would be much appreciated. Stacktrace: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=multipart/form-data, type=class org.glassfish.jersey.media.multipart.FormDataMultiPart, genericType=class org.glassfish.jersey.media.multipart.FormDataMultiPart. at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor

Cannot make basic http authentication work in Jersey

落爺英雄遲暮 提交于 2019-11-26 21:29:51
问题 I am trying to connect to a secure external rest service using Jersey 1.X version. I used the following code public class MyRestClient { private static final String API_USER_NAME = "some value"; private static final String API_PASSWORD = "some value"; private static final String REST_URL = "https://<somevalue>"; public static void main(String[] args) { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); client.addFilter(new HTTPBasicAuthFilter(API_USER_NAME

Jersey ClientResponse.getEntity of generic type

早过忘川 提交于 2019-11-26 16:17:51
问题 I got a problem to deserialize using jeresy ClientRespone.getEntity I've tried to follow some tutorials and questions, include this: http://jersey.576304.n2.nabble.com/How-can-I-parse-a-java-util-List-lt-gt-Is-it-supported-by-the-Jersey-client-td2300852.html https://jersey.java.net/nonav/documentation/1.5/json.html http://www.programcreek.com/java-api-examples/index.php?api=com.sun.jersey.api.client.GenericType and i still got the same exception over and over again.. My goal is: instead of:

Using SSLContext with just a CA certificate and no keystore

有些话、适合烂在心里 提交于 2019-11-26 13:18:40
问题 I need to setup a javax.net.ssl.SSLContext for use in a Jersey-Client application. All I want to do is the context to accept a custom root ca certificate. Is is really true that there is no way around of generating a keystore file and importing the CA certificate? 回答1: Is is really true that there is no way around of generating a keystore file and importing the CA certificate? There are way to do it without a keystore file, but since you would have to load the CA certificate you want to trust