實例化JerseyTest與此類JerseyTest與四郎
public class NMAAbstractRestTest extends JerseyTest {
@Override
protected Application configure() {
NMAdaptorApplication application = new NMAdaptorApplication();
return application;
}
}
NMAdaptorApplication構造。
public NMAdaptorApplication() {
log.info("NM-Adaptor-Application is being initilized....");
register(NMRestExceptionMapper.class);
register(ShiroFeature.class);
register(NMMarshallingFeature.class);
register(new LoggingFeature(java.util.logging.Logger.getLogger("nma"), LoggingFeature.Verbosity.PAYLOAD_ANY));
packages(true, "com.retailwave.rwos.nma.rest.resource");
loadProperties();
}
在執行以下的試驗方法
@Test
public void makeOrder()
{
...
Entity entity = Entity.entity(orderContent, MediaType.APPLICATION_JSON);
WebTarget target = target("customerorders");
target.path("");
target.queryParam("cmd", "create");
target.queryParam("branchCode", "610");
arget.property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_USERNAME, "admin");
target.property(HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_PASSWORD, "admin");
Response response = target.request().post(entity);
}
得到以下例外
16:34:23.893 ERROR [Grizzly的HTTP服務器 - 0] crrneNMRestExceptionMapper - 捕獲到異常在Mapper中:沒有SecurityManager可以被調用代碼訪問,或者綁定到org.apache.shiro.util.ThreadContext或者作爲一個vm靜態單例。這是一個無效的應用程序配置。 org.apache.shiro.UnavailableSecurityManagerException:調用代碼無法訪問SecurityManager,無論是綁定到org.apache.shiro.util.ThreadContext還是作爲vm靜態單例。這是一個無效的應用程序配置。 在org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123) 在org.apache.shiro.subject.Subject $生成器。(Subject.java:627)
我猜它因我在web.xml中配置的Shiro過濾器
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
while JUnit test this failed。是否有任何選項在JerseyTest中包含web.xml
完美,沒有解決但如今卻需要額外四郎CONFIGS。希望我能解決它。一旦完成,我會更新。 – vels4j