1) It is not a requirement to use a proxy 2) No reason you can't have a different proxy for your client 3) No reason you can't change your server-side class that implements this interface to have a getXML() and getJSON() methods.
IMO, I think what you all are doing is a hack. On 1/8/2013 2:02 AM, Dieter Cailliau wrote: > I use a ClientInterceptor for that (the code also takes care of basic > auth, timeouts and ssh-without-hostname-verification). > > ApacheHttpClient4Executor ex = new > ApacheHttpClient4Executor(getBasicAuthClient(LOGIN,PASS, > "application/json", null, new > SingleClientConnManager(getSSHBypassScheme(443)),timeoutMs)); > return ProxyFactory.create(XYZ.class, "https://" + host + > href, ex); > > > public static DefaultHttpClient getBasicAuthClient(final String > login, final String pass, final String acceptType, final String > contentType, ClientConnectionManager ccm, int timeoutMs) throws > NoSuchAlgorithmException, KeyManagementException { > DefaultHttpClient c2 = new DefaultHttpClient(ccm); > c2.addRequestInterceptor(new HttpRequestInterceptor() { > public void process(HttpRequest arg0, HttpContext arg1) > throws HttpException, IOException { > arg0.addHeader("Authorization", > HTTPUtils.getBasicEncodedAuth(login, pass)); > arg0.addHeader("Accept", acceptType); > if (contentType != null) { > arg0.addHeader("ContentType",contentType); > } > } > }); > HttpParams httpParams = c2.getParams(); > HttpConnectionParams.setConnectionTimeout(httpParams, timeoutMs); > HttpConnectionParams.setSoTimeout(httpParams, timeoutMs); > HttpConnectionParams.setSoReuseaddr(httpParams, true); > > c2.setParams(httpParams); > return c2; > } > > public static synchronized SchemeRegistry getSSHBypassScheme(int > port) throws KeyManagementException, NoSuchAlgorithmException { > if (schemeRegistry==null) { > SSLSocketFactory sf = new SSLSocketFactory(getSSLContext(), > SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) { > public java.net.Socket connectSocket(java.net.Socket > arg0, java.net.InetSocketAddress arg1, java.net.InetSocketAddress arg2, > HttpParams arg3) throws IOException ,java.net.UnknownHostException > ,org.apache.http.conn.ConnectTimeoutException { > int port = arg1.getPort(); > InetAddress addr = cache.get(arg1.getAddress()); > arg1 = new InetSocketAddress(addr,port); > return super.connectSocket(arg0, arg1, arg2, arg3); > }; > }; > Scheme httpsScheme = new Scheme("https", port, sf); > schemeRegistry = new SchemeRegistry(); > schemeRegistry.register(httpsScheme); > } > return schemeRegistry; > } > > > > 2013/1/7 Bill Burke <bbu...@redhat.com <mailto:bbu...@redhat.com>> > > Why not just ditch using the proxy? Or create a new different interface > with the specs you want? Overriding Exxecutor.exeucte() is a hack. > > On 1/7/2013 4:38 PM, kishore panda wrote: > > > > Hello, > > > > Query: How to ensure server sends JSON Media, when server is set > with both Application_XML and Application_JSON Media Types (Produces > annotation). > > > > I am executing a RESTEasy POC. > > > > I updated the server to accept and respond with both XML and JSON > Media type. > > > > @POST > > @Path("/getData/") > > @Produces({MediaType.APPLICATION_XML, > MediaType.APPLICATION_JSON}) > > @Consumes({MediaType.APPLICATION_XML, > MediaType.APPLICATION_JSON}) > > public RestReqRes getData(Data request); > > > > In the client code, I have done this: > > > > this.clientService = > ProxyFactory.create(clientService.class, baseURL, > > getExecutor()); > > > > > > and Override execute() method in ApacheHttpClient4Executor. > > > > request.accept(MediaType.APPLICATION_JSON); > > request.body("application/json", request.getBody()); > > return super.execute(request); > > > > > > When the client is used to POST the Request, like > > clientService.getData(new Data()); > > > > I found the below > > The accept header in the Request is updated with "application/xml". > > > > This happens due to > > org.jboss.resteasy.client.core.marshallers.ClientMarshallerFactory.createMarshaller() > method, which calls org.jboss.resteasy.util.getConsumes() method. > > > > The getConsumes() method returns the consume.value()[0] media > type which is 'application/xml' in this case. > > > > > > When request.accept(MediaType.APPLICATION_JSON); is executed the > accept header in the request is updated with > > 'application/xml, application/json' > > > > Due to this the server always responds with xml format. > > > > Is there anyway I can override this so that the server responds > JSON media as per the request. > > > > Thank you, > > Malaya Kishore > > > > > > ------------------------------------------------------------------------------ > > Master Visual Studio, SharePoint, SQL, ASP.NET <http://ASP.NET>, > C# 2012, HTML5, CSS, > > MVC, Windows 8 Apps, JavaScript and much more. Keep your skills > current > > with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft > > MVPs and experts. SALE $99.99 this month only -- learn more at: > > http://p.sf.net/sfu/learnmore_122412 > > _______________________________________________ > > Resteasy-users mailing list > > Resteasy-users@lists.sourceforge.net > <mailto:Resteasy-users@lists.sourceforge.net> > > https://lists.sourceforge.net/lists/listinfo/resteasy-users > > > > -- > Bill Burke > JBoss, a division of Red Hat > http://bill.burkecentral.com > > > ------------------------------------------------------------------------------ > Master Visual Studio, SharePoint, SQL, ASP.NET <http://ASP.NET>, C# > 2012, HTML5, CSS, > MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current > with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft > MVPs and experts. SALE $99.99 this month only -- learn more at: > http://p.sf.net/sfu/learnmore_122412 > _______________________________________________ > Resteasy-users mailing list > Resteasy-users@lists.sourceforge.net > <mailto:Resteasy-users@lists.sourceforge.net> > https://lists.sourceforge.net/lists/listinfo/resteasy-users > > > > > ------------------------------------------------------------------------------ > Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS > and more. Get SQL Server skills now (including 2012) with LearnDevNow - > 200+ hours of step-by-step video tutorials by Microsoft MVPs and experts. > SALE $99.99 this month only - learn more at: > http://p.sf.net/sfu/learnmore_122512 > > > > _______________________________________________ > Resteasy-users mailing list > Resteasy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/resteasy-users > -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com ------------------------------------------------------------------------------ Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS and more. Get SQL Server skills now (including 2012) with LearnDevNow - 200+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only - learn more at: http://p.sf.net/sfu/learnmore_122512 _______________________________________________ Resteasy-users mailing list Resteasy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/resteasy-users