Why does a "named query" I'm using in a Processor.process() method not work.? -how can I fixi it? - spring-boot

A "named query" I'm using in a Processor.process() method doesn't work
--Why? -How can I fix it?
thx for any help! :-)
This is the JPA entity with the "named query" in question...
i.e.,
#NamedQuery(name = "ThingTable.byUpdateTs", query = "SELECT e FROM ThingTable e WHERE e.updateTs > :updateTs")
The "named query" is used in the process method code (below), but, is not working...
i.e.,
#Override
public void process(Exchange msg) throws Exception {
String firedTime = msg.getIn().getHeader("firedTime", String.class);
ZonedDateTime zdtnow = ZonedDateTime.parse(firedTime, formatter2);
zdtnow = zdtnow.withZoneSameInstant(ZoneId.of("America/New_York")); // ...in case springboot server defaults to UTC/GMT time zone...
ZonedDateTime startZDT = zdtnow.minusMonths(24); //.minusSeconds(65);
//*********** this is the line of code using the "named query" **********
String pollingQuery="jpa:aaa.bbb.ccc.jar.ThingTable?namedQuery=ThingTable.byUpdateTs&updateTs='" + startZDT.format(formatter) + "'";
msg.getIn().setBody(pollingQuery);
}
The Processor.process() method is used in this camel route...
i.e.,
from("timer://pollingTimer?fixedRate=true&period=60000")
.process(theProcessor::process)
.toD("${body}")
.split(body())
.convertBodyTo(java.lang.String.class, "UTF-8")
.log("===============>>> NEW MESSAGE: ${body}");
a snippet of stacktrace describing error:
i.e.,
-
-
-
2020-12-30 23:53:32.191 ERROR 1 --- [://pollingTimer] o.a.c.p.e.DefaultErrorHandler : Failed delivery for (MessageId: ID-7499dc21186b-1609372412151-0-1 on ExchangeId: ID-7499dc21186b-1609372412151-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jpa://aaa.bbb.ccc.jar.ThingTable?namedQuery=byUpdateTs&updateTs=%272018-12-30+18%3A53%3A31%27 due to: Failed to resolve endpoint: jpa://aaa.bbb.ccc.jar.ThingTable?namedQuery=byUpdateTs&updateTs=%272018-12-30+18%3A53%3A31%27 due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{updateTs='2018-12-30 18:53:31'}]
Message History (complete message history is disabled)
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[route1 ] [route1 ] [from[timer://pollingTimer?fixedRate=true&period=60000] ] [ 333]
...
[route1 ] [toD1 ] [${body} ] [ 0]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jpa://aaa.bbb.ccc.jar.ThingTable?namedQuery=byUpdateTs&updateTs=%272018-12-30+18%3A53%3A31%27 due to: Failed to resolve endpoint: jpa://aaa.bbb.ccc.jar.ThingTable?namedQuery=byUpdateTs&updateTs=%272018-12-30+18%3A53%3A31%27 due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{updateTs='2018-12-30 18:53:31'}]
at org.apache.camel.impl.engine.AbstractCamelContext.doGetEndpoint(AbstractCamelContext.java:876) ~[camel-base-3.3.0.jar!/:3.3.0]
at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:771) ~[camel-base-3.3.0.jar!/:3.3.0]
at org.apache.camel.support.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:72) ~[camel-support-3.3.0.jar!/:3.3.0]
at org.apache.camel.support.ExchangeHelper.resolveEndpoint(ExchangeHelper.java:114) ~[camel-support-3.3.0.jar!/:3.3.0]
at org.apache.camel.support.ExchangeHelper.resolveEndpoint(ExchangeHelper.java:92) ~[camel-support-3.3.0.jar!/:3.3.0]
at org.apache.camel.processor.SendDynamicProcessor.resolveEndpoint(SendDynamicProcessor.java:287) ~[camel-base-3.3.0.jar!/:3.3.0]
at org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:155) ~[camel-base-3.3.0.jar!/:3.3.0]
at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:395) ~[camel-base-3.3.0.jar!/:3.3.0]
at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148) ~[camel-base-3.3.0.jar!/:3.3.0]
at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:60) ~[camel-base-3.3.0.jar!/:3.3.0]
-
-
-
(Tried apache camel.apache.org website, but, so far, have been unable to find an example "named query" example that uses parameters - like mine, above)
e.g., https://camel.apache.org/components/latest/jpa-component.html)

