How to check if custom headers attribute exist

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to check if custom headers attribute exist

cw storm
Please forgive me but I have a simple question.  How can I check to see if there's custom header attribute exist or not before I perform the below:

String strFirstName = props.getHeaders().get("FirstName").toString()

I believe if there's no custom headers, then it'll exception.

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: How to check if custom headers attribute exist

Tim Watson-6
BasicProperties#getHeaders() returns a Map, so Map#get(key) will return `null' if the key isn't present. It's your #toString() on `null' that is likely causing the problem. You could also call Map#containsKey("FirstName") instead of checking for `null' if you prefer.

Cheers,
Tim

On 30 Jan 2014, at 16:30, cw storm wrote:

> Please forgive me but I have a simple question.  How can I check to see if there's custom header attribute exist or not before I perform the below:
>
> String strFirstName = props.getHeaders().get("FirstName").toString()
>
> I believe if there's no custom headers, then it'll exception.
> _______________________________________________
> rabbitmq-discuss mailing list
> [hidden email]
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: How to check if custom headers attribute exist

cw storm
Thanks Tim.  How do code to see if the key is there or not?


On Thu, Jan 30, 2014 at 11:58 AM, Tim Watson <[hidden email]> wrote:
BasicProperties#getHeaders() returns a Map, so Map#get(key) will return `null' if the key isn't present. It's your #toString() on `null' that is likely causing the problem. You could also call Map#containsKey("FirstName") instead of checking for `null' if you prefer.

Cheers,
Tim

On 30 Jan 2014, at 16:30, cw storm wrote:

> Please forgive me but I have a simple question.  How can I check to see if there's custom header attribute exist or not before I perform the below:
>
> String strFirstName = props.getHeaders().get("FirstName").toString()
>
> I believe if there's no custom headers, then it'll exception.
> _______________________________________________
> rabbitmq-discuss mailing list
> [hidden email]
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: How to check if custom headers attribute exist

cw storm
Does this look right?

Map<String,object> headers = properties.getHeaders();

if (headers.containsKey("FirstName")) {
        String strFirstName = props.getHeaders().get("FirstName").toString();
}



On Thu, Jan 30, 2014 at 12:18 PM, cw storm <[hidden email]> wrote:
Thanks Tim.  How do code to see if the key is there or not?


On Thu, Jan 30, 2014 at 11:58 AM, Tim Watson <[hidden email]> wrote:
BasicProperties#getHeaders() returns a Map, so Map#get(key) will return `null' if the key isn't present. It's your #toString() on `null' that is likely causing the problem. You could also call Map#containsKey("FirstName") instead of checking for `null' if you prefer.

Cheers,
Tim

On 30 Jan 2014, at 16:30, cw storm wrote:

> Please forgive me but I have a simple question.  How can I check to see if there's custom header attribute exist or not before I perform the below:
>
> String strFirstName = props.getHeaders().get("FirstName").toString()
>
> I believe if there's no custom headers, then it'll exception.
> _______________________________________________
> rabbitmq-discuss mailing list
> [hidden email]
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss



_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: How to check if custom headers attribute exist

cw storm
Actually, I need to check if "FirstName" is null or not in order to use toString().


On Thu, Jan 30, 2014 at 12:26 PM, cw storm <[hidden email]> wrote:
Does this look right?

Map<String,object> headers = properties.getHeaders();

if (headers.containsKey("FirstName")) {
        String strFirstName = props.getHeaders().get("FirstName").toString();
}



On Thu, Jan 30, 2014 at 12:18 PM, cw storm <[hidden email]> wrote:
Thanks Tim.  How do code to see if the key is there or not?


On Thu, Jan 30, 2014 at 11:58 AM, Tim Watson <[hidden email]> wrote:
BasicProperties#getHeaders() returns a Map, so Map#get(key) will return `null' if the key isn't present. It's your #toString() on `null' that is likely causing the problem. You could also call Map#containsKey("FirstName") instead of checking for `null' if you prefer.

Cheers,
Tim

On 30 Jan 2014, at 16:30, cw storm wrote:

