In a JavaFx client application, jersey client 2 is used to send request to the server to fetch data. I control both server and client applications.
The time it takes from when client execute .get() to when server receive the request is not less than 8seconds. That is alot of time considering the request has just 2 path variable.
Spring framework is used for a dependency injection, and i have this in configuration file
#Bean
public WebTarget webTarget(){
ClientConfig config = new ClientConfig();
config.register(new JacksonJsonProvider());
final Client client = ClientBuilder.newClient(config);
client.register(new LoggingFilter());
return client.target(getBaseUri());
}
Then anywhere in service layer request to server needs to be made, a Webtarge is Autowired and additional request specific info is added like path and request variables.
What should i do to make request time(from start of request to server receiving request -- in localhost) minimal?
Update
When the same request with is made using Postman, request-response time is 2secs.
Related
I'm trying to setup up an http client to authenticate with spnego (apache http client 4.5.2)
Here's the code that setups the client
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
final CredentialsProvider credsProvider = new SystemDefaultCredentialsProvider();
credsProvider.setCredentials(new AuthScope(null, -1, null), new KerberosCredentials(null));
final HttpClientBuilder builder = HttpClientBuilder.create();
builder.setDefaultCredentialsProvider(credsProvider);
final ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(builder.build());
final Client client = new ResteasyClientBuilder().httpEngine(engine).build();
On the server, I have a JAX-RS service which is sitting behind a waffle.servlet.NegotiateSecurityFilter to allow for ntlm or spnego authentication.
When I send my HTTP request from my chrome rest client, it works, authentication is successfully completed using negotiate.
When I try and use the apache http client however, it fails with the message in the log:
2018-03-05 16:47:16,048 DEBUG o.a.h.impl.auth.GGSSchemeBase main Authentication already attempted
2018-03-05 16:47:16,048 DEBUG o.a.h.i.auth.HttpAuthenticator main Authentication failed
After some further investigation I've discovered that the waffle filter is encoutingering GSS_S_CONTINUE_NEEDED and responding with an additional challenge which the apache client is simply ignoring and giving up on.
I've tested my apache client setup against another service which uses spnego (provided by a 3rd party) and it works properly, although doesn't employ the continue token.
I'm not sure if my system is setup incorrectly, and that the continue token shouldn't be happeneing or if the apache http client is improperly configured (or doesn't support continue tokens at all)
There's a very old ticket here https://issues.apache.org/jira/browse/HTTPCLIENT-1107 indicating that something was added to handle additional challenges, but from reading the code in org.apache.http.impl.auth.GGSSchemeBase.parseChallenge(CharArrayBuffer, int, int) it looks as though only the first challange is ever accepted.
I am working on the integration testcases, as part of that different testcase i have set http timeout for a request means i would like to issue the http request to server but timeout should happen from client side before it receives the request. Since i am using CXF, i have changed as according the solution provided in official site,
How to configure the HTTPConduit for the SOAP Client?
I already a question exists,
changing client timeout for a particular request in Apache CXF
My problem,
I have java classes generated from cxf codegen plugin, where a interface is generated which has all the soap web service operations.
URL wsdl = getClass().getResource("wsdl/CustomerService_1.wsdl");
QName serviceName = new QName("srv.retail.app:ws:customer:1", "CustomerService_1");
QName portName =
new QName("srv.retail.app:ws:customer:1", "CustomerService_1PortTypeSoap11");
CustomerService_1 service = new CustomerService_1(wsdl, serviceName);
CustomerService1PortType customerServicePortType = service.getPort(portName, CustomerService1PortType.class);
Client client = ClientProxy.getClient(customerServicePortType);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setReceiveTimeout(300);
http.setClient(httpClientPolicy);
Tried different ways those are not working, will be great if you give inputs on this.
I am using OkHttp3 in my Android app to make HTTP/1.x requests to my backend servers via a forward proxy, like so:
List<Protocol> protos = new ArrayList<>();
protos.add(Protocol.HTTP_2);
protos.add(Protocol.HTTP_1_1);
InetSocketAddress proxyAddr = new InetSocketAddress("proxy.example.com", 80);
Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddr);
OkHttpClient cli = new OkHttpClient.Builder()
.proxy(proxy)
.protocols(protos)
.build();
String url = "http://www.example.com/";
Request req = new Request.Builder().url(url).build();
Response res = cli.newCall(req).execute();
I would like to upgrade to HTTP2. However, it seems to me that OkHttp3 can make HTTP2 requests only if we are not going via a HTTP proxy. So, the above code wouldn't work.
In other words, OkHttp3 supports the first 3 cases below but not the fourth. HTTP/2 below means h2 (HTTP/2 over TLS) not h2c (HTTP/2 over clear text).
a) client <-- HTTP/1.x --> upstream server
b) client <-- HTTP/1.x --> forward proxy <-- HTTP/x --> upstream server
c) client <-- HTTP/2 --> upstream server
d) client <-- HTTP/2 --> forward proxy <-- HTTP/x --> upstream server
Does anyone confirm or deny my understanding? Thanks.
OkHttp will do HTTP/2 over an HTTP proxy. You’ll need HTTPS on the server since OkHttp doesn’t implement plaintext HTTP/2.
Jesse, I tried retrieving https://www.google.com/ with Proxy.Type.HTTP via nghttp2's forward proxy nghttpx, which supports HTTP2 over TLS. Unfortunately, TLS handshaking did not happen and the forward proxy reported the following error.
... tls: handshake libssl error: error:1407609B:SSL routines:SSL23_GET_CLIENT_HELLO:https proxy request
From what I gather, this error means that okhttp3's proxy code is not doing TLS handshaking with the forward proxy.
This makes me think that HTTP2 over TLS via a forward proxy is kind of pointless, because the forward proxy won't be able to add any value to encrypted requests - the forward proxy is just a pass-through pipe. In fact, I think TLS via any forward proxy is pointless. End-to-end HTTP2 over TLS does make sense, but via a forward proxy doesn't.
I have a web app which consumes two webservice
• The 1st Webservice connects to external websserver over HHTPS
(https://abc.com/int/obj)
• The 2nd Webservice connects to internal websserver over HHTP
`(http://10.14.250.69:7250/uiu/ohg)
If i use
System.setProperty("https.proxyHost", "xxx.xxx.xx.xxx"); //proxy server
System.setProperty("https.proxyPort", "3128"); //proxy port
Then my application is able to connect successfully with the external website and fetch data, but when it invokes the 2nd Webservice the request are routed to the proxy Server which should not happen
All I want when it connects to this internal Webservice it should call it directly and not via proxy. How can I acheive that.Hoe can I bypass when the proxy server when it invkoes the interna Webservice
It is good to know that you are using Axis WS client. So instead of using the System properties that apply to both web services, can you set proxy setting at individual WS client stub level? Here is the sample code
MyServiceStub myService = new MyServiceStub("https://www.foo.com/abc/xyz.asmx");
HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.ProxyProperties();
proxyProperties.setDomain("mydomain");
proxyProperties.setProxyName("xx.xxx.xx.xxx");
proxyProperties.setProxyPort(80);
proxyProperties.setUserName("myusername");
proxyProperties.setPassWord("mypassword");
myService._getServiceClient().getOptions().setProperty(HTTPConstants.PROXY, proxyProperties);
Configure http.nonProxyHosts - a list of hosts or domains to connect to directly, separated by the "pipe" character | by adding 10.14.250.69 to the list.
I have a WCF based web service and hosted on local machine written in c#. I want to get a response from this hosted service in my GWT client side.
Please check the following code:
url = "localhost:8089/request"
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
Request response = builder.sendRequest(null, new RequestCallback() {
#override
public void onResponseReceived(Request request, Response response) {
Window.alert(response + " ");
}
});
Everytime when i am trying to run the code it shows an "http://localhost:8089 is not allowed by Access-Control-Allow-Origin."
PS: i searched for this error but i don't want to disable the web security of all browsers.
Is there any alternative solution to do get response of localhost server running on different porn on same machine. That is why i want to call a url in client side.
Please suggest a solution.
Edit
Let me explain you full scenario in points:
GWT application is hosted on some server (www.abc.com)
WCF is a web service installed at each client.
A client open his/her browser and put the url (www.abc.com/page)
This page want to access the web services hosted on a client machine.
Can't you configure your WCF service to send an Access-Control-Allow-Origin: www.abc.com response header?
Otherwise, I guess you could use a proxy servlet in www.abc.com that proxies the call to the getRemoteAddr, assuming there's no proxy in-between.