use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testQueryParametersIntegerArray.
@Test
public void testQueryParametersIntegerArray() throws Exception {
Class<?>[] argType = { Integer[].class };
Method m = Customer.class.getMethod("testQueryIntegerArray", argType);
Message messageImpl = createMessage();
messageImpl.put(Message.QUERY_STRING, "query=1&query=2");
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals(1, params.size());
Integer[] intValues = (Integer[]) params.get(0);
assertEquals(2, intValues.length);
assertEquals(1, (int) intValues[0]);
assertEquals(2, (int) intValues[1]);
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testQueryParameterDefaultValue.
@Test
public void testQueryParameterDefaultValue() throws Exception {
Message messageImpl = createMessage();
ProviderFactory.getInstance(messageImpl).registerUserProvider(new GenericObjectParameterHandler());
Class<?>[] argType = { String.class, String.class };
Method m = Customer.class.getMethod("testGenericObjectParamDefaultValue", argType);
messageImpl.put(Message.QUERY_STRING, "p1=thequery&p2");
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals(2, params.size());
String query = (String) params.get(0);
assertEquals("thequery", query);
query = (String) params.get(1);
assertEquals("thequery", query);
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testCookieParameters.
@Test
public void testCookieParameters() throws Exception {
Class<?>[] argType = { String.class, Set.class, String.class, Set.class };
Method m = Customer.class.getMethod("testCookieParam", argType);
Message messageImpl = createMessage();
MultivaluedMap<String, String> headers = new MetadataMap<>();
headers.add("Cookie", "c1=c1Value");
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals(4, params.size());
assertEquals("c1Value", params.get(0));
Set<Cookie> set1 = CastUtils.cast((Set<?>) params.get(1));
assertEquals(1, set1.size());
assertTrue(set1.contains(Cookie.valueOf("c1=c1Value")));
assertEquals("c2Value", params.get(2));
Set<Cookie> set2 = CastUtils.cast((Set<?>) params.get(3));
assertTrue(set2.contains((Object) "c2Value"));
assertEquals(1, set2.size());
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSOutInterceptor method processResponse.
// Response shouldn't be closed here
@SuppressWarnings("resource")
private void processResponse(ServerProviderFactory providerFactory, Message message) {
if (isResponseAlreadyHandled(message)) {
return;
}
MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs == null || objs.isEmpty()) {
return;
}
Object responseObj = objs.get(0);
final Response response;
if (responseObj instanceof Response) {
response = (Response) responseObj;
if (response.getStatus() == 500 && message.getExchange().get(JAXRSUtils.EXCEPTION_FROM_MAPPER) != null) {
message.put(Message.RESPONSE_CODE, 500);
return;
}
} else {
int status = getStatus(message, responseObj != null ? 200 : 204);
response = JAXRSUtils.toResponseBuilder(status).entity(responseObj).build();
}
Exchange exchange = message.getExchange();
OperationResourceInfo ori = (OperationResourceInfo) exchange.get(OperationResourceInfo.class.getName());
serializeMessage(providerFactory, message, response, ori, true);
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class UriInfoImpl method getMatchedURIs.
public List<String> getMatchedURIs(boolean decode) {
if (stack != null) {
List<String> objects = new ArrayList<>();
List<String> uris = new LinkedList<>();
StringBuilder sumPath = new StringBuilder("");
for (MethodInvocationInfo invocation : stack) {
List<String> templateObjects = invocation.getTemplateValues();
OperationResourceInfo ori = invocation.getMethodInfo();
URITemplate[] paths = { ori.getClassResourceInfo().getURITemplate(), ori.getURITemplate() };
if (paths[0] != null) {
int count = paths[0].getVariables().size();
List<String> rootObjects = new ArrayList<>(count);
for (int i = 0; i < count && i < templateObjects.size(); i++) {
rootObjects.add(templateObjects.get(i));
}
uris.add(0, createMatchedPath(paths[0].getValue(), rootObjects, decode));
}
if (paths[1] != null && paths[1].getValue().length() > 1) {
for (URITemplate t : paths) {
if (t != null) {
sumPath.append('/').append(t.getValue());
}
}
objects.addAll(templateObjects);
uris.add(0, createMatchedPath(sumPath.toString(), objects, decode));
}
}
return uris;
}
LOG.fine("No resource stack information, returning empty list");
return Collections.emptyList();
}
Aggregations