Search in sources :

Example 1 with ServerRuntimeException

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);
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) URI(java.net.URI) LinkedList(java.util.LinkedList) ExecutionException(java.util.concurrent.ExecutionException) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ServerRuntimeException

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);
}
Also used : SimpleSerializerFactory(org.apache.axis.encoding.ser.SimpleSerializerFactory) HandlerInfoChainFactory(org.apache.axis.handlers.HandlerInfoChainFactory) Service(org.apache.axis.client.Service) URI(java.net.URI) SimpleDeserializerFactory(org.apache.axis.encoding.ser.SimpleDeserializerFactory) Signature(net.sf.cglib.core.Signature) MethodProxy(net.sf.cglib.proxy.MethodProxy) Iterator(java.util.Iterator) TypeMappingRegistry(org.apache.axis.encoding.TypeMappingRegistry) TypeMapping(org.apache.axis.encoding.TypeMapping) BigInteger(java.math.BigInteger) FastClass(net.sf.cglib.reflect.FastClass) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) AxisEngine(org.apache.axis.AxisEngine)

Example 3 with ServerRuntimeException

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());
    }
}
Also used : Call(org.apache.axis.client.Call) List(java.util.List) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) RemoteException(java.rmi.RemoteException) Map(java.util.Map)

Example 4 with ServerRuntimeException

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);
    }
}
Also used : SOAPService(org.apache.axis.handlers.soap.SOAPService) AxisFault(org.apache.axis.AxisFault) Message(org.apache.axis.Message) SOAPMessage(javax.xml.soap.SOAPMessage) InputStream(java.io.InputStream) SOAPEnvelope(org.apache.axis.message.SOAPEnvelope) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) IOException(java.io.IOException) MimeHeaders(javax.xml.soap.MimeHeaders) MimeHeader(javax.xml.soap.MimeHeader) Iterator(java.util.Iterator) MessageContext(org.apache.axis.MessageContext) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) SOAPConstants(org.apache.axis.soap.SOAPConstants) MessageContext(org.apache.axis.MessageContext)

Example 5 with ServerRuntimeException

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;
    }
}
Also used : Binding(javax.xml.ws.Binding) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) HolderInInterceptor(org.apache.cxf.jaxws.interceptors.HolderInInterceptor) SOAPHandlerInterceptor(org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) Service(org.apache.cxf.service.Service) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Endpoint(org.apache.cxf.endpoint.Endpoint) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) LogicalHandlerInInterceptor(org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor) ServiceInvokerInterceptor(org.apache.cxf.interceptor.ServiceInvokerInterceptor) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) WrapperClassInInterceptor(org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

ServerRuntimeException (org.apache.openejb.server.ServerRuntimeException)5 IOException (java.io.IOException)2 URI (java.net.URI)2 Iterator (java.util.Iterator)2 SOAPMessage (javax.xml.soap.SOAPMessage)2 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 RemoteException (java.rmi.RemoteException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AroundInvoke (javax.interceptor.AroundInvoke)1 MimeHeader (javax.xml.soap.MimeHeader)1 MimeHeaders (javax.xml.soap.MimeHeaders)1 Binding (javax.xml.ws.Binding)1