Monday, 9 September 2013

Camel HTTP authentication fails but call works with curl

Camel HTTP authentication fails but call works with curl

I'm constructing a Camel route that will make calls to Twilio's SMS API to
send SMSs. However, it is failing with a 401 authentication error. I've
copied my config from this worked example and validated that my
credentials are sound by curl-ing the call. However, I can't work out what
I'm missing on the Camel side.
My Camel HTTP integration with APIs that don't enforce authentication all
work fine and the URL for the Twilio call is being fed correctly (using
the header *Exchange.HTTP_QUERY*).
Any help much appreciated. Thanks.
Here's my Blueprint-OSGi Camel route:-
<camelContext id="jellyfish-messaging-sms" errorHandlerRef="deadLetterQueue"
trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<route id="sms.twilio">
<from uri="activemq:sms.twilio" />
<setHeader headerName="Content-Type">
<constant>application/x-www-form-urlencoded</constant>
</setHeader>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<to
uri="https://api.twilio.com/2010-04-01/Accounts/{{sms.accountSid}}/SMS/Messages"
/>
</route>
</camelContext>
<!-- BEANS -->
<bean id="httpAuth"
class="org.apache.camel.component.http.HttpConfiguration">
<property name="authMethod" value="Basic"/>
<property name="authUsername" value="${sms.accountSid}"/>
<property name="authPassword" value="${sms.authToken}"/>
</bean>
<bean id="http" class="org.apache.camel.component.http.HttpComponent">
<property name="camelContext" ref="jellyfish-messaging-sms"/>
<property name="httpConfiguration" ref="httpAuth"/>
</bean>
Here's the exception (from karaf.log):-
2013-09-09 17:37:27,627 | INFO | umer[sms.twilio] | HttpMethodDirector
| 366 - org.apache.servicemix.bundles.commons-httpclient -
3.1.0.7 | No credentials available for BASIC 'Twilio
API'@api.twilio.com:443
2013-09-09 17:37:27,632 | ERROR | umer[sms.twilio] | jellyfish-messaging
| 266 - org.apache.camel.camel-core - 2.10.2 | Dead letter
interceptor invoked
2013-09-09 17:37:27,635 | ERROR | umer[sms.twilio] | sms
| 266 - org.apache.camel.camel-core - 2.10.2 |
Exchange[ExchangePattern:InOnly, BodyType:String, Body:Nothing to see
here,
CaughtExceptionType:org.apache.camel.component.http.HttpOperationFailedException,
CaughtExceptionMessage:HTTP operation failed invoking
https://api.twilio.com/2010-04-01/Accounts/...snip.../SMS/Messages?From=%2B44...snip...&To=%2B44...snip...&Body=fred
with statusCode: 401,
StackTrace:org.apache.camel.component.http.HttpOperationFailedException:
HTTP operation failed invoking
https://api.twilio.com/2010-04-01/Accounts/...snip.../SMS/Messages?From=%2B44...snip...&To=%2B44...snip...&Body=fred
with statusCode: 401 at
org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:229)
at
org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:157)
And here's the working curl:-
curl -X POST
https://api.twilio.com/2010-04-01/Accounts/...snip.../SMS/Messages -u
...snip...:...snip... -d "From=+44...snip..." -d "To=+44...snip..." -d
'Body=Hello'

C#, How to delete copy-pase with handlers

C#, How to delete copy-pase with handlers

