本文整理汇总了Java中org.jboss.resteasy.core.ServerResponse类的典型用法代码示例。如果您正苦于以下问题:Java ServerResponse类的具体用法?Java ServerResponse怎么用?Java ServerResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerResponse类属于org.jboss.resteasy.core包,在下文中一共展示了ServerResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postProcess
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
@Override
public void postProcess(ServerResponse response)
{
final MultivaluedMap<String, Object> metadata = response.getMetadata();
final Object contentType = metadata.getFirst(CONTENT_TYPE_HEADER);
if( contentType != null )
{
final String ct;
if( contentType instanceof MediaType )
{
MediaType mct = (MediaType) contentType;
ct = mct.toString().toLowerCase();
}
else
{
ct = ((String) contentType).toLowerCase();
}
if( ct.contains("json") && !ct.contains("charset"))
{
metadata.putSingle(CONTENT_TYPE_HEADER, ct + "; charset=utf-8");
}
}
}
示例2: testURIParamsAuthentication
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
/**
* Test method for
* {@link org.jboss.dcp.api.rest.AuthenticationInterceptor#preProcess(org.jboss.resteasy.spi.HttpRequest, org.jboss.resteasy.core.ResourceMethod)}
* .
*/
@Test
public void testURIParamsAuthentication() {
AuthenticationInterceptor tested = getTested();
HttpRequest requestMock = getHttpRequestMock();
ResourceMethod methodMock = Mockito.mock(ResourceMethod.class);
@SuppressWarnings("unchecked")
MultivaluedMap<String, String> queryParamsMock = Mockito.mock(MultivaluedMap.class);
Mockito.when(queryParamsMock.getFirst("provider")).thenReturn(uname);
Mockito.when(queryParamsMock.getFirst("pwd")).thenReturn(pwd);
Mockito.when(requestMock.getUri().getQueryParameters()).thenReturn(queryParamsMock);
Mockito.when(tested.providerService.authenticate(uname, pwd)).thenReturn(true);
ServerResponse res = tested.preProcess(requestMock, methodMock);
Assert.assertNull(res);
Mockito.verify(tested.providerService, Mockito.times(1)).authenticate(Mockito.anyString(), Mockito.anyString());
SecurityContext ctx = ResteasyProviderFactory.getContextData(SecurityContext.class);
Assert.assertEquals("uname", ctx.getUserPrincipal().getName());
Assert.assertEquals("CUSTOM", ctx.getAuthenticationScheme());
}
示例3: responseHeaderForGETTest
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void responseHeaderForGETTest() {
Class noparams[] = {};
Method aMethod = null;
try {
aMethod = CORSSupportInterceptorTest.class.getDeclaredMethod("methodGET", noparams);
} catch (NoSuchMethodException e) {
Assert.fail(e.getMessage());
}
ServerResponse response = new ServerResponse();
response.setResourceMethod(aMethod);
CORSSupportInterceptor.addHeaders(aMethod);
CORSSupportInterceptor tested = getTested();
tested.postProcess(response);
Assert.assertTrue(response.getMetadata().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
Assert.assertEquals("*", response.getMetadata().get(ACCESS_CONTROL_ALLOW_ORIGIN).get(0));
Assert.assertFalse(response.getMetadata().containsKey(ACCESS_CONTROL_MAX_AGE));
}
示例4: postProcess
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
@Override
public void postProcess(ServerResponse response)
throws Failure, WebApplicationException {
if (response.getEntity() == null) {
LOGGER.info("Entity de la respuesta es null");
}
}
示例5: preProcess
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
@Override
public ServerResponse preProcess(HttpRequest hr, ResourceMethodInvoker rmi) throws Failure, WebApplicationException {
String methodName = rmi.getMethod().getName();
String remoteAddress = servletRequest.getRemoteAddr();
String requestUri = servletRequest.getRequestURI();
String queryString = servletRequest.getQueryString();
String httpMethod = servletRequest.getMethod();
String requestData = "Remote Adress: " + remoteAddress + "\n\t\t\t"
+ "Method: " + methodName + "\n\t\t\t"
+ "Request URI: " + requestUri + "\n\t\t\t"
+ "Query String: " + queryString + "\n\t\t\t"
+ "HTTP Method: " + httpMethod;
LOGGER.info(requestData);
Enumeration<String> headerNames = servletRequest.getHeaderNames();
servletRequest.getHeader("");
if (LOGGER.isTraceEnabled()) {
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
Enumeration<String> headers = servletRequest.getHeaders(headerName);
while (headers.hasMoreElements()) {
String headerValue = headers.nextElement();
LOGGER.trace(headerName + ": " + headerValue);
}
}
} else {
String contentType = servletRequest.getHeader("content-type");
LOGGER.info("content-type: " + contentType);
String acceptEnconding = servletRequest.getHeader("accept-encoding");
LOGGER.info("accept-encoding: " + acceptEnconding);
}
return null;
}
示例6: postProcess
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
@Override
public void postProcess(ServerResponse response) {
final List<Message> messages = clientMessages.getMessages();
if (!messages.isEmpty()) {
try {
headerUtil.writeTo(messages, MessageUtils.MESSAGES_HEADER_SUFFIX, response);
} catch (IOException e) {
LOG.error("Error while adding client messages to the response", e);
}
}
}
示例7: preProcess
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
public ServerResponse preProcess(HttpRequest request, ResourceMethodInvoker method)
throws Failure, WebApplicationException {
if (logger.isDebugEnabled()) {
String httpMethod = request.getHttpMethod();
URI uri = ui.getRequestUri();
String uriPath = uri.getPath();
if (uri.getQuery() != null) {
uriPath += "?" + uri.getQuery();
}
if (uri.getFragment() != null) {
uriPath += "#" + uri.getFragment();
}
String sessionid = null;
List<String> headerSessionId = request.getHttpHeaders().getRequestHeader("sessionid");
if (headerSessionId != null) {
sessionid = headerSessionId.get(0);
}
if (logger.isDebugEnabled()) {
// log only in debug mode
logger.debug(sessionid + "|" + httpMethod + "|" + uriPath);
}
}
return null;
}
示例8: postProcess
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
public void postProcess(ServerResponse response) {
Iterator<Entry<String, List<String>>> it = httpHeaders.getRequestHeaders().entrySet().iterator();
// get sessionid from headers
String sessionid = "[NOTSET]";
List<String> headerSessionId = httpHeaders.getRequestHeaders().get("sessionid");
if (headerSessionId != null) {
sessionid = headerSessionId.get(0);
}
URI uri = ui.getRequestUri();
String uriPath = uri.getPath();
if (uri.getQuery() != null) {
uriPath += "?" + uri.getQuery();
}
if (uri.getFragment() != null) {
uriPath += "#" + uri.getFragment();
}
if (logger.isDebugEnabled()) {
// in debug mode log anything
logger.info(sessionid + "|" + uriPath + "|" + response.getStatus() + "|" + response.getEntity().toString());
} else {
// log errors even in info mode
if ((logger.isInfoEnabled()) && (response.getStatus() >= 300)) {
logger.info(sessionid + "|" + uriPath + "|" + response.getStatus() + "|" +
response.getEntity().toString());
}
}
}
示例9: postProcess
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
@Override
public void postProcess(ServerResponse response) {
final MultivaluedMap<String, Object> headers = response.getMetadata();
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Headers", getRequestedHeaders(response));
headers.add("Access-Control-Allow-Credentials", "true");
headers.add("Access-Control-Allow-Methods", ALLOWED_METHODS);
headers.add("Access-Control-Max-Age", MAX_AGE);
headers.add("x-responded-by", "cors-response-filter");
}
示例10: postProcess
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
/**
* Implementatie van de PostProcessInterceptor interface.
*
* @param response server response
*/
@Override
public void postProcess(ServerResponse response) {
StringBuilder sb = STRING_BUILDER.get();
if (null == sb) {
sb = new StringBuilder();
STRING_BUILDER.set(sb);
}
Object result = response.getEntity();
if (result != null) {
sb.append("\nReply type: ");
sb.append(result.getClass().toString());
sb.append("\nOutput document:\n");
try {
if (result.getClass().isAnnotationPresent(DoNotLog.class)) {
sb.append("<Not serialized ").append(result.getClass().toString()).append(">");
} else if (contains(response.getAnnotations(), DoNotLogResponse.class)) {
sb.append(String.format("<Not serialized response from method '%s>", PROFILE_GROUP.get()));
} else if (result.getClass().isAnnotationPresent(LogUsingToString.class)) {
sb.append(result.toString());
} else if (result instanceof String) {
sb.append(result);
} else {
String output = MAPPER.writeValueAsString(result);
sb.append(output);
}
} catch (IOException e) {
LOG.warn("JSON probleem met " + result, e);
}
}
finishCall(false);
}
示例11: postProcess
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
@Override
public void postProcess(ServerResponse serverResponse) {
List<Header> h = headers.get(serverResponse.getResourceMethod());
if (h != null) {
for (Header header : h) {
serverResponse.getMetadata().add(header.key, header.value);
}
}
}
示例12: testNotAuthenticated
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
/**
* Test method for
* {@link org.jboss.dcp.api.rest.AuthenticationInterceptor#preProcess(org.jboss.resteasy.spi.HttpRequest, org.jboss.resteasy.core.ResourceMethod)}
* .
*/
@Test
public void testNotAuthenticated() {
AuthenticationInterceptor tested = getTested();
HttpRequest requestMock = getHttpRequestMock();
ResourceMethod methodMock = Mockito.mock(ResourceMethod.class);
ServerResponse res = tested.preProcess(requestMock, methodMock);
Assert.assertNull(res);
Mockito.verify(tested.providerService, Mockito.times(0)).authenticate(Mockito.anyString(), Mockito.anyString());
}
示例13: testBasicAuthentication
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
/**
* Test method for
* {@link org.jboss.dcp.api.rest.AuthenticationInterceptor#preProcess(org.jboss.resteasy.spi.HttpRequest, org.jboss.resteasy.core.ResourceMethod)}
* .
*/
@Test
public void testBasicAuthentication() {
AuthenticationInterceptor tested = getTested();
HttpRequest requestMock = getHttpRequestMock();
ResourceMethod methodMock = Mockito.mock(ResourceMethod.class);
String uname = "uname";
String pwd = "pwd";
List<String> value = new ArrayList<String>();
value.add("NTLM:sdfsdfkjskdfs");
value.add("Basic:" + Base64.encodeBytes(uname.getBytes()));
value.add("Basic:" + Base64.encodeBytes((uname + ":" + pwd).getBytes()));
value.add("PPP:sdfsdfkjskdfs");
Mockito.when(requestMock.getHttpHeaders().getRequestHeader("Authorization")).thenReturn(value);
Mockito.when(tested.providerService.authenticate(uname, pwd)).thenReturn(true);
ServerResponse res = tested.preProcess(requestMock, methodMock);
Assert.assertNull(res);
SecurityContext ctx = ResteasyProviderFactory.getContextData(SecurityContext.class);
Assert.assertEquals(uname, ctx.getUserPrincipal().getName());
Assert.assertEquals("BASIC", ctx.getAuthenticationScheme());
}
示例14: responseHeaderForOPTIONSTest
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void responseHeaderForOPTIONSTest() {
Class noparams[] = {};
Method aMethod = null;
try {
aMethod = CORSSupportInterceptorTest.class.getDeclaredMethod("methodOPTIONS", noparams);
} catch (NoSuchMethodException e) {
Assert.fail(e.getMessage());
}
ServerResponse response = new ServerResponse();
response.setResourceMethod(aMethod);
CORSSupportInterceptor.addHeaders(aMethod);
CORSSupportInterceptor tested = getTested();
tested.postProcess(response);
Assert.assertTrue(response.getMetadata().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN));
Assert.assertEquals("*", response.getMetadata().get(ACCESS_CONTROL_ALLOW_ORIGIN).get(0));
Assert.assertTrue(response.getMetadata().containsKey(ACCESS_CONTROL_MAX_AGE));
Assert.assertEquals("86400", response.getMetadata().get(ACCESS_CONTROL_MAX_AGE).get(0));
Assert.assertTrue(response.getMetadata().containsKey(ACCESS_CONTROL_ALLOW_METHODS));
Assert.assertEquals(CORSSupport.PUT, response.getMetadata().get(ACCESS_CONTROL_ALLOW_METHODS).get(0));
Assert.assertEquals(CORSSupport.POST, response.getMetadata().get(ACCESS_CONTROL_ALLOW_METHODS).get(1));
}
示例15: notAuthenticatedTest
import org.jboss.resteasy.core.ServerResponse; //导入依赖的package包/类
@Test
public void notAuthenticatedTest() {
SecurityPreProcessInterceptor tested = getTested();
Mockito.when(tested.securityContext.getUserPrincipal()).thenReturn(null);
ServerResponse res = tested.preProcess(null, null);
Assert.assertNotNull(res);
Assert.assertEquals(HttpResponseCodes.SC_UNAUTHORIZED, res.getStatus());
Assert.assertEquals("Basic realm=\"Insert Provider's username and password\"",
res.getMetadata().get("WWW-Authenticate").get(0));
}