org.apache.camel.Converter Java Examples
The following examples show how to use
org.apache.camel.Converter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #2
Source File: CustomerConverter.java From learning with Apache License 2.0 | 6 votes |
@Converter public static Customer from(List<Map<String, Object>> objects) { Customer customer = new Customer(); if (objects != null && !objects.isEmpty()) { Map<String, Object> customerData = objects.get(0); customer.setFirstName((String)customerData.get("firstName")); customer.setLastName((String)customerData.get("lastName")); customer.setSsn((String)customerData.get("ssn")); customer.setDob(customerData.get("dob").toString()); customer.setStreetAddress(customerData.get("streetaddress").toString()); customer.setCity(customerData.get("city").toString()); customer.setState(customerData.get("state").toString()); customer.setPostalCode(customerData.get("postalcode").toString()); customer.setCheckingBalance(customerData.get("checkingbalance").toString()); customer.setSavingsBalance(customerData.get("savingsBalance").toString()); } return customer; }
Example #3
Source File: PurchaseOrderConverter.java From camelinaction with Apache License 2.0 | 6 votes |
@Converter public static PurchaseOrder toPurchaseOrder(byte[] data, Exchange exchange) { TypeConverter converter = exchange.getContext().getTypeConverter(); String s = converter.convertTo(String.class, data); if (s == null || s.length() < 30) { throw new IllegalArgumentException("data is invalid"); } s = s.replaceAll("##START##", ""); s = s.replaceAll("##END##", ""); String name = s.substring(0, 9).trim(); String s2 = s.substring(10, 19).trim(); String s3 = s.substring(20).trim(); BigDecimal price = new BigDecimal(s2); price.setScale(2); Integer amount = converter.convertTo(Integer.class, s3); PurchaseOrder order = new PurchaseOrder(name, price, amount); return order; }
Example #4
Source File: InventoryConverter.java From camelinaction with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #5
Source File: InventoryConverter.java From camelinaction with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #6
Source File: InventoryConverter.java From camelinaction with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #7
Source File: InventoryConverter.java From camelinaction with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #8
Source File: InventoryConverter.java From camelinaction with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #9
Source File: InventoryConverter.java From camelinaction with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #10
Source File: InventoryConverter.java From camelinaction with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #11
Source File: PurchaseOrderConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Converter public static PurchaseOrder toPurchaseOrder(byte[] data, Exchange exchange) { TypeConverter converter = exchange.getContext().getTypeConverter(); String s = converter.convertTo(String.class, data); if (s == null || s.length() < 30) { throw new IllegalArgumentException("data is invalid"); } s = s.replaceAll("##START##", ""); s = s.replaceAll("##END##", ""); String name = s.substring(0, 10).trim(); String s2 = s.substring(10, 20).trim(); String s3 = s.substring(20).trim(); BigDecimal price = new BigDecimal(s2); price.setScale(2); Integer amount = converter.convertTo(Integer.class, s3); PurchaseOrder order = new PurchaseOrder(name, price, amount); return order; }
Example #12
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #13
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #14
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #15
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #16
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #17
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #18
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #19
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #20
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #21
Source File: InventoryConverter.java From camelinaction2 with Apache License 2.0 | 6 votes |
/** * This method can convert from CSV (String) to model object. * <p/> * By annotation this method with @Converter we tell Camel to include this method * as a type converter in its type converter registry. * * @param csv the from type * @return the to type */ @Converter public static UpdateInventoryInput toInput(String csv) { String[] lines = csv.split(","); if (lines == null || lines.length != 4) { throw new IllegalArgumentException("CSV line is not valid: " + csv); } UpdateInventoryInput input = new UpdateInventoryInput(); input.setSupplierId(lines[0]); input.setPartId(lines[1]); input.setName(lines[2]); input.setAmount(lines[3]); return input; }
Example #22
Source File: CustomerConverter.java From learning with Apache License 2.0 | 6 votes |
@Converter public static Customer from(List<Map<String, Object>> objects) { Customer customer = new Customer(); if (objects != null && !objects.isEmpty()) { Map<String, Object> customerData = objects.get(0); customer.setFirstName((String)customerData.get("firstName")); customer.setLastName((String)customerData.get("lastName")); customer.setSsn((String)customerData.get("ssn")); customer.setDob(customerData.get("dob").toString()); customer.setStreetAddress(customerData.get("streetaddress").toString()); customer.setCity(customerData.get("city").toString()); customer.setState(customerData.get("state").toString()); customer.setPostalCode(customerData.get("postalcode").toString()); customer.setCheckingBalance(customerData.get("checkingbalance").toString()); customer.setSavingsBalance(customerData.get("savingsBalance").toString()); } return customer; }
Example #23
Source File: CustomConverter.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Converter public Map<String, String> toMap(Customer customer) { Map<String, String> result = new LinkedHashMap<String, String>(); result.put("firstName", customer.getFirstName()); result.put("lastName", customer.getLastName()); return Collections.unmodifiableMap(result); }
Example #24
Source File: MyPersonTypeConverter.java From camel-cookbook-examples with Apache License 2.0 | 5 votes |
/** * Converts a String in the format of "firstName|lastName" to a {@link MyPerson}. */ @Converter public static MyPerson convertStringToMyPerson(String str) { final int index = str.indexOf("|"); if (index > 0) { final MyPerson person = new MyPerson(); person.setFirstName(str.substring(0, index)); person.setLastName(str.substring(index + 1)); // skip the '|' at index return person; } throw new IllegalArgumentException("String must be in format of '<firstName>|<lastName>'"); }
Example #25
Source File: CamelNativeImageProcessor.java From camel-quarkus with Apache License 2.0 | 4 votes |
@BuildStep void reflectiveItems( CombinedIndexBuildItem combinedIndex, BuildProducer<ReflectiveClassBuildItem> reflectiveClass, BuildProducer<ReflectiveMethodBuildItem> reflectiveMethod) { final IndexView view = combinedIndex.getIndex(); CAMEL_REFLECTIVE_CLASSES.stream() .map(Class::getName) .map(DotName::createSimple) .map(view::getAllKnownImplementors) .flatMap(Collection::stream) .filter(CamelSupport::isPublic) .forEach(v -> reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, v.name().toString()))); DotName converter = DotName.createSimple(Converter.class.getName()); List<ClassInfo> converterClasses = view.getAnnotations(converter) .stream() .filter(ai -> ai.target().kind() == Kind.CLASS) .filter(ai -> { AnnotationValue av = ai.value("loader"); boolean isLoader = av != null && av.asBoolean(); // filter out camel-base converters which are automatically inlined in the // CoreStaticTypeConverterLoader // need to revisit with Camel 3.0.0-M3 which should improve this area if (ai.target().asClass().name().toString().startsWith("org.apache.camel.converter.")) { LOGGER.debug("Ignoring core " + ai + " " + ai.target().asClass().name()); return false; } else if (isLoader) { LOGGER.debug("Ignoring " + ai + " " + ai.target().asClass().name()); return false; } else { LOGGER.debug("Accepting " + ai + " " + ai.target().asClass().name()); return true; } }) .map(ai -> ai.target().asClass()) .collect(Collectors.toList()); LOGGER.debug("Converter classes: " + converterClasses); converterClasses .forEach(ci -> reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ci.name().toString()))); view.getAnnotations(converter) .stream() .filter(ai -> ai.target().kind() == Kind.METHOD) .filter(ai -> converterClasses.contains(ai.target().asMethod().declaringClass())) .map(ai -> ai.target().asMethod()) .forEach(mi -> reflectiveMethod.produce(new ReflectiveMethodBuildItem(mi))); }
Example #26
Source File: ZipFileEntryTypeConverter.java From secure-data-service with Apache License 2.0 | 4 votes |
@Converter public static XMLEventReader toXMLEventReader(ZipFileEntry zipFileEntry, Exchange exchange) throws XMLStreamException, IOException { StaxConverter c = new StaxConverter(); return c.createXMLEventReader(toInputStream(zipFileEntry, exchange), exchange); }
Example #27
Source File: CustomConverter.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Converter public Customer toCustomer(Map<String, String> map) { return new Customer(map.get("firstName"), map.get("lastName")); }
Example #28
Source File: CloudEventTypeConverter.java From camel-k-runtime with Apache License 2.0 | 4 votes |
@Converter public static CloudEvent fromSpecVersion(String version) { return CloudEvents.fromSpecVersion(version); }