Please say about "How optimally" rewrite this code without copy-paste. Now
I have two handlers with equivalent lambda handlers... Sorry for more code
and bad style ((
wc.DownloadStringCompleted += (sender, args) =>
{
try
{
res = (T)(object)args.Result;
var cook = Regex.Matches(wc.ResponseHeaders.ToString(),
"Set\\-Cookie:\\s*([\\w\\-_\\.]+\\s*=\\s*[^;]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled |
RegexOptions.Singleline);
foreach (Match val in cook)
cookies += val.Groups[1].Value.Trim() + "; ";
isComplited = true;
}
catch (Exception e)
{
lastError = e.InnerException.Message;
}
};
wc.UploadDataCompleted += (sender, args) =>
{
try
{
res = (T)(object)args.Result;
var cook = Regex.Matches(wc.ResponseHeaders.ToString(),
"Set\\-Cookie:\\s*([\\w\\-_\\.]+\\s*=\\s*[^;]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled |
RegexOptions.Singleline);
foreach (Match val in cook)
cookies += val.Groups[1].Value.Trim() + "; ";
isComplited = true;
}
catch (Exception e)
{
lastError = e.InnerException.Message;
}
};

validation enable/disable on class properties

validation enable/disable on class properties

Sorry for the title, don't know what should I use for this issue.
Issue is I am using Attributes & reflection for validation implementation
in my C# application something like this.
public class foo : validationBase
{
[RequiredAttribute("id is required")]
public int id { get; set; }
[RequiredAttribute("name is required")]
public string name { get; set; }
void save()
{
this.IsValid();
//some code
}
void update()
{
this.IsValid();
//some code
}
void delete()
{
// Need some magic here to ignore name attribute's required
validation as only id
// is needed for delete operation
this.IsValid();
//some code
}
}
as you may see in delete operation I don't want to validate name
property's required validation, NOTE there may be some more validation
attributes to a single property and there could be a requirement that one
attribute's validation should not fire but other's should.
Please provide you views to solve this one.

Possible to set a downloaded You Tube video as SCREEN SAVER on home screen in Blackberry?

Possible to set a downloaded You Tube video as SCREEN SAVER on home screen
in Blackberry?

I am working on an application in which I need to download the You Tube
Videos from my application.
By using these videos I have to set them as an SCREEN SAVER.
Can we download the videos from YOU TUBE programmatic?
Can we show them as an SCREEN SAVER on my home screen?

Sunday, 8 September 2013

How to use function's variables inside function's scope in VHDL?

How to use function's variables inside function's scope in VHDL?

Actually I'm new in VHDL, I'm trying to assign a function's variable to a
variable declared in functions scope. But I'm getting an error when I'm
synthesizing. I'm using ISE Project Navigator. Here's my code.
function moverDerecha(datos : std_logic_vector(2 downto 0)) RETURN
std_logic_vector(2 downto 0) IS
variable TMP : datos;
--TMP := datos;
begin
TMP(0)<=TMP(2);
TMP(1)<=TMP(0);
TMP(2)<=TMP(1);
return TMP;
end moverDerecha;
I hope you could help me! It's part of my homework n.n.

Adding APC to Symfony project causes Fatal Error

Adding APC to Symfony project causes Fatal Error

Very new to Symfony so apologies if the answer is obvious. I am trying to
add APC to a project to see if it improves performance. I am running
symfony with easyphp on Windows 7/Windows 8 (installed on usb). APC is
installed in ext folder and added to php.ini file as:
extension=php_apc.dll
then at end of file:
[APC]
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 128M
apc.max_file_size = 5M
apc.stat = 1
php works fine with these settings. However when I now try to load my
Symfony project I get the following error:
FatalErrorException: Compile Error: Cannot redeclare class
Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain in
F:\EasyPHP\data\localweb\projects\SymfonyProj\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain.php
line 36
Not sure if I have my caching set up all wrong or I am missing some config
options somewhere?

How to handle enum parameters properly?

How to handle enum parameters properly?

This question is about a certain bad programming practice. I am looking
for some good article that explains about it and why it's bad.
Unfortunately, I don't know any name or jargon for this practice. So I
will try to describe it instead and ask you to tell me how it's called and
maybe refer me to a good article on the subject.
Suppose we have some enum:
public enum Day
{
SUNDAY, MONDAY, ...
}
Next, suppose that the server-side programmer attaches a numeric id to
each day. The correct thing to do, of course, is to map each Day to an
Integer using an EnumMap, which is defined and used only within the
server-side code. Instead, he messes up the common code and adds a getId()
method:
public enum Day
{
SUNDAY {public int getId() {return 100;}},
MONDAY {public int getId() {return 101;}},
...;
public abstract int getId();
}
Next, the GUI programmer wants to attach a string to each day, so he adds
his own stuff:
public enum Day
{
SUNDAY {
public int getId() {return 100;}
public String getName() {return "sunday";}
},
MONDAY {
public int getId() {return 101;};
public String getName() {return "monday";}
},
...;
public abstract int getId();
public abstract String getName();
}
You get the point...
How do you call this thing? Know any good article about it?