Package org.jibx.ws.server

Examples of org.jibx.ws.server.Service


     * @exception ServletException on message content or operational error
     * @exception IOException on error reading or writing
     */
    public void doPost(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
        logger.debug("Entered WsServletDelegate.doPost()");
        Service serv = null;
        XmlCodec incodec = null;
        XmlCodec outcodec = null;
        InByteBuffer inbuff = null;
        OutByteBuffer outbuff = null;
        try {
            // make sure we have a service instance
            serv = m_serviceMapper.getServiceInstance(req);
            if (serv == null) {
                rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
            } else {
                MediaType intype = getMediaType(req.getContentType(), serv.getMediaTypeMapper());
                MediaType outtype = getAcceptableMediaType(req.getHeader("Accept"), intype);

                synchronized (s_codecPool) {
                    // allocated codec(s) and buffers for the input and output
                    incodec = s_codecPool.getCodec(intype);
                    if (intype.equals(outtype)) {
                        outcodec = incodec;
                    } else {
                        outcodec = s_codecPool.getCodec(outtype);
                    }
                    inbuff = (InByteBuffer) s_inBufferCache.getInstance();
                    outbuff = (OutByteBuffer) s_outBufferCache.getInstance();
                }

                // pass the processing on to the service
                InboundConnection inconn = new InboundConnection(req, incodec, inbuff);
                OutboundConnection outconn = new OutboundConnection(rsp, req.getCharacterEncoding(),
                    serv.getXmlOptions(), outcodec, outbuff);
                HttpServletOptions options = (HttpServletOptions) serv.getTransportOptions(HttpServletOptions.class);
                if (options != null) {
                    if (options.getInputStreamInterceptor() != null) {
                        inconn.setInterceptor(options.getInputStreamInterceptor());
                    }
                    if (options.getOutputStreamInterceptor() != null) {
                        outconn.setInterceptor(options.getOutputStreamInterceptor());
                    }
                }
                serv.processRequest(inconn, outconn);
            }

        } catch (WsException e) {
            logger.error("Error processing request", e);
            rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
        } finally {
            synchronized (s_codecPool) {

                // release all resources acquired for processing request
                if (serv != null) {
                    serv.releaseInstance();
                }
                if (incodec != null) {
                    s_codecPool.releaseCodec(incodec);
                }
                if (outcodec != null && outcodec != incodec) {
View Full Code Here


            logger.debug("Entered WsServletDelegate.doGet() with query string: " + req.getQueryString());
        }
       
        // look up service information and check request
        if ("wsdl".equalsIgnoreCase(req.getQueryString())) {
            Service service = null;
            try {
                logger.debug("Looking up service for WSDL");
                service = m_serviceMapper.getServiceInstance(req);
                if (service == null) {
                    logger.debug("Unable to find service for WSDL");
                    rsp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
                } else {
                    WsdlProvider wsdlProvider = service.getWsdlProvider();
                    if (wsdlProvider == null) {
                        logger.debug("Unable to WSDL provider for service");
                        rsp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
                    } else {
                        logger.debug("Returning WSDL");
                        wsdlProvider.writeWSDL(rsp.getOutputStream(), req);
                    }
                }
            } catch (WsException e) {
                logger.error("Error creating WSDL", e);
                throw new ServletException(e.getMessage(), e);
            } finally {
                // release all resources acquired for processing request
                if (service != null) {
                    service.releaseInstance();
                }
            }
        } else {
            rsp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        }
View Full Code Here

     * socket is closed or the exit flag is set.
     */
    public void run() {
        try {
            while (!m_exit && m_dimeInput.nextMessage() && m_dimeInput.nextPart()) {
                Service serv = null;
                try {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Beginning processing of receive message from " + m_clientAddress);
                    }
                    MediaType mediaType = null;
                    if (m_dimeInput.getPartTypeCode() == DimeCommon.TYPE_MEDIA) {
                        String partTypeText = m_dimeInput.getPartTypeText();
                        try {
                            MediaType partMediaType = new MediaType(partTypeText);
                            if (CodecDirectory.hasCodecFor(partMediaType)) {
                                mediaType = partMediaType;
                            }
                        } catch (ParseException e) {
                            throw new IOException("Unable to parse media type '" + partTypeText + "'");
                        }
                    }
                    if (mediaType == null) {
                        mediaType = CodecDirectory.TEXT_XML_MEDIA_TYPE;
                    }
                    XmlCodec codec = m_codecCache.getCodec(mediaType);
                    IXMLReader reader = codec.getReader(m_dimeInput, null, m_clientAddress, false);
                    Protocol protocol = ProtocolDirectory.getProtocol(m_sdef.getProtocolName());
                    ServiceFactory serviceFactory = protocol.getServiceFactory();
                    serv = ServicePool.getInstance(serviceFactory, m_sdef);
                    serv.processRequest(new TcpInConnection(m_dimeInput, reader), new TcpOutConnection(codec,
                        serv.getXmlOptions()));
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Completed processing of receive message from " + m_clientAddress);
                    }
                } finally {
                    if (serv != null) {
                        serv.releaseInstance();
                    }
                }
            }
        } catch (Exception e) {
           
View Full Code Here

     *
     * @throws Exception e
     */
    public void testProcessRequestReadsSoapHeader() throws Exception {
        m_inbound.setInBytes(TestHeaderObjects.REQUEST_SOAP.getBytes());
        Service service = SoapServiceTestHelper.createSoapServiceWithHandler("findCustomer", "org.jibx.ws.test.locale",
            LocaleUnmarshaller.class);
        service.processRequest(m_inbound, m_outbound);

        assertEquals(false, m_outbound.isNotFoundError());
        // assertEquals(false, m_outbound.isInternalServerError());

        // Check the header
View Full Code Here

     *
     * @throws Exception e
     */
    public void testProcessRequestIgnoresEmptySoapHeader() throws Exception {
        m_inbound.setInBytes(SoapMaker.envelope("<SOAP:Header/>", TestObjects.REQUEST_SOAP_BODY).getBytes());
        Service service = SoapServiceTestHelper.createSoapService("findCustomer");
        service.processRequest(m_inbound, m_outbound);

        assertEquals(false, m_outbound.isNotFoundError());
        // assertEquals(false, m_outbound.isInternalServerError());

        // Check the body
View Full Code Here

     * @throws Exception e
     */
    public void testProcessRequestIgnoresEmptySoapHeader2() throws Exception {
        m_inbound.setInBytes(SoapMaker.envelope("<SOAP:Header></SOAP:Header>", TestObjects.REQUEST_SOAP_BODY)
            .getBytes());
        Service service = SoapServiceTestHelper.createSoapService("findCustomer");
        service.processRequest(m_inbound, m_outbound);

        assertEquals(false, m_outbound.isNotFoundError());
        // assertEquals(false, m_outbound.isInternalServerError());

        // Check the body
View Full Code Here

     *
     * @throws Exception e
     */
    public void testProcessRequestCreatesFaultIfHeaderNotUnderstood() throws Exception {
        m_inbound.setInBytes(TestHeaderObjects.REQUEST_SOAP_MUST_UNDERSTAND.getBytes());
        Service service = SoapServiceTestHelper.createSoapService("findCustomer");
        service.processRequest(m_inbound, m_outbound);

        assertEquals(false, m_outbound.isNotFoundError());
        assertEquals(true, m_outbound.isInternalServerError());

        String responseXML = new String(m_outbound.getOutBytes());
View Full Code Here

     */
    public void testProcessRequestWritesSoapHeader() throws Exception {
        m_inbound.setInBytes(TestObjects.REQUEST_SOAP.getBytes());
        // Set the header
        LocaleMarshaller.setLocale(TestHeaderObjects.EN_US);
        Service service = SoapServiceTestHelper.createSoapServiceWithHandler("findCustomer", "org.jibx.ws.test.locale",
            LocaleMarshaller.class);
        service.processRequest(m_inbound, m_outbound);

        assertEquals(false, m_outbound.isNotFoundError());
        assertEquals(false, m_outbound.isInternalServerError());

        // Check the response includes the header
View Full Code Here

     * <code>SoapService</code>.
     *
     * @throws Exception e
     */
    public void testGetInstanceReturnsSoapService() throws Exception {
        Service service = SoapServiceTestHelper.createSoapService("findCustomer");

        assertNotNull(service);
    }
View Full Code Here

     * returns a valid m_response when the service completes successfully.
     *
     * @throws Exception e
     */
    public void testProcessRequestReturnsValidResponseWhenServiceSuccessful() throws Exception {
        Service service = SoapServiceTestHelper.createSoapService("findCustomer");

        service.processRequest(m_inbound, m_outbound);

        String responseXML = new String(m_outbound.getOutBytes());
        XMLAssert.assertXMLEqual(TestObjects.RESPONSE_SOAP, responseXML);
    }
View Full Code Here

TOP

Related Classes of org.jibx.ws.server.Service

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.