2011年6月14日 星期二

在同一台機器上執行多個 JBOSS server node/instance , 發生 ports 衝突

系統環境:
JBoss: JBoss_4.2.2.GA


在同一台機器上執行多個 JBOSS server node/instanc:

JBoss 提供了 Binding Manager 服務 , 預設可同時執行 4 個 nodes.
JBoss 的設定文件:%JBOSS_HOME%\docs\examples\binding-manager\sample-bindings.xml,該文件默認情況下定義了4組不同的端口配置(port-default、port-01、port-02、port-03

  1. 設置多個 server nodes :
  2. 修改 server nodes 的設定:[node-name]/conf/jboss-service.xml文件,配置Service Binding(默認註釋掉)如下:

        <mbean code="org.jboss.services.binding.ServiceBindingManager"
                       name="jboss.system:service=ServiceBindingManager">
            <attribute name="ServerName">ports-02</attribute>
            <attribute name="StoreURL">${jboss.home.url}/docs/examples/binding-manager    /sample-bindings.xml</attribute>
            <attribute name="StoreFactoryClassName">
                org.jboss.services.binding.XMLServicesStoreFactory
           </attribute>
       </mbean>

======
錯誤狀況 : 如果同時執行 default-ports , ports-03的設置 , 會發生 ports 衝突


解決方案 : 修改 sample-bindings.xml -- 
  • sample-bindings.xml 中 ports-03 並沒有設定 remoting ,  
  • 將  default-ports 的   EJB3 Remoting Connector (line 197) 及 remoting connector (line 267 ) 的 區段複製到 ports-03 中  
  • 將複製到 ports-03 的區段中的 ports 3873 4446 改為 6873 及 7446

2011年5月31日 星期二

Web Service : 無法在 @WebService 中使用 @Autowired

Web Service : 無法在 @WebService 中使用 @Autowired

Solution:
可以使用 springframework  提供的 SpringBeanAutowiringSupport


 import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@WebService()
public class Trade extends SpringBeanAutowiringSupport {// 在 WebService 中使用 Spring @Autowired

  @Resource
  WebServiceContext wsCtxt;

  @Autowired
  private IGameOrderService gameOrderService;

Reference :
http://static.springsource.org/spring/docs/2.5.x/reference/remoting.html
詳見 17.5.5 那一段

Web Service : llegalAnnotationsException: Two classes have the same XML type name

Web Service : com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:
Two classes have the same XML type name

系統環境:
JBoss: JBoss_4.2.2.GA
JDK: JDK1.6.0_14
IDE: NetBeans 6.9

code :

@WebService()
public class Trade {

@WebMethod(operationName = "gameOrder")
public GameOrderResponse gameOrder(
@WebParam(name = "GameOrderId") String gameOrderId,
@WebParam(name = "GameCode") String gameCode) {
GameOrderResponse response = null;
....
return response;
}
}

Error:
java.lang.IllegalStateException: Cannot build JAXB context
......
......
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://ws.billing.lkt.com/}gameOrderResponse". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.lkt.billing.ws.type.GameOrderResponse
at private com.lkt.billing.ws.type.GameOrderResponse com.lkt.billing.ws.jaxws.GameOrderResponse._return
at com.lkt.billing.ws.jaxws.GameOrderResponse
this problem is related to the following location:
at com.lkt.billing.ws.jaxws.GameOrderResponse


Solution:
JAX-WS 會為 annotation @WebMethod 的每個方法, 自動生成一個 message element, 名為 methodName + "Response" ; 恰巧 return object 的 class 也命名相同, 因此會有衝突.
方法一 : 不要使用到 methodName + "Response" 來命名 response classes.
方法二 : 使用 @XMLType 指定不同的 namespaces 給 message elements.

Reference:
http://stackoverflow.com/questions/4254334/illegalannotationexception-two-classes-have-the-same-xml-type-name