i've following working code make async http call using rxclient(see import). however, when there json content, receive following error , couldn't figure out how can pass json parameter in case. fyi: json call post rest of code makes call. calls work w/o json content.
http error 411. request must chunked or have content length.</p>
import com.google.inject.inject; import org.glassfish.jersey.client.rx.rxclient; import org.glassfish.jersey.client.rx.rxinvocationbuilder; import org.glassfish.jersey.client.rx.rxwebtarget; import org.glassfish.jersey.client.rx.rxjava.rxobservableinvoker; import java.io.unsupportedencodingexception; import java.net.urlencoder; import javax.ws.rs.core.response; import rx.observable; import rx.functions.func1; import rx.schedulers.schedulers; public class emprxclient { private rxclient<rxobservableinvoker> httpclient; @inject public emprxclient(rxclient<rxobservableinvoker> httpclient) { this.httpclient = httpclient; } public <t> observable<t> fetchresult(string url, string token, string jsoncontent, string method, func1<response, t> mapper) { rxwebtarget<rxobservableinvoker> rxwebtarget = httpclient.target(url); rxinvocationbuilder<rxobservableinvoker> rxinvocationbuilder; if (jsoncontent != null&& rxwebtarget!=null) rxinvocationbuilder = rxwebtarget.request(jsoncontent); else rxinvocationbuilder = rxwebtarget.request(); return rxinvocationbuilder .header("authorization", "bearer " + token) .header("content-type", "application/json") .header("accept", "application/json") .header("grant_type", "client_credentials") .rx() .method(method) .subscribeon(schedulers.io()) .map(mapper); } }
Comments
Post a Comment