Interceptor Headers not included in response - okhttp

Using Retrofit 2.1.0 and OkHttp 3.4.1
Test project https://github.com/liamheneghan/okhttpAuthenticatorInterceptTest
Retrofit is setup using an OkHttpClient with an Authenticator and Network Interceptor which will attach a header. When I get a 401 and enter the authenticator
response.request().headers()
Contains no headers. However, I can see that the network request did include the header from the network interceptor. Is this the correct way to access the headers attached via the Network Interceptor?

Does this work?
response.networkResponse().request().headers()

Related

WebClient in spring boot

I am using webclient to make 3rd party api call in spring boot.
I am making post request with authorization key in headers.
But I am facing unauthorized error.
here is the code :
https://stackoverflow.com/posts/72070182/revisions
Let me know how can we pass authorization key in headers with request body.

Not getting the API testing sampler in jmeter 3.2

I am using jmeter version 3.2 for REST API testing but i am not getting the API test request sampler in this version. Anyone who is working on the same version please let me know the option. Currently i am test the API through HTTP request sampler.
What do you mean by API test request? You should be able to test either SOAP or REST API endpoints using HTTP Request sampler, you will just need to add HTTP Header Manager to send Content-Type header, in your case it will most likely be application/json
References:
Building a SOAP WebService Test Plan
REST API Testing - How to Do it Right

Send Mock response for Soap Request

We have created an soap request and sending the request using WebServiceTemplate
WebServiceTemplate.marshalSendAndReceive(request)
As my client is not ready with the server. I am trying to handle this request in my local and planning to post some dummy response.
Can you help me how I can mock this response?
If you are using CXF, see my JUnit Rule utility project. It creates an Endpoint using JaxWsServerFactoryBean.

Adding authentication to outbound http requests

I have a rest web service that is implemented using spring boot starter web. This service acts as a client to another application that requires authentication to make calls to it.
Calls made from the client to the server are using org.springframework.web.client.RestTemplate.
Is there a way to come up with a solution to add authentication headers to outbound requests at one single point before they are sent out?
I don't want to add headers in each of the requests separately.
Javadoc for RestTemplate says:
This template uses a SimpleClientHttpRequestFactory and a
DefaultResponseErrorHandler as default strategies for creating HTTP
connections or handling HTTP errors, respectively. These defaults can
be overridden through
HttpAccessor.setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory)
So I would take SimpleClientHttpRequestFactory and override its prepareConnection(..) method.

401 Authorization Required on REST client

I am trying to write a very simple REST client using RestTemplate and Jackson JSON.
Tried such sample from spring.io Getting error 401 Authorization Required even on localhost or even if I include it into the same Tomcat6 Eclipse project where that REST WebService is running.
We don't require any authorization on that Web Service while in Dev or local environment,
and anyway I am an authorized user.
Is that something enforced by Spring RestTemplate?
Running client as Java application on Java 1.6.
I am new to REST and JSON.
No there is no enforced Authorization required by Spring's RestTemplate. You should be able to build or launch an example simple REST webservice and send requests to it with RestTemplate without receiving this response, so either the server you are sending the requests to or something inbetween is returning this response code. Can you share any more details of the service you are communicating with? Is it something internal or a public API which may require Authorization?

Resources