org.apache.camel.InvalidPayloadException:No body available of type: - apache-camel

I have Process model class converting as:
<convertBodyTo type="com.sample.Process" />
My assumption getting body null.
org.apache.camel.InvalidPayloadException:No body available of type: com.sample.Process but has type: org.apache.cxf.message.MessageContentsList on: Message[000000]. Caused by: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: com.sample.Process. Exchange[]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: com.sample.Process]

Related

TypeScript File upload error - Type 'File' is not assignable to type 'string'

This is my PlayerInterface
interface playerInterface {
id?: string,
_id?: null,
name: string
club: string,
image?: string,
important: boolean
}
This is my useState hook:
const [player, setPlayer] = useState<PlayerInterface>({ id: '', name: '', club: '', important: false, image: '' })
And this is my handleFileUpload:
const handleFileUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
setPlayer({ ...player, image: e.target.files![0] })
}
Right now, in handleFileUpload, the image is underlined, with the error saying Type 'File' is not assignable to type 'string'
What is the solution for this?
Edit
Based on your edit to playerInterface, you are trying to assign a File ( e.target.files![0]) to a string variable. Try changing playerInterface to a File type, or using a ReadableStream to store it as a data string.
Without knowing what database you are using, it is difficult to say exactly what the problem is, but it is likely you will need to convert the binary/Base64 string representation of the uploaded file back into its original format in order to store it as a File. However, from my experience, I would suggest storing the file as the string representation, and only converting to the image/file representation when it is actually required (i.e. on rendering in your front end).

How to infer types of an object created from a schema?

I'm trying to implement something similar to storybook's "Controls" feature where you can define a bunch of properties, and they become controls in the UI.
I defined a schema type and a schema of how to create those controls:
// Example schema
var newSchema: BlockSchema = {
title: "New Schema",
controls: {
name: {
type: 'string',
placeholder: 'Please insert your name'
},
size: {
type: 'select',
options: ['quarter', 'half', 'full']
},
hasInfo: {
type: 'bool'
},
amount: {
type: 'number'
}
}
}
But now I need a type that is the result of what the user has selected. A type for the final values, something like:
type MapControlTypes = {
bool: boolean;
string: string;
select: string;
number: number;
};
type InferType<T extends BlockSchema> = { /* MapControlTypes<?????????> */ }
type NewSchemaControls = InferType<typeof newSchema>;
/* Expected result:
NewSchemaControls = {
name: string;
size: string;
hasInfo: boolean;
amount: number;
}
*/
I need to infer the types from the controls property of my schema, but how could I implement this inference? Here's a playground with complete example code
I tried implementing this, and this solution. But they don't work well and also only support two types.
Titian Cernicova-Dragomir's solution didn't work too. Playground, but it has a very similar problem that happened when I tried other solutions. Maybe is it because I'm not using MapControlTypes on my ControlSchema?
Solved!
You can do this, using a mapped type, but first you need to preserve the original type of the schema. If you add a type annotation to it, then information about specific fields and types will be lost. It will just be a BlockSchema
The easiest way to do this is to omit the annotation, and use an as const assertion to make the compiler infer literal types for type.
With this extra info in hand, we can then use a mapped type to transform the schema into an object type:
type InferType<T extends BlockSchema> = {
-readonly [P in keyof T['controls']]: MapControlTypes[T['controls'][P]['type']]
}
Playground Link
You can also use a function to create the schema, and be more selective about what gets the readonly treatment:
function buildBlockSchema<B extends BlockSchema>(b: B) {
return b
}
Playground Link

flow nested object values not accesible

I'm trying to access deeply nested values from an object but i'm getting the following error in flow:
Property cannot be accessed on property 'author' of unknown type
type ARTICLE_TYPE = {
id: number,
authorId: number,
type: 'article' | 'video' | 'audio' | 'perspective',
title: string,
preview: string,
imageUrl: ?string,
date: string,
}
type AUTHOR_TYPE = {
company: string,
id: number,
name: string,
profileImage: string
}
type TileProps = {
...ARTICLE_TYPE,
...{
author: AUTHOR_TYPE,
},
imageAspectRatio: string
}
I suspect it might be something to do with the way i'm defining the type but it seems ok to me:
Relevant testable code is Here
Any help is appreciated!
I suggest you don't use spread operators with flow types, rather use type concatenation.
type TileProps = ARTICLE_TYPE & {
author: AUTHOR_TYPE,
imageAspectRatio: string
}
Make life easy on yourself and those who read your code after you.

RAML 1.0 Array of inner types

I have an api with two main resources : Project and Product, they are two differents resources with only a link between them.
Product:
type: object
properties:
name: string
projects: ProjectReference[]
ProjectReference:
type: object
properties:
identifier: string
links: Links[]
Project:
type: object
properties:
identifier: string
members: string[]
product:
type: object
properties:
name: string
links: Link[]
Link:
type: object
properties:
rel: string
href: string
I would like to inline the ProjectReference type into Product. However, I have not found how to create array of inline types.
Can we create array of inline types with RAML 1.0 ?
Not sure what is the advantage of inlining....but you could do this:
Product:
type: object
properties:
name: string
projects:
type: array
items:
type: object
properties:
identifier: string
links: Links[]

AngularJs Dynamic Input Type [duplicate]

This question already has answers here:
How can I use Angular to output dynamic form fields?
(3 answers)
Closed 9 years ago.
I am trying to create a dynamic input fields based on a given model.
I want the input elements to have a dynamic type property, but when I do it I get the following exception:
Error: type property can't be changed
I've read that IE doesn't support change of the input type, and therefore angular disallowed it for cross-browser compatibility, but I am sure there is a walkaround in my case, when the input elements are loaded only once and don't change after the first load.
The model:
details: {
serverName: { type: 'text' },
port: { type: 'number' },
nickname: { type: 'text' },
password: { type: 'password' },
channel: { type: 'text' },
channelPassword: { type: 'text' },
autoBookmarkAdd: { type: 'checkbox' }
}
The html code:
<ul>
<li ng-repeat="(index,detail) in communication.details">{{index}}:
<input type="{{detail.type}}" ng-model="detail.value" /></li>
</ul>
As Mark said, using ng-switch will allow me using dynamic input types.

Resources