You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Niraj Patel <ni...@data.world> on 2018/09/08 20:00:28 UTC

How to send custom header per request

Hi!

I am using Jena's QueryEngineHTTP for queries and RemoteUpdateRequest for updates. I would like to send a custom header that will differ on each request. I did some digging around and it seems like it’s not possible. Using default headers when configuring Apache’s Http Client wouldn’t work in this case. Any ideas?

Niraj Patel

Re: How to send custom header per request

Posted by Niraj Patel <ni...@data.world>.
Thanks for the replies!

> For the future, Andy's suggestion of a "hook" in HTTP execution for manipulating requests sounds like a good one. Would that meet your needs,
> and if so, will you please file a ticket for it?
Yes, that would be great! Y’all already have a hook for responses so one for requests would fit that pattern. I will file a ticket.

Niraj Patel
On Sep 14, 2018, 8:16 AM -0500, users@jena.apache.org, wrote:
>
> For the future, Andy's suggestion of a "hook" in HTTP execution for manipulating requests sounds like a good one. Would that meet your needs,

Re: How to send custom header per request

Posted by ajs6f <aj...@apache.org>.
> On Sep 14, 2018, at 8:57 AM, Andy Seaborne <an...@apache.org> wrote:
> On 10/09/18 16:08, Niraj Patel wrote:
>> Thank you both for replying!
>>> Can you tell us more about your use case? Are the custom headers for some one particular purpose?
>> Sure! So our database, Allegrograph, allows us to pass down custom headers while querying or updating in order to store that information in access logs. For each SPARQL request we want to send down unique request markers and usernames in order to be able to trace from a UI click to backend calls to queries that were performed in the graph. Does that make sense? Do y’all have any ideas now that y’all know the use case?
> 
> Makes sense.
> 
> Adding HTTP header inform to track an operation end-to-end.
> 
> What might work is to have a point in the HttpOp execution flow that sees the HttpGet/HttpPost/... request just before it is acted upon.

Yes, this use case is quite reasonable. A couple of immediate options:

1. You can repeatedly swap out the client while changing default headers, as Andy describes, and that may work fine, especially if you keep a pool of clients and don't keep building completely fresh ones.

2. You can put some sort of proxy in place between your Jena client and Allegrograph, which adds the appropriate headers. That might or might not be workable depending on how you're sourcing the info to build the headers.

3. You can use low-level methods like building your own HTTP client, and Query::serialize to fill requests with your SPARQL. (There might be something better to use than Query::serialize for that.)

For the future, Andy's suggestion of a "hook" in HTTP execution for manipulating requests sounds like a good one. Would that meet your needs, and if so, will you please file a ticket for it?

ajs6f



Re: How to send custom header per request

Posted by Andy Seaborne <an...@apache.org>.

On 10/09/18 16:08, Niraj Patel wrote:
> Thank you both for replying!
> 
>> Can you tell us more about your use case? Are the custom headers for some one particular purpose?
> Sure! So our database, Allegrograph, allows us to pass down custom headers while querying or updating in order to store that information in access logs. For each SPARQL request we want to send down unique request markers and usernames in order to be able to trace from a UI click to backend calls to queries that were performed in the graph. Does that make sense? Do y’all have any ideas now that y’all know the use case?

Makes sense.

Adding HTTP header inform to track an operation end-to-end.

What might work is to have a point in the HttpOp execution flow that 
sees the HttpGet/HttpPost/... request just before it is acted upon.

> 
> Niraj Patel
> On Sep 9, 2018, 11:58 AM -0500, ajs6f <aj...@apache.org>, wrote:
>> If the header is going to change on every request, setting default headers may not be flexible enough-- the OP would have to change clients for every query.

Yes - but it works on the released version and isn't (I think) too 
expensive caveat it might break connection caching.

>>
>> Can you tell us more about your use case? Are the custom headers for some one particular purpose?
>>
>> In a released version, you may have to use your own HTTP client and just let Jena build the request bodies and parse the response bodies. We can look at adding this to the API in a future release, but I'd like to hear more about the use case first.
>>
>> ajs6f
>>
>>> On Sep 9, 2018, at 12:20 PM, Andy Seaborne <an...@apache.org> wrote:
>>>
>>>
>>>
>>> On 08/09/18 21:00, Niraj Patel wrote:
>>>> Hi!
>>>> I am using Jena's QueryEngineHTTP for queries and RemoteUpdateRequest for updates. I would like to send a custom header that will differ on each request. I did some digging around and it seems like it’s not possible. Using default headers when configuring Apache’s Http Client wouldn’t work in this case. Any ideas?
>>>> Niraj Patel
>>>
>>> Hi there,
>>>
>>> either create a QueryEngineHTTP directly passing in the required HttpClient specially created with setDefaultHeaders(headers)
>>>
>>> Also, have a look at the builder for RDFConnections that are remote: RDFConnectionRemote.create(RDFConnectionRemote)
>>>
>>> What's the use case for the custom header? I'm wondering if it is a usual or unusual situation.
>>>
>>> Andy
>>
> 

