JAXB+Maven+ESB+Restful+XStream

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>

你可能感兴趣的:(maven,JAXB,Restful,xstream,ESB)