Package org.apache.axis

Examples of org.apache.axis.AxisEngine


            servletLog.debug("exit: doPost() after processing atompub request");
            return;
        }

        try {
            AxisEngine engine = getEngine();

            if (engine == null) {
                // !!! should return a SOAP fault...
                ServletException se =
                    new ServletException(Messages.getMessage("noEngine00"));
                servletLog.debug("No Engine!", se);
                throw se;
            }

            res.setBufferSize(1024 * 8); // provide performance boost.

            /** get message context w/ various properties set
             */
            msgContext = createMessageContext(engine, req, res);

            // ? OK to move this to 'getMessageContext',
            // ? where it would also be picked up for 'doGet()' ?
            if (securityProvider != null) {
                if (isDebug) servletLog.debug("securityProvider:" + securityProvider);
                msgContext.setProperty(MessageContext.SECURITY_PROVIDER, securityProvider);
            }

            /* Get request message
             */
            Message requestMsg =
                new Message(req.getInputStream(),
                            false,
                            req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE),
                            req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION));

            if(isDebug) servletLog.debug("Request Message:" + requestMsg);

            /* Set the request(incoming) message field in the context */
            /**********************************************************/
            msgContext.setRequestMessage(requestMsg);
            //String url = HttpUtils.getRequestURL(req).toString();
            String url = req.getRequestURL().toString();
            msgContext.setProperty(MessageContext.TRANS_URL, url);

            try {
                /**
                 * Save the SOAPAction header in the MessageContext bag.
                 * This will be used to tell the Axis Engine which service
                 * is being invoked.  This will save us the trouble of
                 * having to parse the Request message - although we will
                 * need to double-check later on that the SOAPAction header
                 * does in fact match the URI in the body.
                 */
                // (is this last stmt true??? (I don't think so - Glen))
                /********************************************************/
                soapAction = getSoapAction(req);

                if (soapAction != null) {
                    msgContext.setUseSOAPAction(true);
                    msgContext.setSOAPActionURI(soapAction);
                }
                else { // not a SOAP request
                    String content=new String(((SOAPPart)(requestMsg.getSOAPPart())).getAsBytes());
                    if(content.startsWith("<")) { // must be an ATOM request
                        return;
                    }
                    if(content.indexOf("query=")>=0 || content.indexOf("scanClause=")>=0) {
                        processMethodRequest(msgContext, new LateContentParsingHttpServletRequestWrapper(req, content), res);
                        return;
                    }
                   
                    // nothing I recognize
                    AxisFault af = new AxisFault("Client.NoSOAPAction",
                                                 Messages.getMessage("noHeader00",
                                                                      "SOAPAction"),
                                                 null, null);

                    exceptionLog.error(Messages.getMessage("genFault00"), af);

                    throw af;
                }

                // Create a Session wrapper for the HTTP session.
                // These can/should be pooled at some point.
                // (Sam is Watching! :-)
                msgContext.setSession(new AxisHttpSession(req));

                if( tlog.isDebugEnabled() ) {
                    t1=System.currentTimeMillis();
                }

                srwInfo.setSRWStuff(req, res, msgContext);
               
                /* Invoke the Axis engine... */
                /*****************************/
                if(isDebug) servletLog.debug("Invoking Axis Engine.");
                //here we run the message by the engine
                engine.invoke(msgContext);
                if(isDebug) servletLog.debug("Return from Axis Engine.");
                if( tlog.isDebugEnabled() ) {
                    t2=System.currentTimeMillis();
                }
                responseMsg = msgContext.getResponseMessage();
View Full Code Here


            if(servletLog.isDebugEnabled()) {
                servletLog.debug("request="+sb.toString());
                servletLog.debug(Utilities.byteArrayToString(sb.toString().getBytes("UTF-8")));
            }
            msgContext.setProperty("sru", "");
            AxisEngine engine=getEngine();
            ByteArrayInputStream bais=new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
            Message msg=new Message(bais, false);
            msgContext.setRequestMessage(msg);
            msgContext.setTargetService("SRW");
            try {
                engine.invoke(msgContext);
            }
            catch(Exception e) {
                servletLog.error(sb.toString());
                servletLog.error(e, e);
            }

            Message respMsg=msgContext.getResponseMessage();
            if(respMsg!=null) {
                javax.servlet.ServletOutputStream sos = null;
                // code to strip SOAP stuff out.  Hope this can go away some day
                String soapResponse=respMsg.getSOAPPartAsString();
                if("APP".equals(req.getAttribute("service"))||"APP".equals(req.getParameter("service"))) {
                    int start=soapResponse.indexOf("<recordData");
                    if(start>=0) {
                        String contentType=(String)req.getAttribute("ContentType");
                        if(contentType!=null)
                            resp.setContentType(contentType);
                        else
                            resp.setContentType("text/xml");
                        start=soapResponse.indexOf('>', start+1);
                        int stop=soapResponse.indexOf("</recordData>", start);
                        soapResponse=cleanup(soapResponse.substring(start+1, stop)
                            .toCharArray());
                        if(contentType!=null && contentType.toLowerCase().indexOf("html")>0) {
                            soapResponse=srwInfo.getXmlHeaders(req, db.searchStyleSheet)+Utilities.unXmlEncode(soapResponse);
                        }
                        if(negotiatedContent) {
                            String contentLocation=db.contentLocations.get(mediaType);
                            if(contentLocation!=null)
                                resp.setHeader("Content-Location", contentLocation);
                            negotiatedContent=false;
                        }
                    }
                    else { // this was an APP get, but we got nothing!
                        resp.setContentType("text/html");
                        sos=resp.getOutputStream();
                        sos.println("<html><head><title>Document not found</title></head><body><h2>404: Document not found</h2><hr/>OCLC SRW/SRU Server</body></html>");
                        sos.close();
                        resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
                        return;
                    }
                }
                else { // extract SRU response from inside the SRW response
                    int start=soapResponse.indexOf("<searchRetrieveResponse");
                    if(start>=0) {
                        int stop=soapResponse.indexOf("</searchRetrieveResponse>");
                        soapResponse="<searchRetrieveResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.loc.gov/zing/srw/ http://www.loc.gov/standards/sru/sru1-1archive/xml-files/srw-types.xsd\""+cleanup(soapResponse.substring(start+23, stop+25)
                            .toCharArray());
                        if(negotiatedContent)
                            resp.setHeader("Content-Location", req.getRequestURI()+"?"+req.getQueryString()+"&httpAccept="+mediaType);
                    }
                    else { // damn, no searchRetrieveResponse!
                        resp.setContentType("text/html");
                        sos=resp.getOutputStream();
                        sos.println("<html><head><title>Document not found</title></head><body><h2>404: Document not found (No searchRetrieveResponse)</h2><hr/>OCLC SRW/SRU Server</body></html>");
                        sos.close();
                        resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
                        return;
                    }
                }

                // now, let's see if they wanted something else
                if(soapResponse.length()>0 && !mediaType.equals("")) {
                    Transformer trans=null;
                    trans=db.transformers.get(mediaType);
                    if(servletLog.isDebugEnabled())
                        servletLog.debug("trans="+trans);
                    if(trans!=null) {
                        StringWriter toRec = new StringWriter();
                        StreamSource fromRec = new StreamSource(new StringReader(soapResponse));
                        try {
                            trans.transform(fromRec, new StreamResult(toRec));
                            soapResponse=toRec.toString();
                            if(soapResponse.substring(0, Math.min(100, soapResponse.length())).contains("<?xml-stylesheet")) {
                                if(!mediaType.contains("html"))
                                    resp.setContentType("text/xml");
                            }
                            else
                                resp.setContentType(mediaType);
                        } catch (TransformerException e) {
                            servletLog.error(e, e);
                            resp.setContentType("text/xml");
                            sos=resp.getOutputStream();
                            srwInfo.writeXmlHeader(sos, msgContext, req,
                                db.searchStyleSheet);
                            if(db.httpHeaderSetter!=null)
                                db.httpHeaderSetter.setGetResponseHeaders(db.searchRequest, db.response, soapResponse, req, resp);
                        }
                    }
                    else if(mediaType.contains("html")) {
                        // use the stylesheet that would have gone into the XML response as the transformer
                        String styleSheet=req.getParameter("stylesheet");
                        if(styleSheet==null)
                            styleSheet=db.searchStyleSheet;
                        String languages=req.getHeader("Accept-Language");
                        String realXsl=(String)SRWServletInfo.realXsls.get(languages+'/'+styleSheet);
                        if(servletLog.isDebugEnabled())
                            servletLog.debug("realXsl="+realXsl);
                        if(realXsl==null)
                            styleSheet=SRWServletInfo.findRealXsl(languages, req.getLocales(), styleSheet);
                        else
                            styleSheet=realXsl;
//                                if(!styleSheet.startsWith("/")) // relative URL
//                                    styleSheet=req.getContextPath()+"/"+styleSheet;
                        if(servletLog.isDebugEnabled())
                            servletLog.debug("styleSheet="+styleSheet);
                        trans=transformers.get(styleSheet);
                        if(trans==null) { // gotta load it
//                                    URL url=new URL("http://"+req.getServerName()+":"+req.getServerPort()+styleSheet);
                            URL url=new URL("http://localhost"+portNumber+styleSheet);
                            servletLog.info("stylesheet url: "+url);
                            HttpURLConnection conn=null;
                            try {
                                conn=(HttpURLConnection) url.openConnection();
                                servletLog.info("opened URL with response code "+conn.getResponseCode());
                            }
                            catch(ConnectException e) {
                                servletLog.error("ConnectException for stylesheet url: http://localhost"+portNumber+styleSheet);
                            }
                            if(conn.getResponseCode()!=200)
                                servletLog.error("response code="+conn.getResponseCode()+" getting "+url);
                            else {
                                StreamSource so=new StreamSource(conn.getInputStream());
                                so.setSystemId(url.toString());
                                try {
                                    trans = TransformerFactory.newInstance().newTransformer(so);
                                    transformers.put(mediaType, trans);
                                } catch (TransformerConfigurationException ex) {
                                    servletLog.error("unable to build transformer "+url);
                                }
                            }
                        }
                        StringWriter toRec = new StringWriter();
                        StreamSource fromRec = new StreamSource(new StringReader(soapResponse));
                        try {
                            trans.transform(fromRec, new StreamResult(toRec));
                            soapResponse=toRec.toString();
                            if(soapResponse.substring(0, Math.min(100, soapResponse.length())).contains("<?xml-stylesheet")) {
                                resp.setContentType("text/xml");
                            }
                            else
                                resp.setContentType("text/html");
                        } catch (TransformerException e) {
                            servletLog.error(e, e);
                            resp.setContentType("text/xml");
                            sos=resp.getOutputStream();
                            srwInfo.writeXmlHeader(sos, msgContext, req,
                                db.searchStyleSheet);
                            if(db.httpHeaderSetter!=null)
                                db.httpHeaderSetter.setGetResponseHeaders(db.searchRequest, db.response, soapResponse, req, resp);
                        }
                    }
                    else {
                        String xmlHeaders=srwInfo.getXmlHeaders(req, db.searchStyleSheet).toString();
                        if(trans==null && xmlHeaders.substring(0, Math.min(100, xmlHeaders.length())).contains("xml-stylesheet"))
                            resp.setContentType("text/xml");
                        else if(soapResponse.substring(0, Math.min(100, soapResponse.length())).contains("xml-stylesheet"))
                            resp.setContentType("text/xml");
                        else
                            resp.setContentType(mediaType);
                        sos=resp.getOutputStream();
                        if(trans==null)
                            srwInfo.writeXmlHeader(sos, msgContext, req,
                                db.searchStyleSheet);
                        if(db.httpHeaderSetter!=null)
                            db.httpHeaderSetter.setGetResponseHeaders(db.searchRequest, db.response, soapResponse, req, resp);
                    }
                }
                else { //we don't care what they want, just return the SRU response
                    resp.setContentType("text/xml");
                    sos=resp.getOutputStream();
                    srwInfo.writeXmlHeader(sos, msgContext, req,
                        db.searchStyleSheet);
                    if(db.httpHeaderSetter!=null)
                        db.httpHeaderSetter.setGetResponseHeaders(db.searchRequest, db.response, soapResponse, req, resp);
                }
                //writer.println(soapResponse);
                //writer.close();
                if(sos==null)
                    sos=resp.getOutputStream();
                if(db.httpHeaderSetter!=null)
                    db.httpHeaderSetter.setGetResponseHeaders(db.searchRequest, db.response, soapResponse, req, resp);
                try {
                    sos.write(soapResponse.getBytes("utf-8"));
                    sos.close();
                }
                catch (IOException e) {
                    // no need to worry about this, let it slide
                }
            }
            else {
                resp.setContentType("text/html");
                PrintWriter writer=resp.getWriter();
                writer.println("<p>"+Messages.getMessage("noResponse01")+"</p>");
                servletLog.error("request generated no response!");
                writer.close();
            }
//            servletLog.info("at exit: totalMemory="+rt.totalMemory()+", freeMemory="+rt.freeMemory());
            servletLog.debug("exit processMethodRequest");
            return;
        }

        if((operation!=null && operation.equals("scan")) || scanClause!=null) { // scanRequest
            int          i;
            String       t;
            StringBuilder sb=new StringBuilder();
            sb.append("<soap:Envelope ")
              .append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ")
              .append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ")
              .append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">")
              .append("<soap:Body>")
              .append("<srw:scanRequest ")
              .append("xmlns:srw=\"http://www.loc.gov/zing/srw/\">")
              .append("<srw:scanClause>");
            if(scanClause!=null) {
                sb.append(encode(scanClause));
            }
            else
                sb.append("\"\"");
            sb.append("</srw:scanClause>");
           
            t=req.getParameter("responsePosition");
            if(t!=null) {
                try {
                    i=Integer.parseInt(t);
                    if(i<0)
                        i=Integer.MAX_VALUE;
                }
                catch(NumberFormatException e){
                    i=Integer.MAX_VALUE;
                }
                   
                sb.append("<srw:responsePosition>").append(i).append("</srw:responsePosition>");
            }

            t=req.getParameter("maximumTerms");
            if(t!=null) {
                try {
                    i=Integer.parseInt(t);
                    if(i<1)
                        i=Integer.MAX_VALUE;
                }
                catch(NumberFormatException e){
                    i=Integer.MAX_VALUE;
                }
                   
                sb.append("<srw:maximumTerms>").append(i).append("</srw:maximumTerms>");
            }
           
            sb.append("</srw:scanRequest></soap:Body></soap:Envelope>");
            if(servletLog.isDebugEnabled())
                servletLog.debug(sb.toString());
            msgContext.setProperty("sru", "");
            msgContext.setTargetService("SRW");
            AxisEngine engine=getEngine();
            if(servletLog.isDebugEnabled())
                servletLog.debug("request="+sb.toString());
            ByteArrayInputStream bais=new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
            Message msg=new Message(bais, false);
            msgContext.setRequestMessage(msg);
            try {
                engine.invoke(msgContext);
            }
            catch(Exception e) {
                servletLog.error(e, e);
            }
            Message respMsg=msgContext.getResponseMessage();
