use of org.apache.openejb.server.ServerRuntimeException in project tomee by apache.
the class MultipointServer method initiateConnections.
private void initiateConnections() {
synchronized (connect) {
final LinkedList<Host> unresolved = new LinkedList<Host>();
while (connect.size() > 0) {
final Host host = connect.removeFirst();
log.debug("Initiate(uri=" + host.getUri() + ")");
if (connections.containsKey(host.getUri()))
continue;
if (!host.isDone()) {
unresolved.add(host);
log.debug("Unresolved(uri=" + host.getUri() + ")");
continue;
}
final InetSocketAddress address;
try {
address = host.getSocketAddress();
} catch (ExecutionException e) {
final Throwable t = (e.getCause() != null) ? e.getCause() : e;
final String message = String.format("Failed Connect{uri=%s} %s{message=\"%s\"}", host.getUri(), t.getClass().getSimpleName(), t.getMessage());
log.warning(message);
continue;
} catch (TimeoutException e) {
unresolved.add(host);
log.debug("Unresolved(uri=" + host.getUri() + ")");
continue;
}
try {
final URI uri = host.getUri();
println("open " + uri);
// Create a non-blocking NIO channel
final SocketChannel socketChannel = SocketChannel.open();
socketChannel.configureBlocking(false);
socketChannel.connect(address);
final Session session = new Session(socketChannel, address, uri);
session.ops(SelectionKey.OP_CONNECT);
session.trace("client");
connections.put(session.uri, session);
// seen - needs to get maintained as "connected"
// TODO remove from seen
} catch (IOException e) {
throw new ServerRuntimeException(e);
}
}
connect.addAll(unresolved);
}
}
use of org.apache.openejb.server.ServerRuntimeException in project tomee by apache.
the class SeiFactoryImpl method initialize.
void initialize(Object serviceImpl, ClassLoader classLoader) throws ClassNotFoundException {
this.serviceImpl = serviceImpl;
Class serviceEndpointBaseClass = classLoader.loadClass(serviceEndpointClassName);
serviceEndpointClass = enhanceServiceEndpointInterface(serviceEndpointBaseClass, classLoader);
Class[] constructorTypes = new Class[] { classLoader.loadClass(GenericServiceEndpoint.class.getName()) };
this.constructor = FastClass.create(serviceEndpointClass).getConstructor(constructorTypes);
this.handlerInfoChainFactory = new HandlerInfoChainFactory(handlerInfos);
sortedOperationInfos = new OperationInfo[FastClass.create(serviceEndpointClass).getMaxIndex() + 1];
String encodingStyle = "";
for (int i = 0; i < operationInfos.length; i++) {
OperationInfo operationInfo = operationInfos[i];
Signature signature = operationInfo.getSignature();
MethodProxy methodProxy = MethodProxy.find(serviceEndpointClass, signature);
if (methodProxy == null) {
throw new ServerRuntimeException("No method proxy for operationInfo " + signature);
}
int index = methodProxy.getSuperIndex();
sortedOperationInfos[index] = operationInfo;
if (operationInfo.getOperationDesc().getUse() == Use.ENCODED) {
encodingStyle = org.apache.axis.Constants.URI_SOAP11_ENC;
}
}
//register our type descriptors
Service service = ((ServiceImpl) serviceImpl).getService();
AxisEngine axisEngine = service.getEngine();
TypeMappingRegistry typeMappingRegistry = axisEngine.getTypeMappingRegistry();
TypeMapping typeMapping = typeMappingRegistry.getOrMakeTypeMapping(encodingStyle);
typeMapping.register(BigInteger.class, Constants.XSD_UNSIGNEDLONG, new SimpleSerializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG), new SimpleDeserializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG));
typeMapping.register(URI.class, Constants.XSD_ANYURI, new SimpleSerializerFactory(URI.class, Constants.XSD_ANYURI), new SimpleDeserializerFactory(URI.class, Constants.XSD_ANYURI));
//It is essential that the types be registered before the typeInfos create the serializer/deserializers.
for (Iterator iter = typeInfo.iterator(); iter.hasNext(); ) {
TypeInfo info = (TypeInfo) iter.next();
TypeDesc.registerTypeDescForClass(info.getClazz(), info.buildTypeDesc());
}
TypeInfo.register(typeInfo, typeMapping);
}
use of org.apache.openejb.server.ServerRuntimeException in project tomee by apache.
the class ServiceEndpointMethodInterceptor method doIntercept.
private Object doIntercept(Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
int index = methodProxy.getSuperIndex();
OperationInfo operationInfo = operations[index];
if (operationInfo == null) {
throw new ServerRuntimeException("Operation not mapped: " + method.getName() + " index: " + index + "\n OperationInfos: " + Arrays.asList(operations));
}
stub.checkCachedEndpoint();
Call call = stub.createCall();
operationInfo.prepareCall(call);
stub.setUpCall(call);
if (credentialsName != null) {
throw new UnsupportedOperationException("Client side auth is not implementd");
// Subject subject = ContextManager.getNextCaller();
// if (subject == null) {
// throw new IllegalStateException("Subject missing but authentication turned on");
// } else {
// Set creds = subject.getPrivateCredentials(NamedUsernamePasswordCredential.class);
// boolean found = false;
// for (Iterator iterator = creds.iterator(); iterator.hasNext();) {
// NamedUsernamePasswordCredential namedUsernamePasswordCredential = (NamedUsernamePasswordCredential) iterator.next();
// if (credentialsName.equals(namedUsernamePasswordCredential.getName())) {
// call.setUsername(namedUsernamePasswordCredential.getUsername());
// call.setPassword(new String(namedUsernamePasswordCredential.getPassword()));
// found = true;
// break;
// }
// }
// if (!found) {
// throw new IllegalStateException("no NamedUsernamePasswordCredential found for name " + credentialsName);
// }
// }
}
Object response = null;
List parameterDescs = operationInfo.getOperationDesc().getParameters();
Object[] unwrapped = extractFromHolders(objects, parameterDescs, operationInfo.getOperationDesc().getNumInParams());
if (operationInfo.getOperationDesc().getMep() == OperationType.REQUEST_RESPONSE) {
try {
response = call.invoke(unwrapped);
} catch (RemoteException e) {
throw operationInfo.unwrapFault(e);
}
if (response instanceof RemoteException) {
throw operationInfo.unwrapFault((RemoteException) response);
} else {
stub.extractAttachments(call);
Map outputParameters = call.getOutputParams();
putInHolders(outputParameters, objects, parameterDescs);
Class returnType = operationInfo.getOperationDesc().getReturnClass();
//return type should never be null... but we are not objecting if wsdl-return-value-mapping is not set.
if (response == null || returnType == null || returnType.isAssignableFrom(response.getClass())) {
return response;
} else {
return JavaUtils.convert(response, returnType);
}
}
} else if (operationInfo.getOperationDesc().getMep() == OperationType.ONE_WAY) {
//one way
call.invokeOneWay(unwrapped);
return null;
} else {
throw new ServerRuntimeException("Invalid messaging style: " + operationInfo.getOperationDesc().getMep());
}
}
use of org.apache.openejb.server.ServerRuntimeException in project tomee by apache.
the class AxisWsContainer method doService.
protected void doService(final HttpRequest req, final HttpResponse res) throws Exception {
final org.apache.axis.MessageContext messageContext = new org.apache.axis.MessageContext(null);
req.setAttribute(WsConstants.MESSAGE_CONTEXT, messageContext);
messageContext.setClassLoader(classLoader);
Message responseMessage;
String contentType = req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
final String contentLocation = req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION);
final InputStream inputStream = req.getInputStream();
final Message requestMessage = new Message(inputStream, false, contentType, contentLocation);
messageContext.setRequestMessage(requestMessage);
messageContext.setProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO, req.getURI().getPath());
messageContext.setProperty(org.apache.axis.MessageContext.TRANS_URL, req.getURI().toString());
messageContext.setService(service);
messageContext.setProperty(REQUEST, req);
messageContext.setProperty(RESPONSE, res);
messageContext.setProperty(AxisEngine.PROP_DISABLE_PRETTY_XML, Boolean.TRUE);
final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
try {
final String characterEncoding = (String) requestMessage.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
if (characterEncoding != null) {
messageContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, characterEncoding);
} else {
messageContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
}
final String soapAction = req.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
if (soapAction != null) {
messageContext.setUseSOAPAction(true);
messageContext.setSOAPActionURI(soapAction);
}
final SOAPEnvelope env = requestMessage.getSOAPEnvelope();
if (env != null && env.getSOAPConstants() != null) {
messageContext.setSOAPConstants(env.getSOAPConstants());
}
final SOAPService service = messageContext.getService();
Thread.currentThread().setContextClassLoader(classLoader);
service.invoke(messageContext);
responseMessage = messageContext.getResponseMessage();
} catch (final AxisFault fault) {
if (req.getMethod().equals(HttpRequest.Method.GET.name()) && req.getParameters().isEmpty()) {
String serviceName = req.getURI().getRawPath();
serviceName = serviceName.substring(serviceName.lastIndexOf("/") + 1);
printServiceInfo(res, serviceName);
return;
} else {
responseMessage = handleFault(fault, res, messageContext);
}
} catch (final Exception e) {
responseMessage = handleException(messageContext, res, e);
}
//TODO investigate and fix operation == null!
if (messageContext.getOperation() != null) {
if (messageContext.getOperation().getMep() == OperationType.ONE_WAY) {
// No content, so just indicate accepted
res.setStatus(HttpServletResponse.SC_ACCEPTED);
return;
} else if (responseMessage == null) {
responseMessage = handleException(messageContext, null, new ServerRuntimeException("No response for non-one-way operation"));
}
} else if (responseMessage == null) {
res.setStatus(HttpServletResponse.SC_ACCEPTED);
return;
}
try {
final SOAPConstants soapConstants = messageContext.getSOAPConstants();
final String contentType1 = responseMessage.getContentType(soapConstants);
res.setContentType(contentType1);
// Transfer MIME headers to HTTP headers for response message.
final MimeHeaders responseMimeHeaders = responseMessage.getMimeHeaders();
for (final Iterator i = responseMimeHeaders.getAllHeaders(); i.hasNext(); ) {
final MimeHeader responseMimeHeader = (MimeHeader) i.next();
res.setHeader(responseMimeHeader.getName(), responseMimeHeader.getValue());
}
//TODO discuss this with dims.
// // synchronize the character encoding of request and response
// String responseEncoding = (String) messageContext.getProperty(
// SOAPMessage.CHARACTER_SET_ENCODING);
// if (responseEncoding != null) {
// try {
// responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
// responseEncoding);
// } catch (SOAPException e) {
// log.info(Messages.getMessage("exception00"), e);
// }
// }
//determine content type from message response
contentType = responseMessage.getContentType(messageContext.getSOAPConstants());
responseMessage.writeTo(res.getOutputStream());
} catch (final Exception e) {
logger.warning(Messages.getMessage("exception00"), e);
}
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
use of org.apache.openejb.server.ServerRuntimeException in project tomee by apache.
the class EjbInterceptor method intercept.
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
Endpoint endpoint = this.exchange.get(Endpoint.class);
Service service = endpoint.getService();
Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();
this.exchange.put(InvocationContext.class, context);
if (binding.getHandlerChain() == null || binding.getHandlerChain().isEmpty()) {
// no handlers so let's just directly invoke the bean
log.debug("No handlers found.");
EjbMethodInvoker invoker = (EjbMethodInvoker) service.getInvoker();
return invoker.directEjbInvoke(this.exchange, this.method, this.params);
} else {
// have handlers so have to run handlers now and redo data binding
// as handlers can change the soap message
log.debug("Handlers found.");
Message inMessage = exchange.getInMessage();
PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());
chain.setFaultObserver(endpoint.getOutFaultObserver());
/*
* Since we have to re-do data binding and the XMLStreamReader
* contents are already consumed by prior data binding step
* we have to reinitialize the XMLStreamReader from the SOAPMessage
* created by SAAJInInterceptor.
*/
if (inMessage instanceof SoapMessage) {
try {
reserialize((SoapMessage) inMessage);
} catch (Exception e) {
throw new ServerRuntimeException("Failed to reserialize soap message", e);
}
} else {
// TODO: how to handle XML/HTTP binding?
}
this.exchange.setOutMessage(null);
// install default interceptors
chain.add(new ServiceInvokerInterceptor());
//chain.add(new OutgoingChainInterceptor()); // it is already in the enclosing chain, if we add it there we are in the tx so we write the message in the tx!
// See http://cwiki.apache.org/CXF20DOC/interceptors.html
// install Holder and Wrapper interceptors
chain.add(new WrapperClassInInterceptor());
chain.add(new HolderInInterceptor());
// install interceptors for handler processing
chain.add(new MustUnderstandInterceptor());
chain.add(new LogicalHandlerInInterceptor(binding));
chain.add(new SOAPHandlerInterceptor(binding));
// install data binding interceptors - todo: check we need it
copyDataBindingInterceptors(chain, inMessage.getInterceptorChain());
InterceptorChain oldChain = inMessage.getInterceptorChain();
inMessage.setInterceptorChain(chain);
try {
chain.doIntercept(inMessage);
} finally {
inMessage.setInterceptorChain(oldChain);
}
// TODO: the result should be deserialized from SOAPMessage
Object result = getResult();
return result;
}
}
Aggregations