I have such model for saving:
#Table("EXPERIMENTS")
data class Experiment(
#Id val id: Long,
val userId: Long,
val time: String,
#JsonProperty
val data: Any
)
such saving processor:
#PostMapping("/experiment")
fun saveUserExperiment(#RequestBody experiment: Experiment) = service.saveExperiment(experiment)
such service:
#Service
class ExperimentService(val db: ExperimentRepository) {
fun saveExperiment(experiment: Experiment) = db.save(experiment)
...
}
and I save it via postman in such way:
POST /experiment HTTP/1.1
Content-Type: application/json
User-Agent: PostmanRuntime/7.29.2
Accept: */*
Postman-Token: 1c2aaf40-8933-4988-b92a-6694539c3aba
Host: localhost:8080
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 105
{
"userId":1,
"time": "2018-10-18 05:30:57.907",
"data": {"red":123,"blue":123,"green":123}
}
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sat, 30 Jul 2022 15:57:55 GMT
Keep-Alive: timeout=60
Connection: keep-alive
{"id":7,"userId":1,"time":"2018-10-18 05:30:57.907","data":{"red":123,"blue":123,"green":123}}
during saving I receive such error:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.util.ReflectionUtils (file:/Users/_t/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.3.2/152489ed8223a6ad19065a3cd1ee6b9e20c0b82f/spring-core-5.3.2.jar) to field java.util.LinkedHashMap.head
WARNING: Please consider reporting this to the maintainers of org.springframework.util.ReflectionUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
and also after fetching the list of models I receive such error:
Parameter specified as non-null is null: method com.example.demo.models.Experiment.<init>, parameter data
list I receive in such way:
#Query("select * from experiments")
fun getExperiments(): List<Experiment>
my database has such table:
experiments: table
+ columns
id: int NN auto_increment = 1
user_id: mediumtext NN
time: timestamp default CURRENT_TIMESTAMP
data: json
+ keys
#1: PK (id) (underlying index PRIMARY)
I'm not sure whether it is ok that I receive 200OK response from the api but json field is null even if I have it filled.
There are two different things going on here. First, the minor one:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.util.ReflectionUtils (file:/Users/_t/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.3.2/152489ed8223a6ad19065a3cd1ee6b9e20c0b82f/spring-core-5.3.2.jar) to field java.util.LinkedHashMap.head
WARNING: Please consider reporting this to the maintainers of org.springframework.util.ReflectionUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
As the prefix shows, this is a warning, not an error: it's not stopping your program from working (though, as it says, a later Java release might).
They cause is an incompatibility between the version of Spring you're using and the Java Module System that was introduced in Java 9, and is discussed in this question. One simple workaround might be to run it on Java 8.
The actual error is this one:
Parameter specified as non-null is null: method com.example.demo.models.Experiment.<init>, parameter data
That's about nullability. As you probably know, Kotlin distinguishes between references that could be null, and those that can't.
You've defined your JSON property as: val data: Any, and the Any type is non-nullable: Kotlin won't allow it to hold a null value. (To allow a null, you'd specify it as Any?, with a question mark.)
However, the Spring framework is based on Java, which doesn't make that distinction: all its references can potentially be null. And so there are some unfortunate corner cases which throw up unexpected nulls like this.
For some reason, your DB query is returning a null value for that field; when it tries to construct an instance of your Experiment class to hold the returned data, the Kotlin runtime spots the null and gives the error above. (It's not spotted at compile-time, unfortunately, because Spring works much of its magic at run-time.)
So there are two potential approaches to fixing it:
Prevent Spring returning null for that field. I don't think it's possible to guarantee this in all circumstances, as it might depend on what data can be in your database, as well as how the query is performed. (It's probably worth looking at your data and the query to understand why it's coming back as null, though.)
Specify the field as nullable (Any?), and handle the null case yourself. That would make your code very slightly less clean, but a lot safer and more robust.
Related
System environment : Windows 7(64bit), VS 2013, Compile in release 64bit
This is the code:
var clients = new ZSocket(ctx, ZSocketType.ROUTER);
clients.GetOptionString(ZSocketOption.TCP_KEEPALIVE));
Exception as below:
ZeroMQ.ZException ""EINVAL(22): Invalid argument""
EINVAL ( Error: 22 ) was thrown correctly:
EINVAL
The requested option option_name is unknown, or the requested option_len or option_value is invalid, or the size of the buffer pointed to by option_value, as specified by option_len, is insufficient for storing the option value.
Must fix both of the below listed API non-compliant issues:
The ZeroMQ API defines the ZMQ_TCP_KEEPALIVE socket-configuration option to be of an int data type, not a string. Use the appropriate clrzmq4 binding interface function to request an int typed option_value and this first API incompliance will be solved.
Option value type int
Option value unit { -1 | 0 | 1 }
Default value -1 ( leave to OS default )
Applicable socket types all, when using TCP transports.
The ZeroMQ API defines this option to be valid if and only if the socket-instance was equipped with a tcp:// transport-class ( which the clients instance, as posted above, was not ). May defer the request to take place after the socket-instance has been instructed to associate a first tcp:// transport-class engine ( be it via a respective use of a .connect() or a .bind() ).
I am trying to add expression validation on my property on actionbean but I am unable to make it work. I have even tried with integers like this >0 but still the same exception is thrown. Below is the code
#Validate(required=true, minvalue=1, expression="${this > maxBudget}")
int minBudget;
int maxBudget;
I am getting the below exception:
net.sourceforge.stripes.exception.StripesRuntimeException: Could not parse the EL expression being used to validate
field minBudget. This is not a transient error. Please double check the following expression for errors: ${this > maxBudget}
caused by
javax.el.ELException: The identifier [this] is not a valid Java identifier as required by section 1.19 of the EL specification (Identifier ::= Java language identifier).
This check can be disabled by setting the system property org.apache.el.parser.SKIP_IDENTIFIER_CHECK to true.
I have tried few variation, but every time it throws this exception.
Can some one please point out the mistake I am doing here
thanks
If you want to make sure minBudget is larger than maxBudget (isn't that the other way around?) you could just do:
#Validate(required=true, minvalue=1, expression="${minBudget > maxBudget}")
For greater flexibility you could consider implementing a custom validation method:
#ValidationMethod(on={"show"})
public void checkBudgetRange(ValidationErrors errors) {
if (minBudget < maxBudget)
errors.addGlobalError( new SimpleError("This is not good..."));
// all sorts of other checks to your liking
}
The on array argument holds the name(s) of the event handler(s) for which you want to perform this validation method. So in the example here that would be public Resolution show().
There's an excellent explanation at the Stripes Framework site at https://stripesframework.atlassian.net/wiki/display/STRIPES/Validation+Reference
UPDATE:
If you want to make use of the this keyword in validation expressions you may need to add a VM argument to your server (tested this on Tomcat 8):
-Dorg.apache.el.parser.SKIP_IDENTIFIER_CHECK=true
Otherwise the abovementioned error may be thrown.
The default value of org.apache.el.parser.SKIP_IDENTIFIER_CHECK was changed from true to false as of version 7 in Tomcat.
https://tomcat.apache.org/tomcat-6.0-doc/config/systemprops.html
https://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html
I'm trying to model a GET request in my RAML that has an arbitrary list of URL parameters. 2 parameters are known, but the remainder are name/value pairs that are chosen from the response data from other request types. I tried to use additionalParameters: true in my queryParameters list, but I get an error message from osprey-mock-service when it attempts to parse the RAML:
each query parameter must be a map
The relevant snippet from my RAML is:
/statistics:
/{statisticId}:
get:
description: Get the stastic data
queryParameters:
start:
displayName: Start Time
type: integer
description: The timstamp in milliseconds indicating the beginning of the collection of timeseries data
example: 1380601800000
required: false
end:
displayName: End Time
type: integer
description: The timstamp in milliseconds indicating the end of the collection of timeseries data
example: 1380601800000
required: false
additionalParameters: true
responses:
200:
body:
application/json:
schema: statistic
example: !include ../dto/statistic.sample
The error message goes away when I remove the line:
additionalParameters: true
I have not found a reference that indicates that you can use additionalParameters with queryParameters, but it seems to make sense that you could.
I don't necessarily need to resolve the error message, but I would like to have URL parameters like the following:
?start=23010030&end=23011470&content=abc.com&node=siteA
Where content and node are not predefined parameter names.
Is this possible?
additionalParameters is currently not supported by RAML: it is nowhere to be found in version 0.8 of the specification.
This said, this (very important) topic is under discussion in the RAML forums
So for the moment, I see only two options:
Do not specify these parameters, the caveat being that tools, like RAML Tester, will report request violations if you use these parameters.
Specify all the possible parameters with required: false, the caveat being that you need to know all these parameters beforehand.
I'm working with some protocol buffers (java) that have extensions. I'm seemingly able to parse the serialized protocol buffers ok (no errors anyway), but for debugging purposes (yet another issue), I'm printing them out to a log.
I'm getting these types of things scattered around the log:
data_config {
format: FORMAT_DELIMITED
1024: "\022\001\n"
}
And here's the message definition:
message DataConfig {
optional DataFormat format = 1;
extensions 1024 to max;
option (dwhio.data.message_reflection_config) = { reflect_extensions: true };
}
My question is 'Is the debug string in the log with '1024' correct (expected) or indicative of a class loading or other problem?'
I haven't figured out a way to print to a string involving a registry, simply 'merge', so I'm assuming that's not necessary?
The problem is probably that you did not provide an ExtensionRegistry when you parsed the message from binary. So, the extension was treated as an unknown field. When you later print the message, the extension is still unknown, so is printed as you see. The solution is to provide the registry at parse time, e.g. DataConfig.parseFrom(bytes, registry).
I'm using the Oracle.DataAccess.Client data provider client. I am having trouble constructing a new instance of an OracleException object, but it keeps telling me that there are no public constructors. I saw other having the same problem and tried their solutions, but they don't seem to work. Here's my test code:
object[] args = { 1, "Test Message" };
ConstructorInfo ci = typeof(OracleException).GetConstructor(BindingFlags.NonPublic
| BindingFlags.Instance, null, System.Type.GetTypeArray(args), null);
var e = (OracleException)ci.Invoke(args);
When debugging the test code, I always get a NULL value for 'ci'.
Has Oracle changed the library to not allow this? What am I doing wrong and what do I need to do to instantiate an OracleException object to use with NMock?
By the way, I'm using the Client library for version 10g.
Thanks,
Charlie
OracleException in ODP.NET not the same as OracleException in Microsoft client.
OracleException have 5 constructors information of which you can obtain by GetConstructors().
In the obtained list of the constructors you will see that there are no constructor with parameters (int, string). That why you getting NULL in ci.
If you give a proper list of the parameters you will have proper ConstructorInfo and will be able to call a constructor by Invoke(param);
However, OracleException constructor not designed to be called like this - not all the fields will have a proper information.
2All:
I need following OracleException:
ORA-00001 unique constraint (string.string) violated
ORA-03113 end-of-file on communication channel
ORA-03135: connection lost contact
ORA-12170: TNS: Connect timeout occurred
for testing. How do I create them?