I'm building a JAX-RS 2.0 API and I am trying to add Link headers.
links.add(Link.fromUri(firstUri.build()).rel("first").build());
Link.Builder last = Link.fromUri(lastUri.build()).rel("last");
links.add(last.build());
return Response
.ok(content)
.header("X-Total-Count", totalCount)
.links(links.toArray(new Link[] {}))
.build();
So what I get is this:
HTTP/1.1 200 OK
X-Total-Count: 224
Link: <entities?limit=15&offset=70>;rel="next"
Link: <entities?limit=15&offset=40>;rel="prev"
Link: <entities?limit=15&offset=0>;rel="first"
Link: <entities?limit=15&offset=210>;rel="last"
Content-Type: application/json
But what I want is this:
HTTP/1.1 200 OK
X-Total-Count: 224
Link: <entities?limit=15&offset=70>;rel="next",<entities?limit=15&offset=40>;rel="prev",<entities?limit=15&offset=0>;rel="first",<entities?limit=15&offset=210>;rel="last"
Content-Type: application/json
So, am I doing something wrong or is JAX-RS just not sane?
Related
Using ADAL libs for java I managed to get Access,Refresh and ID Tokens using my office365 credentials.
Now my intention is using REST Web APIs, my intention is to create an entity, as a proof of concept. Based on my experience with other venders and REST APIs, once you have a valid token, you just add it as a Authorization header like:
Authorization=Bearer 709709JHKLJHKJLhHKHKJHKH...etc
Is something similar to this in Dynamic CRM 2016?
Here here is nice info about composing a POST http request, but I am missing the Authorization part... Any idea guys?
Here is a valid GET request to pull back accounts.
GET https://<CRM DOMAIN>.com/api/data/v8.1/accounts HTTP/1.1
Authorization: Bearer:<TOKEN GOES HERE>
Host: <CRM DOMAIN>.com
And here is a valid POST
POST https://<CRM DOMAIN>.com/api/data/v8.1/accounts HTTP/1.1
Content-Type: application/json; charset=utf-8
Accept: application/json
Authorization: Bearer:<TOKEN GOES HERE>
Host: <CRM DOMAIN>.com
Content-Length: 224
{
"name": "Sample Account",
"creditonhold": false,
"address1_latitude": 47.639583,
"description": "This is the description of the sample account",
"revenue": 5000000,
"accountcategorycode": 1
}
I have read this: compress-responses-in-jersey and have Jersey 2 config:
#ApplicationPath("/jaxrs/")
public class AppConfig extends ResourceConfig {
public AppConfig() {
super(AdvertisementResource.class, MultiPartFeature.class);
packages("jaxrs");
EncodingFilter.enableFor(this, GZipEncoder.class, DeflateEncoder.class);
}
}
I have header Request:
GET http://localhost:8081/jaxrs/admin-adblock
Accept:application/json
Cache-Control:no-cache
Content-Type:application/json
Authorization:Basic c21h...
Accept-Encoding:gzip,deflate
But header response are:
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
Server: Jetty(9.2.2.v20140723)
Header in response Content-Encoding:gzip is missing only Vary: Accept-Encoding is appear if I have:
EncodingFilter.enableFor(this, GZipEncoder.class, DeflateEncoder.class);
If I remove compression and comment EncodingFilter row response header are:
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Server: Jetty(9.2.2.v20140723)
or this:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 369
Server: Jetty(9.2.2.v20140723)
I`m testing with Intellij Rest Client Tool and I`m not sure if I receive compressed response from server?
I have download jersey sources and set breakpoint here and debug rest service web application with Intellij it appears that CONTENT_ENCODING gzip is added here:
response.getHeaders().putSingle(HttpHeaders.CONTENT_ENCODING, contentEncoding);
but its missing in response header from Intellij Rest Client tool..
I have download SoapUI and test the same Rest requests response headers:
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 204
Server: Jetty(9.2.2.v20140723)
The Intellij Rest Client Tool is hiding response headers Content-Encoding and Content-Length..
I have open new issue
I am able to set content type using cxf library but I don't know how to set Authorization header. Whenever I set user name and password then it set Authorization header and encode whole value and add Basic. I don't want to do this. I want to add Authorization header with plain string which ever I provide. Please help me to solve out this problem.
AMPServices services = new AMPServices();
CoreXmlPort coreXmlPort = services.getAMPSoapService();
Client client = ClientProxy.getClient(coreXmlPort);
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy=httpConduit.getClient();
String contentType=httpClientPolicy.getContentType();
contentType="application/soap+xml; type=vnd.iShip.AMP.SOAP; charset=UTF-8";
httpClientPolicy.setContentType(contentType);
AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
authorizationPolicy.setUserName("username");
authorizationPolicy.setPassword("password");
httpConduit.setAuthorization(authorizationPolicy);
It generates following request xml.
POST https://api.iship.com/Root/Enterprises/Pitney%20Bowes/Progistics; HTTP/1.1
Content-Type: application/soap+xml; type=vnd.iShip.AMP.SOAP; charset=UTF-8
Accept: */*
Authorization: Basic aXNoaXAgcGIvd3NkZXZlbDowNzZhNjFjYTM5MDcxODAxODVjNWRkMjM2YTdkMzZhNGQ1ODg5OWFj
User-Agent: Apache CXF 3.1.0
Cache-Control: no-cache
Pragma: no-cache
Host: api.iship.com
Connection: keep-alive
Content-Length: 246
But I want this type of request
POST https://api.iship.com/Root/Enterprises/Pitney%20Bowes/Progistics; HTTP/1.1
Content-Type: application/soap+xml; type=vnd.iShip.AMP.SOAP; charset=UTF-8
Accept: */*
Authorization: username;password
User-Agent: Apache CXF 3.1.0
Cache-Control: no-cache
Pragma: no-cache
Host: api.iship.com
Connection: keep-alive
Content-Length: 246
But I was not able to do it. Please help me to solve out this problem.
Thanks,
Awadhendra
I think you are trying to call is a RestFul Service, so that's why the server side always response with a different content type than you expected (json instead of soap/xml). Is your url endpoint based on http protocol? If yes, do you need send additional parameters to this url?
The issue here is that the client you are using to interact with Webservice expecting XML based Soap Messages , while the service is serving JSON as a return media.
Either convert your client to use the JSON format and communicate using that, or alternatively use the XML based endpoint , consult with webservice provider for that.
I am doing this request:
POST request to
https://accounts.google.com/o/oauth2/token?
client_secret=xxxxx-x8U-tDOJbCPN3&
grant_type=authorization_code&
redirect_uri=[url]
client_id=xxxxxx-e4u1224f7uqjafv7m1lu2ek5ac01isi4.apps.googleusercontent.com&
code=xxxxxxlpdiZfd_LhYu167gK.QvJZYyoaoQAQ3oEBd8DOtNC9kGrnjwI
So, as doc says, i make that request with these headers:
"Accept-Encoding": "gzip"
"Content-Type": "application/x-www-form-urlencoded"
But when i do it i am getting a 400:
{"error":"invalid_request","error_description":"Required parameter is missing: grant_type"}
I have already solved this. The problem was that i was sending params in query string, and the correct way was sending them as x-www-form-urlencoded. So the correct request had to be like this:
POST /o/oauth2/token? HTTP/1.1
Host: accounts.google.com
Cache-Control: no-cache
Postman-Token: b38df5b3-b64f-338a-1374-220647ee05a0
Content-Type: application/x-www-form-urlencoded
client_secret=xxxxx-x8U-tDOJbCPN3%26&grant_type=authorization_code&redirect_uri=myredirecturi&client_id=xxxxxx-e4u1224f7uqjafv7m1lu2ek5ac01isi4.apps.googleusercontent.com&code=xxxxxxlpdiZfd_LhYu167gK.QvJZYyoaoQAQ3oEBd8DOtNC9kGrnjwI
Hope this helps
had a similar problem, but in my case it was postman leaving a stupid Content-Type:application/json in the header!
Hope this might avoid my struggling for someone having the same issue!
im using a generated axis client to consume a service that requires headers
when using SOAPUI, i add the headers and the request looks like this
POST https://fttoo/service/v3.2/SOAP HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Authorization: Bearer 123
Content-Length: 270
Host: my host
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
when trying to set the headers with code i'm doing the following
proxy = (SessionServiceImplServiceSoapBindingStub)locator.getSessionService();
proxy._setProperty("Authorization", "Bearer 123");
this is not working well and i get Error 401, when inspecting the proxy object i see that a property called cachedProperties has the value of {Authorization=Bearer 123}
I've also tried proxy._setProperty(HTTPConstants.HEADER_AUTHORIZATION, "Bearer 123");
and also inside the stub, in the _call object....
given the fact that axis 1 is very old i generated a new web client using CXF instead of Axis, this way i was able to use cxf api to place the headers