LWP::UserAgent and HTTP::Request for a POST request
In a certain script I tried to write this:
my $ua = LWP::UserAgent->new;
my $res = $ua->post($url, Content => $data);
and got "400 Bad Request". After some reading I tried this:
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new( 'POST', $url );
$req->content( $data );
my $res = $ua->request( $req );
and it worked, but I thought these two should do the same. What am I
missing here? Am I misunderstanding something in the documentation of
HTTP::Request and LWP::UserAgent?
Is there a way to ask LWP::UserAgent to print what it is doing?
Boos
Thursday, 3 October 2013
Wednesday, 2 October 2013
Complex Regex composition - Regex that match "if"
Complex Regex composition - Regex that match "if"
I'm making a Regex to match hashtags to my project. I want that regex
match hashtags that are separeted by one single space, don't have another
hashtag inside this content and just match a space in the string if this
is followed by any word (except other blank space or #).
I'm really curious to know if I can do something like "if" in regular
expressions and I hope you can help me with this.
So, in:
"#hashtag?!-=_" "#hashhash#" "#hash tag" "#hash tag" "#hash
#ahuhuhhuasd" "#hash "
The regex must match the following sentences:
"#hashtag?!-=_" "#hashhash" "#hash tag" "#hash" "#hash #ahuhuhhuasd" "#hash"
(all hashtag) (one) (another h.)
Actually, this is my code:
#{1,1}\S+\s{0,1}
You can test here this code, but it matches things that isn't desired:
"#ahusdhuas?!__??###hud #ahusdhuads "
The blank space in the end of the string, the 3 '#' inside the string.
none of the following content is desired in this string, just
"#ahusdhuas?!__??"
Glad if you can help me!
I'm making a Regex to match hashtags to my project. I want that regex
match hashtags that are separeted by one single space, don't have another
hashtag inside this content and just match a space in the string if this
is followed by any word (except other blank space or #).
I'm really curious to know if I can do something like "if" in regular
expressions and I hope you can help me with this.
So, in:
"#hashtag?!-=_" "#hashhash#" "#hash tag" "#hash tag" "#hash
#ahuhuhhuasd" "#hash "
The regex must match the following sentences:
"#hashtag?!-=_" "#hashhash" "#hash tag" "#hash" "#hash #ahuhuhhuasd" "#hash"
(all hashtag) (one) (another h.)
Actually, this is my code:
#{1,1}\S+\s{0,1}
You can test here this code, but it matches things that isn't desired:
"#ahusdhuas?!__??###hud #ahusdhuads "
The blank space in the end of the string, the 3 '#' inside the string.
none of the following content is desired in this string, just
"#ahusdhuas?!__??"
Glad if you can help me!
Problems with geotools library to create a .jar?
Problems with geotools library to create a .jar?
I have a java project and it works in eclipse then I create a .jar for
this project and when a try to execute the jar the following errors
appears:
If I create the .jar with eclipse: Exception in thread "main"
java.lang.NoClassDefFoundError: org/geotools/data/FeatureSource
If I create the .jar with mvn: Error: no se ha encontrato o cargado la
clase principal client.Client
Thanks
I have a java project and it works in eclipse then I create a .jar for
this project and when a try to execute the jar the following errors
appears:
If I create the .jar with eclipse: Exception in thread "main"
java.lang.NoClassDefFoundError: org/geotools/data/FeatureSource
If I create the .jar with mvn: Error: no se ha encontrato o cargado la
clase principal client.Client
Thanks
comparing pointer to a negative value
comparing pointer to a negative value
Can i typecast a pointer to a structure to a signed value to return a
different types of errors. Does the C standard allow this or is an
undefined behaviour.
typedef enum lError
{
l_OK = 0,
l_ERROR = -1,
l_ABORT = -2,
l_HALT = -3
}L_STATUS;
typedef struct dataCards
{
int card1;
int card2;
char flag;
}DATACARD;
DATACARD dataCardG;
DATACARD *getCard(int i)
{
if(i == 1)
return &dataCardG;
else if (i == 2)
return (DATACARD *)l_ERROR;
else if (i==3)
return (DATACARD *)l_ABORT;
else
return (DATACARD *)l_HALT;
}
int main ()
{
DATACARD *ptr = NULL;
ptr = getCard(3);
if(ptr < (DATACARD *) 1) /* Is this allowed or undefined behaviour */
printf("Card failed\n");
}
How can i make this condition work?
Can i typecast a pointer to a structure to a signed value to return a
different types of errors. Does the C standard allow this or is an
undefined behaviour.
typedef enum lError
{
l_OK = 0,
l_ERROR = -1,
l_ABORT = -2,
l_HALT = -3
}L_STATUS;
typedef struct dataCards
{
int card1;
int card2;
char flag;
}DATACARD;
DATACARD dataCardG;
DATACARD *getCard(int i)
{
if(i == 1)
return &dataCardG;
else if (i == 2)
return (DATACARD *)l_ERROR;
else if (i==3)
return (DATACARD *)l_ABORT;
else
return (DATACARD *)l_HALT;
}
int main ()
{
DATACARD *ptr = NULL;
ptr = getCard(3);
if(ptr < (DATACARD *) 1) /* Is this allowed or undefined behaviour */
printf("Card failed\n");
}
How can i make this condition work?
Getting the JAXB exception like "Two classes have the same XML type name..."
Getting the JAXB exception like "Two classes have the same XML type name..."
Getting the JAXB exception like "Two classes have the same XML type name...",
Here is the exception details:
Exception in thread "main"
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts
of IllegalAnnotationExceptions Two classes have the same XML type name
"city". Use @XmlType.name and @XmlType.namespace to assign different names
to them. this problem is related to the following location: at
com.model.City at public com.model.City com.model.Address.getCurrentCity()
at com.model.Address this problem is related to the following location: at
com.common.City at public com.common.City
com.model.Address.getPreviousCity() at com.model.Address
at
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown
Source) at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown
Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(Unknown
Source) at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown
Source) at
com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown
Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
javax.xml.bind.ContextFinder.newInstance(Unknown Source) at
javax.xml.bind.ContextFinder.find(Unknown Source) at
javax.xml.bind.JAXBContext.newInstance(Unknown Source) at
javax.xml.bind.JAXBContext.newInstance(Unknown Source) at
com.PojoToXSD.main(PojoToXSD.java:17)
I took the example like:
package com.model; ---->this package contains 'Address' class and 'City'
class
public class Address {
private String areaName;
private City currentCity;
private com.common.City previousCity;
}
package com.model;
public class City {
private String cityName;
}
Another city class in "com.common" package.
package com.common;
public class City {
private String pinCode;
}
We need to create XSDs and needs to do the Marshalling and unmarshalling
with the existing code in our project(like as above example code), code
does not have any annotations like "@XmlRootElement/@XmlType" and we can
not able to change the source code.
I would like to know is there any solution to fix the above issue or any
other ways to create XSDs and marshaling/unmarshalling(like MOXy..etc)?
It would be great if i can get the solution from any one....May thanks in
advance.
Thanks,
Satya.
Getting the JAXB exception like "Two classes have the same XML type name...",
Here is the exception details:
Exception in thread "main"
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts
of IllegalAnnotationExceptions Two classes have the same XML type name
"city". Use @XmlType.name and @XmlType.namespace to assign different names
to them. this problem is related to the following location: at
com.model.City at public com.model.City com.model.Address.getCurrentCity()
at com.model.Address this problem is related to the following location: at
com.common.City at public com.common.City
com.model.Address.getPreviousCity() at com.model.Address
at
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown
Source) at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown
Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(Unknown
Source) at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown
Source) at
com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown
Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
javax.xml.bind.ContextFinder.newInstance(Unknown Source) at
javax.xml.bind.ContextFinder.find(Unknown Source) at
javax.xml.bind.JAXBContext.newInstance(Unknown Source) at
javax.xml.bind.JAXBContext.newInstance(Unknown Source) at
com.PojoToXSD.main(PojoToXSD.java:17)
I took the example like:
package com.model; ---->this package contains 'Address' class and 'City'
class
public class Address {
private String areaName;
private City currentCity;
private com.common.City previousCity;
}
package com.model;
public class City {
private String cityName;
}
Another city class in "com.common" package.
package com.common;
public class City {
private String pinCode;
}
We need to create XSDs and needs to do the Marshalling and unmarshalling
with the existing code in our project(like as above example code), code
does not have any annotations like "@XmlRootElement/@XmlType" and we can
not able to change the source code.
I would like to know is there any solution to fix the above issue or any
other ways to create XSDs and marshaling/unmarshalling(like MOXy..etc)?
It would be great if i can get the solution from any one....May thanks in
advance.
Thanks,
Satya.
Tuesday, 1 October 2013
Multiple and dynamic databases in doctrine 2
Multiple and dynamic databases in doctrine 2
I checked already multiple answers on stackoverflow but couldnt find a
sufficient answer for that problem.
Imagine I have a MAIN database and multiple SLAVE databases. Based on some
information in the MAIN database I will then know which SLAVE database I
will connect to and which table I will use for my model.
As an example:
A Person entity can be connected to a database1234 database using the
table person_india or to database7834 using a table person_uk etc. Which
one I will connect to is decide on runtime and cant be configured before.
What I found so far:
I can directly bind a model to a database.table via
@Entity @Table(name="databaseName.tablename")
So Im able to join over databases. So basically Im ignoring the dbname in
the connection params for the entityManager.
Question:
How to dynamically set the information(database,table) for an entity on
the fly?
Will this affect caching?
If this is not possible in a good manner. Is there any other orm which
will provide me that kind of functionality.
Thanks in advance
I checked already multiple answers on stackoverflow but couldnt find a
sufficient answer for that problem.
Imagine I have a MAIN database and multiple SLAVE databases. Based on some
information in the MAIN database I will then know which SLAVE database I
will connect to and which table I will use for my model.
As an example:
A Person entity can be connected to a database1234 database using the
table person_india or to database7834 using a table person_uk etc. Which
one I will connect to is decide on runtime and cant be configured before.
What I found so far:
I can directly bind a model to a database.table via
@Entity @Table(name="databaseName.tablename")
So Im able to join over databases. So basically Im ignoring the dbname in
the connection params for the entityManager.
Question:
How to dynamically set the information(database,table) for an entity on
the fly?
Will this affect caching?
If this is not possible in a good manner. Is there any other orm which
will provide me that kind of functionality.
Thanks in advance
How to trigger two function on form submit?
How to trigger two function on form submit?
I have a form when the form is submitted i'll call one javascript function
and action it to to form handler.
<form action="subscribe.php" onsubmit="return form_check(this)"
method="post">
<input type="text" value="">
<input type="submit" value="click">
</form>
Everything Works fine, Now i want to send the same form fields to another
javascript function so i tried like this on submit code
<form action="subscribe.php"
onsubmit="return (form_check(this) & another_script(this))" method="post">
Added & in onsubmit but the function is not triggering when the button is
clicked. I think this is due to the action="subscribe.php" in the form.
I want to send the form value to another javascript function also. how can
i achieve this?
I have a form when the form is submitted i'll call one javascript function
and action it to to form handler.
<form action="subscribe.php" onsubmit="return form_check(this)"
method="post">
<input type="text" value="">
<input type="submit" value="click">
</form>
Everything Works fine, Now i want to send the same form fields to another
javascript function so i tried like this on submit code
<form action="subscribe.php"
onsubmit="return (form_check(this) & another_script(this))" method="post">
Added & in onsubmit but the function is not triggering when the button is
clicked. I think this is due to the action="subscribe.php" in the form.
I want to send the form value to another javascript function also. how can
i achieve this?
Subscribe to:
Comments (Atom)