View Full Code Here

            // Got one!
            try {
                Long id = (Long)header.
                             getValueAsType(Constants.XSD_LONG);
                // Store it away.
                AxisEngine engine = context.getAxisEngine();
                engine.setOption(SESSION_ID, id);
            } catch (Exception e) {
                throw AxisFault.makeFault(e);
            }
        } else {
            AxisEngine engine = context.getAxisEngine();
            Long id = (Long)engine.getOption(SESSION_ID);
            if (id == null)
                return;
           
            // We have a session ID, so insert the header
            Message msg = context.getRequestMessage();
View Full Code Here

        // register the service with the engine
        SOAPService target = new SOAPService(new RPCProvider());
        provider.deployService(new QName(null,namespace), target);

        // setup
        AxisEngine engine = new AxisServer(provider);
        engine.init();

        // create a message in context
        MessageContext msgContext = new MessageContext(engine);
        Message message = new Message(request);
        message.setMessageContext(msgContext);
View Full Code Here

        "</SOAP-ENV:Envelope>";

    public void testDOM() throws Exception {

       // setup
       AxisEngine engine = new AxisServer();
       engine.init();
       MessageContext msgContext = new MessageContext(engine);
       msgContext.setHighFidelity(true);
       String request = header + request1 + footer;
       Message message = new Message(request);
       message.setMessageContext(msgContext);
View Full Code Here

       assertEquals("Request is not the same as the result.", request, result);
    }

    public void testHeaders() throws Exception {
       AxisEngine engine = new AxisServer();
       engine.init();
       MessageContext msgContext = new MessageContext(engine);
       msgContext.setHighFidelity(true);
        String request = header + request1 + footer;
       Message message = new Message(request);
       message.setMessageContext(msgContext);
View Full Code Here

    /**
     * Test for Bug 7132
     */
    public void testAttributes() throws Exception {
       AxisEngine engine = new AxisServer();
       engine.init();
       MessageContext msgContext = new MessageContext(engine);
       msgContext.setHighFidelity(true);
       String request = header + request2 + footer;
       Message message = new Message(request);
       message.setMessageContext(msgContext);
View Full Code Here

                }
            }
        }

        String rootNS = root.getNamespaceURI();
        AxisEngine engine = msgContext.getAxisEngine();

        // If this is WSDD, process it correctly.
        if (rootNS != null && rootNS.equals(WSDDConstants.URI_WSDD)) {
            return processWSDD(msgContext, engine, root);
        }
View Full Code Here

            // System.exit( 1 );
        }

        Admin admin = new Admin();

        AxisEngine engine;
        if ( args[0].equals("client") )
            engine = new AxisClient();
        else
            engine = new AxisServer();
        engine.setShouldSaveConfig(true);
        engine.init();
        MessageContext msgContext = new MessageContext(engine);

        try {
            for ( i = 1 ; i < args.length ; i++ ) {
                if (log.isDebugEnabled())
View Full Code Here

                scopeHolder.value = Scope.DEFAULT.getValue();
                return getNewServiceObject(msgContext, clsName);
            }
        } else if (scope == Scope.APPLICATION) {
            // MUST be AxisEngine here!
            AxisEngine engine = msgContext.getAxisEngine();
            Session appSession = engine.getApplicationSession();
            if (appSession != null) {
                return getSessionServiceObject(appSession, serviceName,
                                               msgContext, clsName);
            } else {
                // was no application session - log an error and
View Full Code Here

TOP

Related Classes of org.apache.axis.AxisEngine

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.