> Please forgive me but I have a simple question.  How can I check to see if there's custom header attribute exist or not before I perform the below:
>
> String strFirstName = props.getHeaders().get("FirstName").toString()
>
> I believe if there's no custom headers, then it'll exception.
> _______________________________________________
> rabbitmq-discuss mailing list
> [hidden email]
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss




_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: How to check if custom headers attribute exist

cw storm
Can I do a check something like below?

if (headers.getHeaders().get("FirstName") != null))


On Thu, Jan 30, 2014 at 12:35 PM, cw storm <[hidden email]> wrote:
Actually, I need to check if "FirstName" is null or not in order to use toString().


On Thu, Jan 30, 2014 at 12:26 PM, cw storm <[hidden email]> wrote:
Does this look right?

Map<String,object> headers = properties.getHeaders();

if (headers.containsKey("FirstName")) {
        String strFirstName = props.getHeaders().get("FirstName").toString();
}



On Thu, Jan 30, 2014 at 12:18 PM, cw storm <[hidden email]> wrote:
Thanks Tim.  How do code to see if the key is there or not?


On Thu, Jan 30, 2014 at 11:58 AM, Tim Watson <[hidden email]> wrote:
BasicProperties#getHeaders() returns a Map, so Map#get(key) will return `null' if the key isn't present. It's your #toString() on `null' that is likely causing the problem. You could also call Map#containsKey("FirstName") instead of checking for `null' if you prefer.

Cheers,
Tim

On 30 Jan 2014, at 16:30, cw storm wrote:

> Please forgive me but I have a simple question.  How can I check to see if there's custom header attribute exist or not before I perform the below:
>
> String strFirstName = props.getHeaders().get("FirstName").toString()
>
> I believe if there's no custom headers, then it'll exception.
> _______________________________________________
> rabbitmq-discuss mailing list
> [hidden email]
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss





_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: How to check if custom headers attribute exist

cw storm
Nevermind.  I was able to get around my issue.  During publish, I should not populate the key.  That way, during consumption, I can use the method "containsKey" properly.  Thanks.

-PH


On Thu, Jan 30, 2014 at 12:38 PM, cw storm <[hidden email]> wrote:
Can I do a check something like below?

if (headers.getHeaders().get("FirstName") != null))


On Thu, Jan 30, 2014 at 12:35 PM, cw storm <[hidden email]> wrote:
Actually, I need to check if "FirstName" is null or not in order to use toString().


On Thu, Jan 30, 2014 at 12:26 PM, cw storm <[hidden email]> wrote:
Does this look right?

Map<String,object> headers = properties.getHeaders();

if (headers.containsKey("FirstName")) {
        String strFirstName = props.getHeaders().get("FirstName").toString();
}



On Thu, Jan 30, 2014 at 12:18 PM, cw storm <[hidden email]> wrote:
Thanks Tim.  How do code to see if the key is there or not?


On Thu, Jan 30, 2014 at 11:58 AM, Tim Watson <[hidden email]> wrote:
BasicProperties#getHeaders() returns a Map, so Map#get(key) will return `null' if the key isn't present. It's your #toString() on `null' that is likely causing the problem. You could also call Map#containsKey("FirstName") instead of checking for `null' if you prefer.

Cheers,
Tim

On 30 Jan 2014, at 16:30, cw storm wrote:

> Please forgive me but I have a simple question.  How can I check to see if there's custom header attribute exist or not before I perform the below:
>
> String strFirstName = props.getHeaders().get("FirstName").toString()
>
> I believe if there's no custom headers, then it'll exception.
> _______________________________________________
> rabbitmq-discuss mailing list
> [hidden email]
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss






_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: How to check if custom headers attribute exist

Tim Watson-6
On 30 Jan 2014, at 18:24, cw storm wrote:

> Nevermind.  I was able to get around my issue.  During publish, I should not populate the key.  That way, during consumption, I can use the method "containsKey" properly.  Thanks.
>

Glad you figured it out.

Cheers,
Tim
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss