Error "Failed to construct URI for OData request with request path" SAP Java VDM withQueryParameter - sap-cloud-sdk

I have create a CAP VDM in java with SAP SDK 3.29.1.
In event handler #On read, i would like to pass the input filters to the VDM.
Es.
#On(event = CdsService.EVENT_READ, entity = "XXXX")
public void readXXX(CdsReadEventContext context) throws ODataException {
final String filter = context.getParameterInfo().getQueryParameter("$filter");
final List<XXXXX> dati = new DefaultXXXService().getAllXXXX().select().withQueryParameter("$filter", filter).executeRequest(dest);
}
When run the query in the log i get the error:
"Failed to construct URI for OData request with request path ..."
"Illegal character in query at index 95. ...."
But the path and filter is right for the call, can you help me?
In the old version sdk i used:
FilterExpression filtriFrontEnd =FilterExpressionConverter.convertTo(queryRequest.getQueryExpression());
final List<XXXX> area = new DefaultXXXXService().getAllXXX().filter(new UncheckedFilterExpression<>(filtriFrontEnd)).select().execute(new ErpConfigContext("XXX"));
Thank you.

When run the query in the log i get the error: "Failed to construct URI for OData request with request path ..." "Illegal character in query at index 95. ...."
Can you check whether the following works for you..?
import com.sap.cloud.sdk.datamodel.odata.client.request.ODataUriFactory;
final String filter = context.getParameterInfo().getQueryParameter("$filter");
final String encodedFilter = ODataUriFactory.encodeQuery(filter);
final List<XXXXX> dati = new DefaultXXXService().getAllXXXX().select().withQueryParameter("$filter", encodedFilter ).executeRequest(dest);
Please let me know, as this could be an issue that needs to be addressed.

The method contract of withQueryParameter which explicitly warns about this API usage:
Using this function to bypass fluent helper method calls can lead to unsupported response handling. There is no contract on the order or priority of parameters added to the query.
Instead please use the filter function directly. There should be an entity field for the postal code, the code should look similar to this:
new DefaultXXXService()
.getAllXXXX()
.filter(Entity.POSTAL_CODE.eq("16100"))
If this is not feasible in your use case I suggest to build this filter expression manually as you did before and apply encoding to it as Alex pointed out in his answer.

Related

Why do I fail to submit data to textarea with python requests.post()

I want to use the requests.post tool to automatically query domain name attribution on this websitea website,But the return value is always empty, I guess it is because the post method failed to transfer the data to the textarea
url = 'http://icp.chinaz.com/searchs'
data = {
'hosts':'qq.com',
'btn_search':'%E6%9F%A5%E8%AF%A2', '__RequestVerificationToken=':'CfDJ8KmGV0zny1FLtrcRZkGCczG2owvCRigVmimqp33mw5t861kI7zU2VfQBri65hIwu_4VXbmtqImMmTeZzqxE7NwwvAtwWcZSMnk6UDuzP3Ymzh9YrHPJkj_cy8vSLXvUYXrFO0HnCb0pSweHIL9pkReY',
}
requests.post(url=url,data=data,headers=headers).content.decode('utf-8')
I'd be very grateful if you could point out where I'm going wrong
I have tried to replace headers and so on.

ReplyRequiredException on attempt to get data from <int-jdbc:outbound-gateway>?

I would like to define an
<int-jdbc:outbound-gateway/> with query and without update to retrieve data from database. Then I would like to use the int-jdbc:outbound-gateway as an implementation of Service.findSomeData() interface method. The data retrieved from interface implementation is used in my custom transformer's CheckService class. See the configuration below:
<int:service-activator method=“performCheck”>
<bean class=“com.example.service.CheckService”
c:service-ref=“service”
</int:service-activator>
<int:gateway id=“service” service-interface=“com.example.service.Service”>
<int:method name=“findSomeData” request-channel=“jdbcChan” reply-channel=“jdbcChanReply”/>
</int:gateway>
<int-jdbc:outbound-gateway request-channel=“jdbcChan”
data-source=“pooledDs” row-mapper=“dataRowMapper” reply-channel=“jdbcChanReply”>
<int-jdbc:query>
select some, data from some_table
</int-jdbc:query>
The problem is that I get ReplyRequiredException exception when I move my payload to jdbcChan:
org.springframework.integration.handler.ReplyRequiredException: No reply produced by handler 'org.springframework.integration.jdbc.JdbcOutboundGateway#0', and its 'requiresReply' property is set to true.
I decided to pay more attention on example located in spring in spring-integration-samples repository on GitHub, but looks like it also does not work as expected. I get exactly the same exception in example project trying to find User by name foo. You can easily reproduce the exception with basic jdbc example located on GitHub and the following test method:
#Test
public void findPerson() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"/META-INF/spring/integration/spring-integration-context.xml");
PersonService service = context.getBean(PersonService.class);
final List<Person> foo = service.findPersonByName("foo");
assertThat(foo, is(not(empty())));
}
Am I doing it wrong or there is a bug in latest Spring Integration JDBC? (for me looks like even example is broken)
I fixed the sample.
We changed the default for requires-reply to true a long time ago but the sample was never updated.
assertThat(foo, is(not(empty())));
However, the List<Person> is null when no results are received.
EDIT
But I would expect empty list instead of a null if ResultSet was empty.
That's not how it works.
If the resultSet is empty, null is returned (hence the original error you were seeing).
If the resultSet has 1 entry, just that entry is returned.
Otherwise a list of entities is returned.
Object payload = list;
if (list.isEmpty()) {
return null;
}
if (list.size() == 1) {
payload = list.get(0);
}
return payload;
It's been like that forever but I believe the single Object Vs. List is wrong (if maxRows > 1).
maxRows is 1 by default so it made sense then; however, if maxRows is > 1 and only 1 row is returned I think it should still be a list of 1. The application shouldn't have to check the type of the result. It either expects a list or a single object (or null). INT-4559.

How can I call this jOOQ generated function taking a custom bound type?

I originally had the following SQL function:
CREATE FUNCTION resolve_device(query JSONB) RETURNS JSONB...
and the following code calling the method generated by jOOQ:
final JsonArray jsonArray = jooqDWH.select(resolveDevice(queryJson)).fetchOne().value1().getAsJsonArray();
final JsonObject o = jsonArray.get(0).getAsJsonObject();
This worked fine. I needed to return a real device object rather than a JSON blob though, so I changed the SQL function to:
CREATE FUNCTION resolve_device(query JSONB) RETURNS SETOF device...
and the code to:
final ResolveDeviceRecord deviceRecord = jooqDWH.fetchOne(resolveDevice(queryJson));
but I am getting a runtime error:
org.jooq.exception.SQLDialectNotSupportedException: Type class com.google.gson.JsonElement is not supported in dialect DEFAULT
Many other parts of my code continue to work fine with the custom binding I have converting JsonElement to JSONB, but something about the change to this function's signature caused it to stop working.
I tried a few different variants of DSL.field() and DSL.val() to try to force it to be recognized but have not had any luck so far.
This could be a bug in jOOQ or a misconfiguration in your code generator. I'll update my answer once it is clear what went wrong.
Workaround:
Meanwhile, here's a workaround using plain SQL:
// Manually create a data type from your custom JSONB binding first:
final DataType<JsonObject> jsonb = SQLDataType.OTHER.asConvertedDataType(jsonBinding);
// Then, create an explicit bind variable using that data type:
final ResolveDeviceRecord deviceRecord =
jooqDWH.fetchOptional(table("resolve_device({0})", val(queryJson, jsonb)))
.map(r -> r.into(ResolveDeviceRecord.class))
.orElse(null);

com.google.gdata.util.InvalidEntryException when max-results is in URL

I want to change max-results while retrieving comments of a video from youtube. This is my code :
YouTubeService service = new YouTubeService(
"CLIENT_ID");
String str="http://gdata.youtube.com/feeds/api/videos/"+videoId;
YouTubeQuery youtubeQuery = new YouTubeQuery(new URL(
str));
youtubeQuery.setMaxResults(50);
youtubeQuery.setStartIndex(1);
String videoEntryUrl = youtubeQuery.getUrl().toString();
System.out.println(videoEntryUrl+" *************");
VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl),
VideoEntry.class);
While creating VideoEntry object in the last row, it gives this error :
Exception in thread "main" com.google.gdata.util.InvalidEntryException: The 'max-results' parameter is not supported on this resource
http://schemas.google.com/g/2005'>GDataunsupportedQueryParamThe 'max-results' parameter is not supported on this resource
My code prints the query so when it gives error query is like that :
http://gdata.youtube.com/feeds/api/videos/v_wzBsZLLaE?start-index=1&max-results=40
Why max-results parameter is not supported in this situation?
Greetings
You are requesting video information about one video. So, for 1 video, using start-index and max-results does not make any sense. (If it would be allowed then both can only be 1.)

return codes for Jira workflow script validators

I'm writing a workflow validator in Groovy to link two issues based on a custom field value input at case creation. It is required that the custom filed value to Jira issue link be unique. In other words, I need to ensure only one issue has a particular custom field value. If there is more than one issue that has the input custom field value, the validation should fail.
How or what do I return to cause a workflow validator to fail?
Example code:
// Set up jqlQueryParser object
jqlQueryParser = ComponentManager.getComponentInstanceOfType(JqlQueryParser.class) as JqlQueryParser
// Form the JQL query
query = jqlQueryParser.parseQuery('<my_jql_query>')
// Set up SearchService object used to query Jira
searchService = componentManager.getSearchService()
// Run the query to get all issues with Article number that match input
results = searchService.search(componentManager.getJiraAuthenticationContext().getUser(), query, PagerFilter.getUnlimitedFilter())
// Throw a FATAL level log statement because we should never have more than one case associated with a given KB article
if (results.getIssues().size() > 1) {
for (r in results.getIssues()) {
log.fatal('Custom field has more than one Jira ssue associated with it. ' + r.getKey() + ' is one of the offending issues')
}
return "?????"
}
// Create link from new Improvement to parent issue
for (r in results) {
IssueLinkManager.createIssueLink(issue.getId(), r.getId(), 10201, 1, getJiraAuthenticationContext().getUser())
}
try something like
import com.opensymphony.workflow.InvalidInputException
invalidInputException = new InvalidInputException("Validation failure")
this is based of the groovy script runner. If it doesn't work for you, i would recommend you using some sort of framework to make scripting easier, I like using either groovy script runner , Jira Scripting Suite or Behaviours Plugin
. All of them really makes script writing easier and much more intuitive.

Resources