Re: How to send custom header per request

Posted by Niraj Patel <ni...@data.world>.
Thank you both for replying!

> Can you tell us more about your use case? Are the custom headers for some one particular purpose?
Sure! So our database, Allegrograph, allows us to pass down custom headers while querying or updating in order to store that information in access logs. For each SPARQL request we want to send down unique request markers and usernames in order to be able to trace from a UI click to backend calls to queries that were performed in the graph. Does that make sense? Do y’all have any ideas now that y’all know the use case?

Niraj Patel
On Sep 9, 2018, 11:58 AM -0500, ajs6f <aj...@apache.org>, wrote:
> If the header is going to change on every request, setting default headers may not be flexible enough-- the OP would have to change clients for every query.
>
> Can you tell us more about your use case? Are the custom headers for some one particular purpose?
>
> In a released version, you may have to use your own HTTP client and just let Jena build the request bodies and parse the response bodies. We can look at adding this to the API in a future release, but I'd like to hear more about the use case first.
>
> ajs6f
>
> > On Sep 9, 2018, at 12:20 PM, Andy Seaborne <an...@apache.org> wrote:
> >
> >
> >
> > On 08/09/18 21:00, Niraj Patel wrote:
> > > Hi!
> > > I am using Jena's QueryEngineHTTP for queries and RemoteUpdateRequest for updates. I would like to send a custom header that will differ on each request. I did some digging around and it seems like it’s not possible. Using default headers when configuring Apache’s Http Client wouldn’t work in this case. Any ideas?
> > > Niraj Patel
> >
> > Hi there,
> >
> > either create a QueryEngineHTTP directly passing in the required HttpClient specially created with setDefaultHeaders(headers)
> >
> > Also, have a look at the builder for RDFConnections that are remote: RDFConnectionRemote.create(RDFConnectionRemote)
> >
> > What's the use case for the custom header? I'm wondering if it is a usual or unusual situation.
> >
> > Andy
>

Re: How to send custom header per request

Posted by ajs6f <aj...@apache.org>.
If the header is going to change on every request, setting default headers may not be flexible enough-- the OP would have to change clients for every query.

Can you tell us more about your use case? Are the custom headers for some one particular purpose?

In a released version, you may have to use your own HTTP client and just let Jena build the request bodies and parse the response bodies. We can look at adding this to the API in a future release, but I'd like to hear more about the use case first.

ajs6f

> On Sep 9, 2018, at 12:20 PM, Andy Seaborne <an...@apache.org> wrote:
> 
> 
> 
> On 08/09/18 21:00, Niraj Patel wrote:
>> Hi!
>> I am using Jena's QueryEngineHTTP for queries and RemoteUpdateRequest for updates. I would like to send a custom header that will differ on each request. I did some digging around and it seems like it’s not possible. Using default headers when configuring Apache’s Http Client wouldn’t work in this case. Any ideas?
>> Niraj Patel
> 
> Hi there,
> 
> either create a QueryEngineHTTP directly passing in the required HttpClient specially created with setDefaultHeaders(headers)
> 
> Also, have a look at the builder for RDFConnections that are remote: RDFConnectionRemote.create(RDFConnectionRemote)
> 
> What's the use case for the custom header?  I'm wondering if it is a usual or unusual situation.
> 
>     Andy


Re: How to send custom header per request

Posted by Andy Seaborne <an...@apache.org>.

On 08/09/18 21:00, Niraj Patel wrote:
> Hi!
> 
> I am using Jena's QueryEngineHTTP for queries and RemoteUpdateRequest for updates. I would like to send a custom header that will differ on each request. I did some digging around and it seems like it’s not possible. Using default headers when configuring Apache’s Http Client wouldn’t work in this case. Any ideas?
> 
> Niraj Patel
> 

Hi there,

either create a QueryEngineHTTP directly passing in the required 
HttpClient specially created with setDefaultHeaders(headers)

Also, have a look at the builder for RDFConnections that are remote: 
RDFConnectionRemote.create(RDFConnectionRemote)

What's the use case for the custom header?  I'm wondering if it is a 
usual or unusual situation.

      Andy