Mike
Mike

Reputation: 857

Adding headers in jersey 2.x

I am using jersey 2.25.1 and I am encountering a lots of changes. I've figured out most of them but I am stuck to declare the headers. I changed ClientResponse to Response and it seems like there is no header() method in the WebTarget to return Response.

Response response = webTarget
            .header( KeyConstants.REST_URI_APPENDERS, stringBuilder)
            .header( DocusignRESTContants.CONTENT_TYPE, MediaType.APPLICATION_JSON )
            .header( DocusignRESTContants.X_DOCUSIGN_AUTHENTICATION, getDocusignAuthHeader( cu ) )
            .accept( MediaType.APPLICATION_XML )
            .get( Response.class );

Is there a way to declare this in jersey 2.25.1

Thanks

Upvotes: 1

Views: 2187

Answers (1)

Justin Jose
Justin Jose

Reputation: 2171

Setting header is not part of web target. It is part of Request builder(Invocation.Builder) actually as shown below.

Response response = webTarget.request().
        .header( KeyConstants.REST_URI_APPENDERS, stringBuilder)
        .header( DocusignRESTContants.CONTENT_TYPE, MediaType.APPLICATION_JSON )
        .header( DocusignRESTContants.X_DOCUSIGN_AUTHENTICATION, getDocusignAuthHeader( cu ) )
        .accept( MediaType.APPLICATION_XML )
        .get(Response.class);

Upvotes: 5

Related Questions