Here is my connection URL:
jdbc:mysql://mydbhost:3306/mydatabase?user=username&password=%u16*!ypK#WrUQbr
When i call
DriverManager.getConnection()
with current URL i'm catching exception:
ava.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "u1"
If connection URL not contain % everything works.
i have found some info about this issue, and there recommend to do next conversion :
replaceAll("%(?![0-9a-fA-F]{2})", "%25")
With this conversion i have error:
Access denied for user(incorrect password)
Can somebody help to convert url correctly?
Try it with below string, where all reserved characters in your password are replaced with the appropriate percent-encoded value:
% : %25
* : %2A
! : %21
# : %40
"jdbc:mysql://mydbhost:3306/mydatabase?user=username&password=%25u16%2A%21ypK%40WrUQbr"
More information about percent-encoding Wikipedia
I have tried as "Carlos Heuberger" recommended,
call getConnection(String url, String user, String password)
In this style it works, and from my view looks more clear instead of build one huge URL with all parameters included
Related
I am trying to receive name and value (query details) from a URL but I have a restriction that the URL shouldn't be parsed to find out query details from the URL. I tried to find the index of '?' and then add the substring on a list till index of '='-1 from the query which I found using the statement:
String query = uri.getQuery() == null || uri.getQuery().trim().isEmpty() ? "" : uri.getQuery();
The issue that comes here is I am getting an error which states:
java.net.URISyntaxException: Illegal character in query at index
Can anyone point where am I going wrong ?
The URL which I am using is:
https://xyzz.com.in/collections/two-tone-wedding-rings?ugg_9ty554_tags=ROSE|WHITE&ugg_yuiolz_price=%3A700%201000%20%7B0%7D%20-%20%7B1%7D
(The | symbol is creating issues)
I think you're using the wrong class for this
I tried doing it with URL class instead
String input = "https://xyzz.com.in/collections/two-tone-wedding-rings?ugg_9ty554_tags=ROSE|WHITE&ugg_yuiolz_price=%3A700%201000%20%7B0%7D%20-%20%7B1%7D\n"
URL uri = new URL(input);
System.out.println(uri.getQuery());
Output:
ugg_9ty554_tags=ROSE|WHITE&ugg_yuiolz_price=%3A700%201000%20%7B0%7D%20-%20%7B1%7D
I'm trying to decode a JWT token returned, and check the sub claim for if it matches the username. But I can't seem to find the syntax to do so.
...
.check(status.is(HttpResponseStatus.OK.code()))
.check(jsonPath("$.access_token").saveAs("access_token"))
.check(jsonPath("$.refresh_token").exists)
.check(JWSObject.parse("${access_token}").getPayload.toJSONObject.get("sub").toString.substring("$username"))
I'm getting errors around it expecting a HttpCheck, is there a HTTPCheck for this type?
Thanks
This is pretty much exactly what .transform is for.
You extract the token with jsonPath, do a transform to get the sub, and then assert that it matches the username.
(I have not tried the actual jwt extract / validation)
.check(jsonPath("$.access_token").transform(jwt => JWT.decode(jwt).getClaim("sub").asString()).is("${username}")
I'm using jsoup to get all text from websites.
Document doc = Jsoup.connect("URL").get();
String allText doc.text().toLowerCase();
Then I'm using Hibernate to persist the object that holds all text to a MySQL DB:
...
#Column(name="all_text")
#Lob
private String allText = null;
...
Everything is good so far. Only that sometimes I get a MySQL error when I try to save the object with allText:
java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8A s...' for column 'all_text' at row 1
Already looked this up and it's an encoding error. Probably have some special characters on their websites. I found a way to fix this by changing the encoding in the DB.
But my actual question is: what's the best way to filter and remove the special characters from the allText string and not persist them at all?
EDIT: To clarify, by special characters I mean Emoticons and all that stuff. Definitely anything that doesn't fit into UTF-8 encoding. I'm not concerned about ~ ^ etc...
Thanks in advance!
Just use regex:
allText.replaceAll("\\p{C}", "");
Don't forget to import java.util.regexPattern
I am passing a String value in a URL
eg: http://localhost:8080/webservice/useradmin/a%bghijlk123/0978+gh
The String "ab%ghijlk123/0978+gh" breaks the URL.
What are the available options to overcome this.
Is encoding the string the only option? There must be minimal code change. Any server side configurations can be used to achieve this?
Kindly provide suggestions please.
Is encoding the string the only option?
It is the only correct option.
Use URLEncoder.encode("ab%ghijlk123/0978+gh", "UTF-8"),
which will give you ab%25ghijlk123%2F0978%2Bgh, for a full URL of:
http://localhost:8080/webservice/useradmin/ab%25ghijlk123%2F0978%2Bgh
The URL http://localhost:8080/webservice/useradmin/a%bghijlk123/0978+gh is invalid.
The URL specification (RFC3986) says that path segments (the values separated by a /) may only consist of:
ALPHA: "a"-"z", "A"-"Z"
DIGIT: "0"-"9"
Special chars: - . _ ~ ! $ & ' ( ) * + , ; = : #
pct-encoded: "%" HEXDIG HEXDIG
Values that has to be disallowed because they have other meanings are: / (path separator), ? (start of query), # (start of fragment), and % (start of 2-digit hex encoded char).
As you can see, the % sign is only allowed as a percent-encoded character, so %bg makes the URL invalid.
If the part after the useradmin/ is supposed to be the value ab%ghijlk123/0978+gh, then it must be encoded as shown above.
If the server rejects that as "400:Bad request", then the server is in error.
i want to send an email this text
Destination : 6W - ATLANTA WEST!##$%^*!gemini!##$%^*!jfds!##$%^*!,Trailer Number : 000564,,Drop empty trailer at Plant Numbe :546,Pick up trailer at Plant Number :45, Bill Date : 25-Jan-2013,Bill Time - Eastern Time : 1,Trip Number :456,MBOL :546,Carrier :Covenant!##$%^*!test#shaw.com!##$%^*!transport#shaw.com!##$%^*!test#transport.com!##$%^*!antoalphi#gmail.com,Destination : 6W - ATLANTA WEST!##$%^*!gemini!##$%^*!jfds!##$%^*!,Customer Name : 567,Cusomer Delivery Address : 657567657,General Comments :657,Warehouse Comments : 65,Carrier Comments : ,Appointment Date :25-Jan-2013,Appointment Time : 1am,Rail Only :Standard,Total Weight : 45645
and i used this mailContent = URLDecoder.decode(Body, "UTF-8"); decode,
but it is giving me this exception URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "^*"
could any one of you help me,how to solve this. I get this while sending mail.
Best Regards
You are trying to URL decode something that wasn't URL encoded in the first place. What's wrong with the body as it is? In other words, what happens if you just use:
mailContent = Body
(In URL encoding, the % character is used with two hexadecimal digits to encode characters that might cause problems, for example / would be encoded as %2F, as its ASCII code is 47 (decimal) or 2F (hex). In your body, % is followed by two characters that are not hexadecimal digits - that's how I can tell it hasn't been URL encoded, and why the decoder is erroring.)
Simply stop calling URLDecoder.decode() and you will stop getting the error! The string value you are passing to it is not URL encoded.
There are various forms of MIME encoding that you might want to consider, if you are sending an email with content that would not normally be allowed in an email message without encoding. There references might be handy:
What is allowed in SMTP: http://www.apps.ietf.org/rfc/rfc788.html
Basic MIME encoding: http://www.apps.ietf.org/rfc/rfc1341.html
Java MIME support: http://docs.oracle.com/javaee/1.4/api/javax/mail/internet/MimeUtility.html
For example, you might try:
String sendable = MimeUtility.encodeText(body,"UTF-8","BASE64")