Package org.apache.axis.server

Examples of org.apache.axis.server.AxisServer


     * The main workhorse method.
     */
    public void run() {
        byte buf[] = new byte[BUFSIZ];
        // create an Axis server
        AxisServer engine = server.getAxisServer();

        // create and initialize a message context
        MessageContext msgContext = new MessageContext(engine);
        Message requestMsg;

        // Reusuable, buffered, content length controlled, InputStream
        NonBlockingBufferedInputStream is =
                new NonBlockingBufferedInputStream();

        // buffers for the headers we care about
        StringBuffer soapAction = new StringBuffer();
        StringBuffer httpRequest = new StringBuffer();
        StringBuffer fileName = new StringBuffer();
        StringBuffer cookie = new StringBuffer();
        StringBuffer cookie2 = new StringBuffer();
        StringBuffer authInfo = new StringBuffer();
        StringBuffer contentType = new StringBuffer();
        StringBuffer contentLocation = new StringBuffer();

        Message responseMsg = null;

        // prepare request (do as much as possible while waiting for the
        // next connection).  Note the next two statements are commented
        // out.  Uncomment them if you experience any problems with not
        // resetting state between requests:
        //   msgContext = new MessageContext();
        //   requestMsg = new Message("", "String");
        try {
            msgContext.setTargetService(null);
        } catch (AxisFault fault) {
        }
        msgContext.setResponseMessage(null);
        msgContext.reset();
        //msgContext.setProperty("transport", "HTTPTransport");
        msgContext.setTransportName(transportName);

        responseMsg = null;

        try {
            // assume the best
            byte[] status = OK;

            // assume we're not getting WSDL
            boolean doWsdl = false;

            // cookie for this session, if any
            String cooky = null;

            try {
                // wipe cookies if we're doing sessions
                if (server.isSessionUsed()) {
                    cookie.delete(0, cookie.length());
                    cookie2.delete(0, cookie2.length());
                }
                authInfo.delete(0, authInfo.length());

                // read headers
                is.setInputStream(socket.getInputStream());
                // parse all headers into hashtable
                int contentLength = parseHeaders(is, buf, contentType,
                        contentLocation, soapAction,
                        httpRequest, fileName,
                        cookie, cookie2, authInfo);
                is.setContentLength(contentLength);

                int paramIdx = fileName.toString().indexOf('?');
                if (paramIdx != -1) {
                    // Got params
                    String params = fileName.substring(paramIdx + 1);
                    fileName.setLength(paramIdx);

                    log.debug(JavaUtils.getMessage("filename00",
                            fileName.toString()));
                    log.debug(JavaUtils.getMessage("params00",
                            params));

                    if ("wsdl".equalsIgnoreCase(params))
                        doWsdl = true;
                }

                // Real and relative paths are the same for the
                // SimpleAxisServer
                msgContext.setProperty(Constants.MC_REALPATH,
                        fileName.toString());
                msgContext.setProperty(Constants.MC_RELATIVE_PATH,
                        fileName.toString());
                msgContext.setProperty(Constants.MC_JWS_CLASSDIR,
                        "jwsClasses");

                // !!! Fix string concatenation
                String url = "http://" + getLocalHost() + ":" +
                        server.getServerSocket().getLocalPort() + "/" +
                        fileName.toString();
                msgContext.setProperty(MessageContext.TRANS_URL, url);

                String filePart = fileName.toString();
                if (filePart.startsWith("axis/services/")) {
                    msgContext.setTargetService(filePart.substring(14));
                }

                if (authInfo.length() > 0) {
                    // Process authentication info
                    //authInfo = new StringBuffer("dXNlcjE6cGFzczE=");
                    byte[] decoded = Base64.decode(authInfo.toString());
                    StringBuffer userBuf = new StringBuffer();
                    StringBuffer pwBuf = new StringBuffer();
                    StringBuffer authBuf = userBuf;
                    for (int i = 0; i < decoded.length; i++) {
                        if ((char) (decoded[i] & 0x7f) == ':') {
                            authBuf = pwBuf;
                            continue;
                        }
                        authBuf.append((char) (decoded[i] & 0x7f));
                    }

                    if (log.isDebugEnabled()) {
                        log.debug(JavaUtils.getMessage("user00",
                                userBuf.toString()));
                    }

                    msgContext.setUsername(userBuf.toString());
                    msgContext.setPassword(pwBuf.toString());
                }

                // if get, then return simpleton document as response
                if (httpRequest.toString().equals("GET")) {
                    OutputStream out = socket.getOutputStream();
                    out.write(HTTP);
                    out.write(status);

                    if (doWsdl) {
                        engine.generateWSDL(msgContext);

                        Document doc = (Document) msgContext.getProperty("WSDL");
                        if (doc != null) {
                            String response = XMLUtils.DocumentToString(doc);
                            byte[] respBytes = response.getBytes();

                            out.write(XML_MIME_STUFF);
                            putInt(buf, out, respBytes.length);
                            out.write(SEPARATOR);
                            out.write(respBytes);
                            out.flush();
                            return;
                        }
                    }

                    StringBuffer sb = new StringBuffer();
                    sb.append("<h2>And now... Some Services</h2>\n");
                    Iterator i = engine.getConfig().getDeployedServices();
                    out.write("<ul>\n".getBytes());
                    while (i.hasNext()) {
                        ServiceDesc sd = (ServiceDesc)i.next();
                        sb.append("<li>\n");
                        sb.append(sd.getName());
                        sb.append(" <a href=\"../services/");
                        sb.append(sd.getName());
                        sb.append("?wsdl\"><i>(wsdl)</i></a></li>\n");
                        ArrayList operations = sd.getOperations();
                        if (!operations.isEmpty()) {
                            sb.append("<ul>\n");
                            for (Iterator it = operations.iterator(); it.hasNext();) {
                                OperationDesc desc = (OperationDesc) it.next();
                                sb.append("<li>" + desc.getName());
                            }
                            sb.append("</ul>\n");
                        }
                    }
                    sb.append("</ul>\n");

                    byte [] bytes = sb.toString().getBytes();

                    out.write(HTML_MIME_STUFF);
                    putInt(buf, out, bytes.length);
                    out.write(SEPARATOR);
                    out.write(bytes);
                    out.flush();
                    return;
                }

                // this may be "" if either SOAPAction: "" or if no SOAPAction at all.
                // for now, do not complain if no SOAPAction at all
                String soapActionString = soapAction.toString();
                if (soapActionString != null) {
                    msgContext.setUseSOAPAction(true);
                    msgContext.setSOAPActionURI(soapActionString);
                }
                requestMsg = new Message(is,
                        false,
                        contentType.toString(),
                        contentLocation.toString()
                );
                msgContext.setRequestMessage(requestMsg);

                // set up session, if any
                if (server.isSessionUsed()) {
                    // did we get a cookie?
                    if (cookie.length() > 0) {
                        cooky = cookie.toString().trim();
                    } else if (cookie2.length() > 0) {
                        cooky = cookie2.toString().trim();
                    }

                    // if cooky is null, cook up a cooky
                    if (cooky == null) {
                        // fake one up!
                        // make it be an arbitrarily increasing number
                        // (no this is not thread safe because ++ isn't atomic)
                        int i = server.sessionIndex++;
                        cooky = "" + i;
                    }

                    msgContext.setSession(server.createSession(cooky));
                }

                // invoke the Axis engine
                engine.invoke(msgContext);

                // Retrieve the response from Axis
                responseMsg = msgContext.getResponseMessage();
                if (responseMsg == null) {
                    throw new AxisFault(JavaUtils.getMessage("nullResponse00"));
View Full Code Here


    * @return DOCUMENT_ME
    */
   public static synchronized AxisServer getServerEngine( String config )
   {
      config = ( config == null ) ? DEFAULT_SERVER_CONFIG : config;
      AxisServer engine = (AxisServer) s_serverEngines.get( config );
      if ( engine == null )
      {
         engine = new AxisServer( new FileProvider( config ) );
         s_serverEngines.put( config, engine );
      }

      return engine;
   }
View Full Code Here

        {
            if ( m_myConfig == null )
            {
                m_myConfig = EngineConfigurationFactoryFinder.newFactory().getServerEngineConfig();
            }
            myAxisServer = new AxisServer( m_myConfig );
            ServiceAdmin.setEngine( myAxisServer, NetworkUtils.getLocalHostname() + "@" + m_serverSocket.getLocalPort() );
        }
        return myAxisServer;
    }
View Full Code Here

   public void execute(  )
   {
      byte[] buf = new byte[BUFSIZ];

      // create an Axis server
      AxisServer engine = m_server.getAxisServer(  );

      // create and initialize a message context
      MessageContext msgContext = new MessageContext( engine );
      Message        requestMsg = null;

      // Reusuable, buffered, content length controlled, InputStream
      NonBlockingBufferedInputStream is = new NonBlockingBufferedInputStream(  );

      // buffers for the headers we care about
      StringBuffer soapAction      = new StringBuffer(  );
      StringBuffer httpRequest     = new StringBuffer(  );
      StringBuffer fileName        = new StringBuffer(  );
      StringBuffer cookie          = new StringBuffer(  );
      StringBuffer cookie2         = new StringBuffer(  );
      StringBuffer authInfo        = new StringBuffer(  );
      StringBuffer contentType     = new StringBuffer(  );
      StringBuffer contentLocation = new StringBuffer(  );

      Message      responseMsg = null;

      // prepare request (do as much as possible while waiting for the
      // next connection).  Note the next two statements are commented
      // out.  Uncomment them if you experience any problems with not
      // resetting state between requests:
      //   msgContext = new MessageContext();
      //   requestMsg = new Message("", "String");
      //msgContext.setProperty("transport", "HTTPTransport");
      msgContext.setTransportName( TRANSPORT_NAME );

      responseMsg = null;

      try
      {
         // assume the best
         byte[] status = OK;

         // assume we're not getting WSDL
         boolean doWsdl = false;

         // cookie for this session, if any
         String cooky = null;

         String methodName = null;

         try
         {
            // wipe cookies if we're doing sessions
            if ( m_server.isSessionUsed(  ) )
            {
               cookie.delete( 0,
                              cookie.length(  ) );
               cookie2.delete( 0,
                               cookie2.length(  ) );
            }

            authInfo.delete( 0,
                             authInfo.length(  ) );

            // read headers
            is.setInputStream( m_socket.getInputStream(  ) );

            // parse all headers into hashtable
            MimeHeaders requestHeaders = new MimeHeaders(  );
            int         contentLength =
               parseHeaders( is, buf, contentType, contentLocation, soapAction, httpRequest, fileName, cookie,
                             cookie2, authInfo, requestHeaders );
            is.setContentLength( contentLength );

            int paramIdx = fileName.toString(  ).indexOf( '?' );
            if ( paramIdx != -1 )
            {
               // Got params
               String params = fileName.substring( paramIdx + 1 );
               fileName.setLength( paramIdx );

               log.debug( Messages.getMessage( "filename00",
                                               fileName.toString(  ) ) );
               log.debug( Messages.getMessage( "params00", params ) );

               if ( "wsdl".equalsIgnoreCase( params ) )
               {
                  doWsdl = true;
               }

               if ( params.startsWith( "method=" ) )
               {
                  methodName = params.substring( 7 );
               }
            }

            // Real and relative paths are the same for the
            // SimpleAxisServer
            msgContext.setProperty( Constants.MC_REALPATH,
                                    fileName.toString(  ) );
            msgContext.setProperty( Constants.MC_RELATIVE_PATH,
                                    fileName.toString(  ) );
            msgContext.setProperty( Constants.MC_JWS_CLASSDIR, "jwsClasses" );
            msgContext.setProperty( Constants.MC_HOME_DIR, "." );

            // !!! Fix string concatenation
            String url =
               "http://" + getLocalHost(  ) + ":" + m_server.getServerSocket(  ).getLocalPort(  ) + "/"
               + fileName.toString(  );
            msgContext.setProperty( MessageContext.TRANS_URL, url );

            String filePart = fileName.toString(  );
            if ( filePart.startsWith( "axis/services/" ) )
            {
               String servicePart = filePart.substring( 14 );
               int    separator = servicePart.indexOf( '/' );
               if ( separator > -1 )
               {
                  msgContext.setProperty( "objectID",
                                          servicePart.substring( separator + 1 ) );
                  servicePart = servicePart.substring( 0, separator );
               }

               msgContext.setTargetService( servicePart );
            }

            if ( authInfo.length(  ) > 0 )
            {
               // Process authentication info
               //authInfo = new StringBuffer("dXNlcjE6cGFzczE=");
               byte[]       decoded = Base64.decode( authInfo.toString(  ) );
               StringBuffer userBuf = new StringBuffer(  );
               StringBuffer pwBuf   = new StringBuffer(  );
               StringBuffer authBuf = userBuf;
               for ( int i = 0; i < decoded.length; i++ )
               {
                  if ( (char) ( decoded[i] & 0x7f ) == ':' )
                  {
                     authBuf = pwBuf;
                     continue;
                  }

                  authBuf.append( (char) ( decoded[i] & 0x7f ) );
               }

               if ( log.isDebugEnabled(  ) )
               {
                  log.debug( Messages.getMessage( "user00",
                                                  userBuf.toString(  ) ) );
               }

               msgContext.setUsername( userBuf.toString(  ) );
               msgContext.setPassword( pwBuf.toString(  ) );
            }

            // if get, then return simpleton document as response
            if ( httpRequest.toString(  ).equals( "GET" ) )
            {
               OutputStream out = m_socket.getOutputStream(  );
               out.write( HTTP );
               if ( fileName.length(  ) == 0 )
               {
                  out.write( "301 Redirect\nLocation: /axis/\n\n".getBytes(  ) );
                  out.flush(  );
                  return;
               }

               out.write( status );

               if ( methodName != null )
               {
                  String body = "<" + methodName + ">" +
                     //                               args +
                     "</" + methodName + ">";
                  String msgtxt =
                     "<SOAP-ENV:Envelope" + " xmlns:SOAP-ENV=\"" + Constants.URI_SOAP12_ENV + "\">"
                     + "<SOAP-ENV:Body>" + body + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>";

                  ByteArrayInputStream istream = new ByteArrayInputStream( msgtxt.getBytes(  ) );
                  requestMsg = new Message( istream );
               }
               else if ( doWsdl )
               {
                  engine.generateWSDL( msgContext );

                  Document doc = (Document) msgContext.getProperty( "WSDL" );
                  if ( doc != null )
                  {
                     XMLUtils.normalize( doc.getDocumentElement(  ) );
                     String response  = XMLUtils.PrettyDocumentToString( doc );
                     byte[] respBytes = response.getBytes(  );

                     out.write( XML_MIME_STUFF );
                     putInt( buf, out, respBytes.length );
                     out.write( SEPARATOR );
                     out.write( respBytes );
                     out.flush(  );
                     return;
                  }
               }
               else if ( fileName.equals( "/" ) )
               {
                  StringBuffer sb = new StringBuffer(  );
                  sb.append( "<h2>And now... Some Services</h2>\n" );
                  Iterator i = engine.getConfig(  ).getDeployedServices(  );
                  sb.append( "<ul>\n" );
                  while ( i.hasNext(  ) )
                  {
                     ServiceDesc sd = (ServiceDesc) i.next(  );
                     sb.append( "<li>\n" );
                     sb.append( sd.getName(  ) );
                     sb.append( " <a href=\"services/" );
                     sb.append( sd.getName(  ) );
                     sb.append( "?wsdl\"><i>(wsdl)</i></a></li>\n" );
                     ArrayList operations = sd.getOperations(  );
                     if ( !operations.isEmpty(  ) )
                     {
                        sb.append( "<ul>\n" );
                        for ( Iterator it = operations.iterator(  ); it.hasNext(  ); )
                        {
                           OperationDesc desc = (OperationDesc) it.next(  );
                           sb.append( "<li>" + desc.getName(  ) );
                        }

                        sb.append( "</ul>\n" );
                     }
                  }

                  sb.append( "</ul>\n" );

                  byte[] bytes = sb.toString(  ).getBytes(  );

                  out.write( HTML_MIME_STUFF );
                  putInt( buf, out, bytes.length );
                  out.write( SEPARATOR );
                  out.write( bytes );
                  out.flush(  );
                  return;
               }
               else
               {
                  String filePath = fileName.toString(  );
                  if ( filePath.startsWith( "/" ) )
                  {
                     filePath = filePath.substring( 1 );
                  }

                  File        realPath = new File( m_docRootDir, filePath );
                  InputStream in = new BufferedInputStream( new FileInputStream( realPath ) );

                  //System.out.println( "Serving up " + realPath + " on a silver platter..." );
                  IoUtils.copy( in, out );
                  in.close(  );
                  out.flush(  );
                  return;
               }
            }
            else
            {
               // this may be "" if either SOAPAction: "" or if no SOAPAction at all.
               // for now, do not complain if no SOAPAction at all
               String soapActionString = soapAction.toString(  );
               if ( soapActionString != null )
               {
                  msgContext.setUseSOAPAction( true );
                  msgContext.setSOAPActionURI( soapActionString );
               }

               requestMsg = new Message( is,
                                         false,
                                         contentType.toString(  ),
                                         contentLocation.toString(  ) );
            }

            // Transfer HTTP headers to MIME headers for request message.
            MimeHeaders requestMimeHeaders = requestMsg.getMimeHeaders(  );
            for ( Iterator i = requestHeaders.getAllHeaders(  ); i.hasNext(  ); )
            {
               MimeHeader requestHeader = (MimeHeader) i.next(  );
               requestMimeHeaders.addHeader( requestHeader.getName(  ),
                                             requestHeader.getValue(  ) );
            }

            msgContext.setRequestMessage( requestMsg );

            // put character encoding of request to message context
            // in order to reuse it during the whole process.
            String requestEncoding = (String) requestMsg.getProperty( SOAPMessage.CHARACTER_SET_ENCODING );
            if ( requestEncoding != null )
            {
               msgContext.setProperty( SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding );
            }

            // set up session, if any
            if ( m_server.isSessionUsed(  ) )
            {
               // did we get a cookie?
               if ( cookie.length(  ) > 0 )
               {
                  cooky = cookie.toString(  ).trim(  );
               }
               else if ( cookie2.length(  ) > 0 )
               {
                  cooky = cookie2.toString(  ).trim(  );
               }

               // if cooky is null, cook up a cooky
               if ( cooky == null )
               {
                  // fake one up!
                  // make it be an arbitrarily increasing number
                  // (no this is not thread safe because ++ isn't atomic)
                  int i = SimpleAxisServer.sessionIndex++;
                  cooky = "" + i;
               }

               msgContext.setSession( m_server.createSession( cooky ) );
            }

            // invoke the Axis engine
            engine.invoke( msgContext );

            // Retrieve the response from Axis
            responseMsg = msgContext.getResponseMessage(  );

            if ( responseMsg == null )
View Full Code Here

            throw new BuildException( "No deploy WSDDs were specified!" );
        }

        try
        {
            AxisEngine axisEngine = new AxisServer( new FileProvider( m_configWsdd ) );
            m_msgContext = new MessageContext( axisEngine );
            m_axisAdmin = new Admin();
            for ( int i = 0; i < m_wsddFiles.size(); i++ )
            {
                deployWsdd( (File) m_wsddFiles.get( i ) );
View Full Code Here

import java.net.URI;

public class TestSerialization {

    public static void main(String[] args) throws Exception {
        MessageContext msgContext = new MessageContext(new AxisServer());
        SOAPEnvelope msg = new SOAPEnvelope();
        RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam", "this is a string");
        //QName dataQName = new QName("typeNS", "Data");

        Document doc = msg.getAsDocument();
View Full Code Here

    /**
     * @see org.ofbiz.webapp.event.EventHandler#invoke(Event, org.ofbiz.webapp.control.ConfigXMLReader.RequestMap, HttpServletRequest, HttpServletResponse)
     */
    public String invoke(Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException {
        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
        AxisServer axisServer;

        // first check for WSDL request
        String wsdlReq = request.getParameter("wsdl");
        if (wsdlReq == null) {
            wsdlReq = request.getParameter("WSDL");
View Full Code Here

  boolean  pleaseStop = false ;
  boolean  halted     = false ;

  public void run() {
    String tmp = "" ;
    AxisServer  server = new AxisServer();
    server.init();

    while( !pleaseStop ) {
      try {
        Thread.sleep( 100 );
        File file = new File( "xml" + nextNum + ".req" );
        if ( !file.exists() ) continue ;
         
          // avoid race condition where file comes to exist but we were halted -- RobJ
          if (pleaseStop) continue;

        Thread.sleep( 100 );   // let the other side finish writing
        FileInputStream fis = new FileInputStream( file );

        int thisNum = nextNum++; // increment early to avoid infinite loops
       
        Message msg = new Message( fis );
        msg.getSOAPPartAsBytes();

        fis.close();
        file.delete();

        MessageContext  msgContext = new MessageContext(server);
        msgContext.setRequestMessage( msg );

        try {
            server.invoke( msgContext );
            msg = msgContext.getResponseMessage();
        } catch (AxisFault af) {
            msg = new Message(af);
            msg.setMessageContext(msgContext);
        } catch (Exception e) {
View Full Code Here

        }
        public void run () {
            // get the input stream
            if ( engine == null ) {
                XMLStringProvider provider = new XMLStringProvider(wsdd);
                engine = new AxisServer(provider);
                engine.init();
            }

            /* Place the Request message in the MessagContext object - notice */
            /* that we just leave it as a 'ServletRequest' object and let the  */
 
View Full Code Here

    * @return DOCUMENT_ME
    */
   public static synchronized AxisServer getServerEngine( String config )
   {
      config = ( config == null ) ? DEFAULT_SERVER_CONFIG : config;
      AxisServer engine = (AxisServer) s_serverEngines.get( config );
      if ( engine == null )
      {
         engine = new AxisServer( new FileProvider( config ) );
         s_serverEngines.put( config, engine );
      }

      return engine;
   }
View Full Code Here

TOP

Related Classes of org.apache.axis.server.AxisServer

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.