private Object handleFault(Message ret) throws InvocationTargetException { if (ret.getBody() instanceof ServiceRuntimeException) { ServiceRuntimeException e = (ServiceRuntimeException) ret.getBody(); if (e.getCause() instanceof NotAuthorizedException) { // authorization exceptions need to be mapped to a client 403 response throw new InvocationTargetException(new WebApplicationException(Response.Status.FORBIDDEN)); } throw new InvocationTargetException(e); } throw new InvocationTargetException((Throwable) ret.getBody()); }
public Message invoke(Message message) { Object[] args = (Object[]) message.getBody(); ClassLoader old = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Object body = response.build(args); message.reset(); message.setBody(body); } catch (RuntimeException e) { throw new ServiceRuntimeException(e); } finally { Thread.currentThread().setContextClassLoader(old); } return message; }
public Message invoke(Message msg) { byte[] body = (byte[]) msg.getBody(); WorkContext workContext = msg.getWorkContext(); sender.send(body, index, workContext); return ONE_WAY_RESPONSE; }
public Message invoke(Message msg) { Message ret = next.invoke(msg); if (ret.isFault() && expected.equals(ret.getBody().getClass())) { ret.setBody(null); } return ret; }
public Message invoke(Message msg) { msg.setBody(new Object[]{msg.getBody()}); return next.invoke(msg); }
public Message invoke(Message msg) { Object body = msg.getBody(); if (body == null || !body.getClass().isArray()) { return next.invoke(msg); } Object[] payload = (Object[]) body; if (payload.length != 1) { throw new ServiceRuntimeException("Unexpected payload size: " + payload.length); } msg.setBody(payload[0]); return next.invoke(msg); }
public Message invoke(final Message msg) { WorkContext workContext = msg.getWorkContext(); List<CallbackReference> newStack = null; List<CallbackReference> stack = workContext.getCallbackReferences(); if (stack != null && !stack.isEmpty()) { // clone the callstack to avoid multiple threads seeing changes newStack = new ArrayList<CallbackReference>(stack); } Map<String, Object> newHeaders = null; Map<String, Object> headers = workContext.getHeaders(); if (headers != null && !headers.isEmpty()) { // clone the headers to avoid multiple threads seeing changes newHeaders = new HashMap<String, Object>(headers); } SecuritySubject subject = workContext.getSubject(); Object payload = msg.getBody(); AsyncRequest request = new AsyncRequest(next, payload, subject, newStack, newHeaders, monitor); executorService.execute(request); return RESPONSE; }
public Message invoke(Message msg) { byte[] body = (byte[]) msg.getBody(); WorkContext workContext = msg.getWorkContext(); byte[] value = sender.sendAndReply(body, index, workContext); msg.setBody(value); return msg; }
Object body = msg.getBody(); ClassLoader old = Thread.currentThread().getContextClassLoader(); try {
private void transformInput(Message msg) { Object params = msg.getBody(); // TODO handle null types if (params != null) { try { // Operations take 0..n parameters. A single parameter must be unwrapped from the invocation array and passed to a transformer. // In contrast, multiple parameter operations are passed as an array to the transformer. if (params.getClass().isArray() && ((Object[]) params).length == 1) { Object[] paramArray = (Object[]) params; paramArray[0] = inTransformer.transform(paramArray[0], inLoader); } else { // multiple parameters - pass the entire array to transform Object transformed = inTransformer.transform(params, inLoader); msg.setBody(transformed); } } catch (TransformationException e) { throw new ServiceRuntimeException(e); } } }
private Message interceptService(Message message) { Object[] payload = (Object[]) message.getBody(); if (payload != null && payload.length > 0) { OMElement omElement = (OMElement) payload[0]; Object jaxbObject = inTransformer.transform(omElement, null); message.setBody(new Object[]{jaxbObject}); } Message response = next.invoke(message); Object result; if (response.isFault()) { Object webFault = response.getBody(); result = getFault(webFault); } else { result = response.getBody(); } if (result != null) { OMElement omElement = outTransformer.transform(result, null); response.setBody(omElement); } return response; }
/** * Performs the invocation on the target component instance. If a target classloader is configured for the interceptor, it will be set as the TCCL. * * @param msg the messaging containing the invocation data * @param instance the target component instance * @return the response message */ private Message invoke(Message msg, Object instance) { try { Object body = msg.getBody(); if (targetTCCLClassLoader == null) { msg.setBody(invoker.invoke(instance, body)); } else { ClassLoader old = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(targetTCCLClassLoader); msg.setBody(invoker.invoke(instance, body)); } finally { Thread.currentThread().setContextClassLoader(old); } } } catch (InvocationTargetException e) { msg.setBodyWithFault(e.getCause()); } catch (IllegalAccessException e) { throw new InvocationRuntimeException(e); } return msg; }
public void run() { Message request = MessageCache.getAndResetMessage(); try { request.setBody(frames[0]); int methodIndex = ByteBuffer.wrap(frames[1]).getInt(); WorkContext context = setWorkContext(frames[2]); request.setWorkContext(context); Interceptor interceptor = interceptors[methodIndex]; // invoke the service Message response = interceptor.invoke(request); Object responseBody = response.getBody(); if (!(responseBody instanceof byte[])) { throw new ServiceRuntimeException("Return value not serialized"); } // queue the response try { queue.put(new Response(clientId, (byte[]) responseBody)); } catch (InterruptedException e) { Thread.interrupted(); } } finally { request.reset(); // context.reset(); } } });
Object element = ret.getBody(); if (element instanceof AxisFault) { throw (AxisFault) element;
public Object invoke(Method method, Object[] args) throws Throwable { InvocationChain invocationChain = chains.get(method.getName()); if (invocationChain == null) { throw new ServiceRuntimeException("Unknown resource method: " + method.toString()); } WorkContext context = WorkContextCache.getThreadWorkContext(); // work context set previously in RsContainer Message message = MessageCache.getAndResetMessage(); try { if (authenticate) { authenticate(context); } message.setWorkContext(context); message.setBody(args); if (invocationChain != null) { Interceptor headInterceptor = invocationChain.getHeadInterceptor(); Message ret = headInterceptor.invoke(message); if (ret.isFault()) { return handleFault(ret); } else { return ret.getBody(); } } else { return null; } } catch (RuntimeException e) { throw new InvocationTargetException(e); } finally { message.reset(); } }
private Message transformOutput(Message ret) { // FIXME For exception transformation, if it is checked convert as application fault Object body = ret.getBody(); // TODO handle null types if (body != null) { try { Object transformed = outTransformer.transform(body, outLoader); if (ret.isFault()) { ret.setBodyWithFault(transformed); } else { ret.setBody(transformed); } } catch (ClassCastException e) { // an unexpected type was returned by the target service or an interceptor later in the chain. This is an error in the extension or // interceptor and not user code since errors should be trapped and returned in the format expected by the transformer if (body instanceof Throwable) { throw new ServiceRuntimeException("Unexpected exception returned", (Throwable) body); } else { throw new ServiceRuntimeException("Unexpected type returned: " + body.getClass()); } } catch (TransformationException e) { throw new ServiceRuntimeException(e); } } return ret; }
public void run() { WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); workContext.addCallbackReferences(stack); workContext.addHeaders(headers); workContext.setSubject(subject); Message message = MessageCache.getAndResetMessage(); message.setBody(payload); message.setWorkContext(workContext); Message response = next.invoke(message); if (response.isFault()) { // log the exception monitor.onError((Throwable) response.getBody()); } message.reset(); workContext.reset(); }
public boolean onUpload(String fileName, String contentType, InputStream uploadData) throws Exception { Object[] args = new Object[]{fileName, uploadData}; WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext(); Message input = MessageCache.getAndResetMessage(); try { // set the header value for the request context workContext.setHeader(FtpConstants.HEADER_CONTENT_TYPE, contentType); input.setWorkContext(workContext); input.setBody(args); Message response = getInterceptor().invoke(input); if (response.isFault()) { monitor.fileProcessingError(servicePath, (Throwable) response.getBody()); input.reset(); return false; } return true; } finally { input.reset(); workContext.reset(); } }