You have specified the option updateTs which is not a known option for the JPA component.

Related

Setting the Symfony session storage factory

I'm using Symfony 6 to refactor a CodeIgniter 3 framework. User logging in is done via CodeIgniter so I'd like to read the CI session data (stored in a DB) in Symfony.
I'm trying to use my own session storage factory because the CI session name is dynamically constructed using the hostname and also because of the way CI stores the session in the db is different to Symfony.
I've set the session storage factory in framework.yaml
# config/packages/framework.yaml
session:
storage_factory_id: App\Service\CINativeSessionStorageFactory
And I've configured my services (including my own PDO session handler):
# config/services.yaml
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind: # defines the scalar arguments once and apply them to any service defined/created in this file
string $locales: '%app_locales%'
string $defaultLocale: '%locale%'
string $emailSender: '%app.notifications.email_sender%'
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
# CodeIgniter Session handler
App\Service\CIPdoSessionHandler:
arguments:
- '%env(DATABASE_URL)%'
- {
db_table: 'ci_sessions',
db_id_col: 'id',
db_data_col: 'data',
db_time_col: 'timestamp',
db_lifetime_col: 'sess_lifetime'
}
properties:
logger: '#logger'
tags:
- { name: monolog.logger, channel: session }
App\Service\CINativeSessionStorageFactory:
arguments:
$handler : '#App\Service\CIPdoSessionHandler'
$options : {
cookie_secure: auto,
cookie_samesite: lax,
gc_maxlifetime: 7200
}
tags:
- { name: monolog.logger, channel: session }
However I am getting these errors in the logs:
[2022-11-30T17:32:16.738059+00:00] php.CRITICAL: Fatal Compile Error: Cannot declare class App\Service\CINativeSessionStorageFactory, because the name is already in use {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Compile Error: Cannot declare class App\\Service\\CINativeSessionStorageFactory, because the name is already in use at /workspace/symfony/src/Service/CINativeSessionStorageFactory.php:16)"} []
[2022-11-30T17:32:16.739841+00:00] request.CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\FatalError: "Compile Error: Cannot declare class App\Service\CINativeSessionStorageFactory, because the name is already in use" at /workspace/symfony/src/Service/CINativeSessionStorageFactory.php line 16 {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Compile Error: Cannot declare class App\\Service\\CINativeSessionStorageFactory, because the name is already in use at /workspace/symfony/src/Service/CINativeSessionStorageFactory.php:16)"} []
[2022-11-30T17:32:16.741681+00:00] session.DEBUG: Using App\Service\CIPdoSessionHandler [] []
[2022-11-30T17:32:16.741839+00:00] session.DEBUG: Setting session name to ci_session_XXXXXXX [] []
The last two lines indicate that my storage factory is working (at least partially) so I'm unsure as why I'm getting these errors.
The first part of my question is: Where am I going wrong?
As an aside, I noticed that if I set up my framework.yaml like this:
# config/packages/framework.yaml
session:
handler_id: App\Service\CIPdoSessionHandler
storage_factory_id: App\Service\CINativeSessionStorageFactory
Then the handler passed to my constructor was always null
public function __construct(array $options = [], AbstractProxy|\SessionHandlerInterface $handler = null, MetadataBag $metaBag = null, bool $secure = false)
{
// $handler is null!
So the second part of my question is: Do handler_id and storage_factory_id not work together?
Some additional information from trying to debug this issue:
If I save config/services.yaml and then refresh the page - I don't get this message.
If I then refresh the page again - I get the error message.
If I then save config/services.yaml again and refresh the page - I don't get this message
... etc
Is my installation broken? I followed the steps here : https://symfony.com/doc/current/setup.html

How can I fix the error "The [standard] token filter has been removed"?

I am trying to upgrade a project from ElasticSearch 2.3 with NEST version 2.5.8 to ElasticSearch 7.9 with NEST 7.11.1. When I try to create the index I get the error:
# OriginalException: Elasticsearch.Net.ElasticsearchClientException: The remote server returned an error: (400) Bad Request.. Call: Status code 400 from: PUT /partsearch.01. ServerError: Type: illegal_argument_exception Reason: "failed to build synonyms" CausedBy: "Type: parse_exception Reason: "Invalid synonym rule at line 1" CausedBy: "Type: illegal_argument_exception Reason: "The [standard] token filter has been removed."""
The code that is attempting to create the index when this error occurs is:
protected internal CreateIndexResponse CreateIndex(string name)
{
var indicesOperationResponse = this.elasticClientProxy.CreateIndex(
name, c => c
.Settings(
s => s
.NumberOfReplicas(this.numberOfReplicas)
.NumberOfShards(this.numberOfShards)
.Setting("index.max_result_window", this.maxResultWindow)
.Analysis(
ad => ad
.CharFilters(this.RegisterCharFilters)
.Tokenizers(this.RegisterTokenizers)
.TokenFilters(this.RegisterTokenFilters)
.Analyzers(this.RegisterAnalyzers)))
.Map<T>(this.Map)
.Map<IndexMetaData>(this.MapIndexMetaData));
return indicesOperationResponse;
}
The implementation of the RegisterTokenFilters is:
protected internal override TokenFiltersDescriptor RegisterTokenFilters(TokenFiltersDescriptor descriptor)
{
return descriptor.UserDefined(TokenFilter.NormalizeNumberSeparator.DisplayName, TokenFilter.NormalizeNumberSeparator.Filter)
.UserDefined(TokenFilter.CustomStopWordFilter.DisplayName, TokenFilter.CustomStopWordFilter.Filter)
.UserDefined(TokenFilter.StripNumberUnit.DisplayName, TokenFilter.StripNumberUnit.Filter)
.UserDefined(TokenFilter.StripEndingPunctuation.DisplayName, TokenFilter.StripEndingPunctuation.Filter)
.UserDefined(TokenFilter.StripCommaFromNumber.DisplayName, TokenFilter.StripCommaFromNumber.Filter)
.UserDefined(TokenFilter.EnglishStemmer.DisplayName, TokenFilter.EnglishStemmer.Filter)
.UserDefined(TokenFilter.EnglishPossessiveStemmer.DisplayName, TokenFilter.EnglishPossessiveStemmer.Filter)
.UserDefined(TokenFilter.PatternFilter.DisplayName, TokenFilter.PatternFilter.Filter)
.UserDefined(TokenFilter.SynonymFilter.DisplayName, TokenFilter.SynonymFilter.Filter)
.UserDefined(TokenFilter.StripLeadingCharNoise.DisplayName, TokenFilter.StripLeadingCharNoise.Filter)
.UserDefined(TokenFilter.NumericSynonymFilter.DisplayName, TokenFilter.NumericSynonymFilter.Filter)
.UserDefined(TokenFilter.StemmerExclusionFilter.DisplayName, TokenFilter.StemmerExclusionFilter.Filter)
.UserDefined(TokenFilter.AsciiFoldingTokenFilter.DisplayName, TokenFilter.AsciiFoldingTokenFilter.Filter)
.UserDefined(TokenFilter.DashWordsSynonymFilter.DisplayName, TokenFilter.DashWordsSynonymFilter.Filter)
.UserDefined(TokenFilter.DashSplitTokenFilter.DisplayName, TokenFilter.DashSplitTokenFilter.Filter);
}
I wanted to find and remove the Standard token filter based on answers I found to similar errors but I don't see it being used here.
How can I troubleshoot and resolve this issue?
The method RegisterAnalyzers made a call that led to this code:
private static AnalyzerBase CustomDescriptionAnalyzer()
{
var customAnalyzer = new CustomAnalyzer();
customAnalyzer.CharFilter = new List<string>
{
CharacterFilter.HtmlStrip.DisplayName,
CharacterFilter.UniCodeFilter.DisplayName
};
customAnalyzer.Tokenizer = Tokenizer.DescriptionTokenizer.DisplayName;
customAnalyzer.Filter = new List<string>
{
TokenFilter.Standard.DisplayName,
TokenFilter.Lowercase.DisplayName,
TokenFilter.StripLeadingCharNoise.DisplayName,
TokenFilter.PatternFilter.DisplayName,
TokenFilter.StripLeadingCharNoise.DisplayName,
TokenFilter.NormalizeNumberSeparator.DisplayName,
I removed the line TokenFilter.Standard.DisplayName from the customerAnalyzer.Filter list and now I don't get the error Type: parse_exception Reason: "Invalid synonym rule at line 1" CausedBy: "Type: illegal_argument_exception Reason: "The [standard] token filter has been removed
See also
Breaking changes in 7.0
The [standard] token filter has been removed #175
Standard token filter removal causes exceptions after upgrade #50734

ELK serilog sink FailureCallback

I was able to successfully integrate the elastic search sink in my .net app, now I am trying to setup the FailureCallback option but every time there is an error the exception in LogEvent is null, I can see the actual error in the console but I want to be able to capture this exception in my failure callback function, here is my current configuration:
myLogger = new LoggerConfiguration()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elasticSearchUrl))
{
AutoRegisterTemplate = true,
AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6,
IndexDecider = (#event, dateTimeOffset) =>
{
//some logic here
return $"custom-index";
},
EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog | EmitEventFailureHandling.RaiseCallback,
FailureCallback = HandleElasticError
})
.Enrich.WithProperty("Environment", Config.Environment)
.Destructure.ByTransforming<ExpandoObject>(JsonConvert.SerializeObject)
.CreateLogger();
Here is my HandleElasticError function:
private void HandleElasticError(LogEvent e)
{
FileLogger.Error(e.Exception, e.MessageTemplate.Text, e.Properties);
}
When I attach the debugger and inspect the LogEvent, exception is null, however in the output window in Visual Studio I can see the actual error:
2020-11-30T20:55:07.7820674Z Caught exception while preforming bulk operation to Elasticsearch: Elasticsearch.Net.ElasticsearchClientException: The underlying connection was closed: An unexpected error occurred on a send.. Call: Status code unknown from: POST /_bulk ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: The handshake failed due to an unexpected packet format.
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
I am not concerned about the error, I know what the issue is, I just want to be able to capture this exception in my failure callback function.
Any ideas?
LogEvent.Exception is the Exception shipped with your call to (for example) logger.Error(myException) - not the exception thrown by failure to write to Elastic Search.
The exception you're trying to catch doesn't look to be exposed by the sink as it just passes the LogEvent to FailureCallback and not exception that caused the failure.
Here's what it could look like were the exception exposed.
you can use:
StreamWriter writer = File.CreateText(...);
Serilog.Debugging.SelfLog.Enable(writer);

Kony service giving 1012 opstatus Request failed error and not giving response

I have a kony sample app where I am trying to do a build and the app has one web service in it for fetching categories of some product. I have the following code also that I wrote:
function GetCategories() {
var inputparam = {
"appID": "bbuy",
"serviceID": "GetCategories",
"catId": "cat00000",
"channel": "rc",
"httpheaders": {}
};
kony.net.invokeServiceAsync("http://192.168.42.134/middleware/MWservlet",inputparam, serv_GetCategoriesCallback);
}
I am getting no response for this. Getting 1012 opstatus and the message is saying "Request failed" error.
kony.net.invokeServiceAsync("http://192.168.42.134/middleware/MWservlet",inputparam, serv_GetCategoriesCallback);
In the above line, you have not given the port number in the MWservlet URL.(e.g. 8080) Give that and check.
Also, make sure all input params are being fed to the service and that they correspond to the exact naming convention followed in the service editor.
Visit :
Find the below link. i hope it gives you a solution
http://developer.kony.com/twiki/pub/Portal/Docs/API_Reference/Content/Network_APIs.htm#net.invo2
Check the mandatory and optional fields of Inputparam

Google.Apis.Email_Migration_v2

I am attempting to retrieve the HttpStatusCode from every UploadAsync method call. I need the status code as to properly perform an exponential back-off algorithm to retry a failed upload, display an error message to the user when not retrying the upload and to report success of the upload. I do not care how it is received, so long as it is clean and not being parsed from the Exception.Message (string) property like Tor Jonsson suggested in the link provided below.
To force the "Bad Request Error [400]" I simply provided an invalid userkey (email) in the constructor for MailResource.InsertMediaUpload.
e.g. MailResource.InsertMediaUpload(mailItem, "invalidEmail#domain.com", stream, "message/rfc822")
Problem
1) GoogleApiException.HttpStatusCode is always 0 (unavailable). Even when Exception.Message appears to contain a status code in brackets. e.g. [400]
2) Cannot find GoogleApiRequestException.
Questions
1) What is the best way to perform the exponential back-off algorithm???
2) Is this the expected behaviour for this property in this case?
3) Does GoogleApiRequestException still exist, if so where?
Side Note:
I also noticed that the GoogleApiRequestException class is no longer in the same file as GoogleApiException class. Has it been moved to another namespace or deleted? Because I would like to attempt to catch a GoogleApiRequestException object and grab its RequestError object.
I added links to the two diffs for what I mean:
Before: http://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis/GoogleApiException.cs?r=a8e27790f8769c1d6aaae030bb46c79daa7cdbad
After: http://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis/GoogleApiException.cs?r=d6f06e92d90b635c179013e2c287b42b82909c09
Sources
I'm using the latest binaries from NuGet (1.6.0.8-beta)
The only question I found related to my problem: (Can only post two links... heres the raw)
stackoverflow.com/questions/18985306/httpstatuscode-not-set-in-exceptions-when-using-google-net-apis
Code: (Using a custom logger to write to debugview)
public int Index; // Used to Id the process
private void TryUpload(MailResource.InsertMediaUpload upload, out IUploadProgress uploadProgress, out bool retryUpload)
{
uploadProgress = null;
retryUpload = false;
CancellationToken token;
try
{
uploadProgress = upload.UploadAsync(token).Result;
if (uploadProgress.Exception != null)
{
_logger.WriteTrace("EXCEPTION!!! Type: {0}", uploadProgress.Exception.GetType().ToString()); // Remove:
// *) Handle all of the various exceptions
if (uploadProgress.Exception is JsonReaderException)
{
JsonReaderException jreEx = uploadProgress.Exception as JsonReaderException;
_logger.WriteTrace("JsonReaderException-> Message: {0}", jreEx.Message);
}
if (uploadProgress.Exception is TokenResponseException)
{
TokenErrorResponse trEx = uploadProgress as TokenErrorResponse;
_logger.WriteTrace("TokenErrorResponse-> Message: {0}", trEx.Error);
}
if (uploadProgress.Exception is HttpRequestValidationException)
{
HttpRequestValidationException hrvEx = uploadProgress.Exception as HttpRequestValidationException;
_logger.WriteTrace("HttpRequestValidationException-> Message: {0}", hrvEx.Message);
_logger.WriteTrace("HttpRequestValidationException-> Status Code: {0}", hrvEx.GetHttpCode());
}
if (uploadProgress.Exception is GoogleApiException)
{
GoogleApiException gApiEx = uploadProgress.Exception as GoogleApiException;
_logger.WriteTrace("GoogleApiException-> Message: {0}", gApiEx.Message);
_logger.WriteTrace("GoogleApiException-> Status Code: {0}", gApiEx.HttpStatusCode);
}
}
}
catch (Exception ex)
{
_logger.WriteTrace(ex, "An exception occured while uploading...");
}
finally
{
if (uploadProgress != null)
_logger.WriteTrace("Upload Completed... Status: {0} Exception?: {1}",
uploadProgress.Status,
(uploadProgress.Exception == null) ? "None" : uploadProgress.Exception.ToString());
else
_logger.WriteTrace("Upload Aborted... Exited without returning a status!");
}
}
Output Snippet
[5224] (T101) VSLLC: EXCEPTION!!! Type: Google.GoogleApiException
[5224] (T101) VSLLC: GoogleApiException-> Message: Google.Apis.Requests.RequestError
[5224] Bad Request [400]
[5224] Errors [
[5224] Message[Bad Request] Location[ - ] Reason[badRequest] Domain[global]
[5224] ]
[5224] (T101) VSLLC: GoogleApiException-> Status Code: 0
[5224] (T101) VSLLC: Upload Completed... Status: Failed Exception?: The service admin has thrown an exception: Google.GoogleApiException: Google.Apis.Requests.RequestError
[5224] Bad Request [400]
[5224] Errors [
[5224] Message[Bad Request] Location[ - ] Reason[badRequest] Domain[global]
[5224] ]
[5224]
[5224] at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[5224] at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
[5224] at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
[5224] at Google.Apis.Upload.ResumableUpload`1.d__0.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis[Media]\Upload\ResumableUpload.cs:line 373
Sorry for the extensive post! Thanks for your time!
The library already supports exponential back-off for 503 responses. In case of 400 (bad request) you should not retry, because you will get the same response over and over again.
Take a look in the service initializer parameter DefaultExponentialBackOffPolicy
You can also take a look in our ExponentialBackOff implementation. BackOffHandler wraps the logic and implements unsuccessful response handler and exception handler.
GoogleApiRequest doesn't exists anymore.
It looks like we are not setting the status code properly, as you can find here. I open a new issue in our issue tracker, available here - https://code.google.com/p/google-api-dotnet-client/issues/detail?id=425. Feel free to add more content to it.

Resources