Hi Jagath, It was only a test service and I have attached class with this. Full source is available at [1] as well.
Problem occurs with "void confirmOrder(-)" method because it is an InOnly operation. Unless "OUT_ONLY" property is applied on endpoint, ESB tries to get return value of above operation invocation, resulting in the exception. Hence, wanted to check with team what is the best approach to follow while defining proxy for a WSDL that has both InOnly and TwoChannel operations in a mix. [1] https://svn.wso2.com/wso2/interns/2013/ayoma/Axis2 Thanks and best regards, Ayoma. On Fri, Dec 11, 2015 at 2:18 PM, Jagath Sisirakumara Ariyarathne < [email protected]> wrote: > Hi Ayoma, > > Could you please share your OrderProcessor service class. > > Thanks. > > On Thu, Dec 10, 2015 at 5:10 PM, Ayoma Wijethunga <[email protected]> wrote: > >> Hi All, >> >> This is relevant to WSO2 ESB 4.9.0. >> >> In WSDL attached [1], there are five TwoChannelAxisOperation(s) and one >> InOnlyAxisOperation. In such situation, if we create a single proxy service >> in ESB with configuration [2 >> <https://drive.google.com/a/wso2.com/file/d/0B-0UyBaVrBStV3NhTG4wMWhvRFE/view?usp=drive_web>], >> InOnlyAxisOperation will fail with below exception : >> >> ERROR - NativeWorkerPool Uncaught exception >>> java.lang.UnsupportedOperationException: An access occurred that is not >>> valid. >>> at >>> org.apache.axis2.description.InOnlyAxisOperation.getMessage(InOnlyAxisOperation.java:117) >>> ..... >>> >> >> It was observed that it is possible to use "OUT_ONLY" and >> "FORCE_SC_ACCEPTED" to correct this [3 >> <https://docs.wso2.com/display/ESB481/Sample+12%3A+One-Way+Messaging+in+a+Fire-and-Forget+Mode+through+ESB>] >> [4 >> <https://docs.wso2.com/display/ESB481/HTTP+Transport+Properties#HTTPTransportProperties-FORCE_SC_ACCEPTED>]. >> But relevant transport property applies to endpoint, resulting in >> TwoChannelAxisOperation to fail if applied. >> >> When creating proxy service for a web service, what is the best practice >> to follow in order to avoid this type of problems? >> Do we create, >> >> - separate proxy services for each set of operations >> - use "switch" or "filter" mediator in the "in sequence" and "send" >> to OUT_ONLY endpoint depending on operation >> >> or what is the best path to follow? >> >> [1] >> https://drive.google.com/a/wso2.com/file/d/0B-0UyBaVrBStMDczTkRmMkhxcDg/view?usp=drive_web >> <https://drive.google.com/a/wso2.com/file/d/0B-0UyBaVrBStR0x4TUR6LWJkYnM/view?usp=drive_web> >> [2] >> https://drive.google.com/a/wso2.com/file/d/0B-0UyBaVrBStV3NhTG4wMWhvRFE/view?usp=drive_web >> [3] >> https://docs.wso2.com/display/ESB481/Sample+12%3A+One-Way+Messaging+in+a+Fire-and-Forget+Mode+through+ESB >> [4] >> https://docs.wso2.com/display/ESB481/HTTP+Transport+Properties#HTTPTransportProperties-FORCE_SC_ACCEPTED >> >> Thanks and best regards, >> Ayoma Wijethunga >> Software Engineer >> WSO2, Inc.; http://wso2.com >> lean.enterprise.middleware >> >> Mobile : +94 (0) 719428123 <+94+(0)+719428123> >> Blog : http://www.ayomaonline.com >> LinkedIn: https://www.linkedin.com/in/ayoma >> >> _______________________________________________ >> Dev mailing list >> [email protected] >> http://wso2.org/cgi-bin/mailman/listinfo/dev >> >> > > > -- > Jagath Ariyarathne > Technical Lead > WSO2 Inc. http://wso2.com/ > Email: [email protected] > Mob : +94 77 386 7048 > > -- Ayoma Wijethunga Software Engineer WSO2, Inc.; http://wso2.com lean.enterprise.middleware Mobile : +94 (0) 719428123 <+94+(0)+719428123> Blog : http://www.ayomaonline.com LinkedIn: https://www.linkedin.com/in/ayoma
/* * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.wso2.fasttrack.axis2.orderprocessor.processor; import java.math.BigDecimal; import com.wso2.fasttrack.axis2.orderprocessor.datamodel.init.PaymentMethod; import com.wso2.fasttrack.axis2.orderprocessor.datamodel.init.ShippingMethod; import com.wso2.fasttrack.axis2.orderprocessor.datamodel.item.Item; import com.wso2.fasttrack.axis2.orderprocessor.datamodel.order.Order; import com.wso2.fasttrack.axis2.orderprocessor.datamodel.order.OrderItem; import com.wso2.fasttrack.axis2.orderprocessor.datastore.DataStoreErrors; import com.wso2.fasttrack.axis2.orderprocessor.datastore.ItemStore; import com.wso2.fasttrack.axis2.orderprocessor.datastore.OrderItemStore; import com.wso2.fasttrack.axis2.orderprocessor.datastore.OrderStore; import com.wso2.fasttrack.axis2.orderprocessor.datastore.PaymentMethodStore; import com.wso2.fasttrack.axis2.orderprocessor.datastore.ShippingMethodStore; import com.wso2.fasttrack.axis2.orderprocessor.processor.error.OrderProcessorValidationError; /** * General order processing service functions */ public class OrderProcessor { public OrderProcessor() { InitDataStore.initDataStore(); } /** * Create new order * * @return created order ID * @throws OrderProcessorValidationError */ public long createOrder() throws OrderProcessorValidationError { Order order = new Order(); try { OrderStore.insert(order); } catch (IllegalArgumentException ex) { throw new OrderProcessorValidationError(ex.getMessage(), DataStoreErrors.getErrorDescription(ex.getMessage()), ex); } return order.getId(); } /** * Add an item to order * * @param orderId order ID * @param itemId item ID * @param quantity quantity to be added to order * @return order ID * @throws OrderProcessorValidationError */ public long addItemToOrder(long orderId, long itemId, short quantity) throws OrderProcessorValidationError { Item item = ItemStore.getItemById(itemId); Order order = OrderStore.getOrderById(orderId); OrderItem orderItem = new OrderItem(); orderItem.setItem(item); orderItem.setOrder(order); orderItem.setQuantity(quantity); try { OrderItemStore.insert(orderItem); } catch (IllegalArgumentException ex) { throw new OrderProcessorValidationError(ex.getMessage(), DataStoreErrors.getErrorDescription(ex.getMessage()), ex); } order.addOrderItems(orderItem); return orderItem.getId(); } /** * Link an payment method with order * * @param orderId order ID * @param paymentMethodId payment method ID * @return order ID */ public long addPaymentMethodToOrder(long orderId, long paymentMethodId) { Order order = OrderStore.getOrderById(orderId); PaymentMethod paymentMethod = PaymentMethodStore .getPaymentMethodById(paymentMethodId); order.setPaymentMethod(paymentMethod); return order.getId(); } /** * Link an shipping method with order * * @param orderId order ID * @param shippingMethodId shipping methid ID * @return order ID */ public long addShippingMethodToOrder(long orderId, long shippingMethodId) { Order order = OrderStore.getOrderById(orderId); ShippingMethod shippingMethod = ShippingMethodStore .getShippingMethodById(shippingMethodId); order.setShippingMethod(shippingMethod); return order.getId(); } /** * Calculate total value of the order as of currently available data. * Method does not fail if payment option or shipping method are not * selected. * * @param orderId order ID * @return total order value * @throws OrderProcessorValidationError */ public BigDecimal calculateOrder(long orderId) throws OrderProcessorValidationError { Order order = OrderStore.getOrderById(orderId); if (order.getOrderItems().size() == 0) { throw new OrderProcessorValidationError( DataStoreErrors.ORDER_EMPTY, DataStoreErrors .getErrorDescription(DataStoreErrors.ORDER_EMPTY)); } BigDecimal itemTotal = new BigDecimal(0); for (OrderItem orderItem : order.getOrderItems()) { itemTotal = itemTotal.add(orderItem.getItem().getPrice() .multiply(new BigDecimal(orderItem.getQuantity()))); } order.setItemTotal(itemTotal); if (order.getPaymentMethod() != null) { order.setPaymentTotal(order.getPaymentMethod().getCharge()); } if (order.getShippingMethod() != null) { order.setShippingTotal(order.getShippingMethod().getCharge()); } order.setOrderTotal(itemTotal.add(order.getPaymentTotal()).add( order.getShippingTotal())); return order.getOrderTotal(); } /** * Validate if order is in complete state and calculate total order value * and set order state as confirmed. * * @param orderId order ID * @throws OrderProcessorValidationError */ public void confirmOrder(long orderId) throws OrderProcessorValidationError { Order order = OrderStore.getOrderById(orderId); if (order.getOrderItems().size() == 0) { throw new OrderProcessorValidationError( DataStoreErrors.ORDER_EMPTY, DataStoreErrors .getErrorDescription(DataStoreErrors.ORDER_EMPTY)); } if (order.getPaymentMethod() == null) { throw new OrderProcessorValidationError( DataStoreErrors.ORDER_PAYMENT_EMPTY, DataStoreErrors .getErrorDescription(DataStoreErrors.ORDER_PAYMENT_EMPTY)); } if (order.getShippingMethod() == null) { throw new OrderProcessorValidationError( DataStoreErrors.ORDER_SHIPPING_EMPTY, DataStoreErrors .getErrorDescription(DataStoreErrors.ORDER_SHIPPING_EMPTY)); } calculateOrder(orderId); order.setConfirmed(true); System.err.println("CONFIRMED : " + orderId); } }
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
