Home How to add form param to ClientInvocation while upgrading from RESTEasy 3.0.9 to 3.1.4?
Reply: 0

How to add form param to ClientInvocation while upgrading from RESTEasy 3.0.9 to 3.1.4?

user4945
1#
user4945 Published in April 23, 2018, 9:26 am

I had client request being returned by getRestClient() with request made using RESTEasy 3.0.9 as follows:

public static RestClientClass getRestClient(String uri_argument) {
        HttpConnectionManagerParams params = getHttpClient().getHttpConnectionManager().getParams();
    params.setConnectionTimeout(0);         
    final ClientExecutor clientExecutor = new ApacheHttpClient4Executor() {
        @Override
        public ClientResponse execute(ClientRequest request) throws Exception {
            if (!keyToken.equals("")) {
                request.formParameter("key", value);
            }
            return super.execute(request);
        }
    };
    RestClientClass client = ProxyFactory.create(RestClientClass.class, uri_argument, clientExecutor);
    return client;
}

In 3.1.4 RestEasy, the client framework is moved to jax rs 2.0 and so I am updating this code to be handled by new classes

But I am not able to send form parameter to the ClientRequest in Resteasy 3.1.4 and then use the proxy framework to make and return the client.

Ive tried the following methods till now:

1)

public static RestClientClass getRestClient(String uri_argument) {
  HttpConnectionManagerParams params = getHttpClient().getHttpConnectionManager().getParams();
  params.setConnectionTimeout(0);

  ResteasyClient rsclient = new ResteasyClientBuilder().build();
  ResteasyWebTarget target = rsclient.target(uri_argument);

  Form form = new Form().param("key", value);
  Invocation invocation = target.request().buildPost(Entity.form(form));
  invocation.invoke()


  RestClientClass client = target.proxy(RestClientClass.class);
  return client;

  }

But in this invocation is not able to call proxy to make client

2)

 public static RestClientClass getRestClient(String uri_argument) {
     HttpConnectionManagerParams params = getHttpClient().getHttpConnectionManager().getParams();
 params.setConnectionTimeout(0);

 ResteasyClient rsclient = new ResteasyClientBuilder().build();
 ResteasyWebTarget target = rsclient.target(uri_argument);

 Form form = new Form().param("key", value);
// Invocation invocation = target.request().buildPost(Entity.form(form));

 final ClientHttpEngine clientHttpEngine = new ApacheHttpClient4Engine() {

    @Override
    public ClientResponse invoke(ClientInvocation request) {
        if (!keyToken.equals("")) {
            request.setEntity(Entity.form(form));
        }
        return super.invoke(request); 
    }

 };


 RestClientClass client = target.proxy(RestClientClass.class);
 return client;

 }

I am unsure if request.setEntity will set the form parameter for the request just like before and target.proxy will create the client object that can be used further to get the resopnse.

Im getting this error:

javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request
        at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:316)
        at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:462)
        at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:105)
        at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
        at com.sun.proxy.$Proxy20.logout(Unknown Source)
        at JoinsAndViews.Joins.ES.Logout.testlogout_1(Logout.java:21)
        at JoinsAndViews.Joins.ES.BaseEntityNoClobWFEnabled.BaseEntityNoClobWFEnabled.logout(BaseEntityNoClobWFEnabled.java:122)
        at JoinsAndViews.Joins.ES.BaseEntityNoClobWFEnabled.BaseEntityNoClobWFEnabled.main(BaseEntityNoClobWFEnabled.java:57)
Caused by: java.lang.IllegalStateException: Connection is still allocated
        at org.apache.http.util.Asserts.check(Asserts.java:34)
        at org.apache.http.impl.conn.BasicHttpClientConnectionManager.getConnection(BasicHttpClientConnectionManager.java:266)
        at org.apache.http.impl.conn.BasicHttpClientConnectionManager$1.get(BasicHttpClientConnectionManager.java:217)
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:190)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
        at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:312)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.554459 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO