当前位置:首页 > 开发 > 开源软件 > 正文

JAXB+Maven+ESB+Restful+XStream

发表于: 2014-04-23   作者:coffeehot   来源:转载   浏览次数:
摘要: JAXB在rest架构中充当着不可或缺的角色,是xml数据得以转化为java对象 注册JAXB类       public void registerClasses(Class[] classes){ try { JAXBContext context = JAXBContext.newInstance(classes); } cat
JAXB在rest架构中充当着不可或缺的角色,是xml数据得以转化为java对象
注册JAXB类

      public void registerClasses(Class[] classes){
try {
JAXBContext context = JAXBContext.newInstance(classes);
} catch (JAXBException e) {
log.error("Initialize JAXB failed:" + e.getMessage());
}
}

XStream配合JAXB的工作,其中client端的类需要序列化,server端不需要
client 端的类定义

@XmlRootElement(name = "VirtualRoomFilter")
public class VirtualRoomFilter implements java.io.Serializable
{
public VirtualRoomFilter(){};

public String name = null;

public Integer customerId = null;

public Integer siteId = null;

public String status = null;

public String e164 = null; 

public Integer mcuId = null;

}

server 端的类定义

@XmlRootElement(name = "VirtualRoomFilter")
public class VirtualRoomFilter implements java.io.Serializable
{
public VirtualRoomFilter(){};

public String name = null;

public Integer customerId = null;

public Integer siteId = null;

public String status = null;

public String e164 = null; 

public Integer mcuId = null;

}

rest(ESB)的逻辑
@POST
@Path("/getvrsfltr/")
public String getVirtualRoomsByFilter(
@HeaderParam(SERV_NAME) String serv_name,
@HeaderParam(SERV_PW) String serv_pw,
@HeaderParam(USER_NAME) String user_name,
@HeaderParam(USER_PW)   String user_pw,
@HeaderParam(VERSION)   String version,
@HeaderParam(CALLING_MODULE) String calling_module,
@QueryParam("requestContext") String request_context,
@QueryParam(SESSION_ID) String sessionId1,
@HeaderParam(SESSION_ID)    String sessionId2,
@Context HttpServletRequest httpRequestContext,
VirtualRoomFilter vrFilter)
{
String METHOD_NAME = "getVirtualRoomsByFilter";
log.info(METHOD_NAME + "===filter info: customer id = " + vrFilter.customerId + ", vr name = " + vrFilter.name + ", site id = " + vrFilter.siteId+ ", vr status = " + vrFilter.status + ", e164 = " + vrFilter.e164 + ", mcu id = " + vrFilter.mcuId);
BcsAuditLog esbUsageLog = handleStart(user_name, serv_name, METHOD_NAME, toPostXML(vrFilter), calling_module, getIp(httpRequestContext));

BcsResponse loginResult = loginByCredentialsOrSession(serv_name, serv_pw, user_name,  user_pw, esbUsageLog, sessionId1, sessionId2, httpRequestContext);
if(! loginResult.isSuccessful()) return  handleError("login", loginResult, esbUsageLog);

RequestContext requestContext = null;
try
{
requestContext = handleRequestContextParameter(request_context);
}
catch (Exception e)
{
return handleError("Parameter problem: ", new BcsResponseErrorAndDescr(new BcsResponseError("AA11", null), e.getMessage()), esbUsageLog);
}

try
{
log.debug("getVirtualRoomsByFilter: step 1");

BcsResponse retVal = new BcsResponse();
retVal.setSuccessful(true);
retVal.setReturnedObject(myMethods.getVirtualRoomsByFilter(vrFilter));
retVal.setWarningStr(METHOD_NAME);

return marshal(retVal, esbUsageLog, "getvrs", version, requestContext);
}
catch (java.lang.Throwable t)
{
return handleError(METHOD_NAME, t, esbUsageLog, user_name);
}
}

maven的依赖配置
<dependency>
  <groupId>junit</groupId>
<artifactId>junit</artifactId>
  <version>4.4</version>
</dependency>
  <dependency>
<groupId>org.apache.servicemix.specs</groupId>
<artifactId>org.apache.servicemix.specs.jsr311-api-0.8</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.specs</groupId>
<artifactId>org.apache.servicemix.specs.jaxb-api-2.1</artifactId>
<version>1.3.0.0-fuse</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.commons-httpclient</artifactId>
<version>3.1_1-fuse</version>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.16</version>
</dependency>

JAXB+Maven+ESB+Restful+XStream

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

推荐文章
编辑推荐
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号