Package com.eviware.soapui.support.scripting

Examples of com.eviware.soapui.support.scripting.SoapUIScriptEngine


      if( !scriptEnginePools.containsKey( engineId ) )
        scriptEnginePools.put( engineId, new ScriptEnginePool( engineId ) );
    }

    ScriptEnginePool scriptEnginePool = scriptEnginePools.get( engineId );
    SoapUIScriptEngine scriptEngine = scriptEnginePool.getScriptEngine();
    try
    {
      scriptEngine.setScript( name );
      for( String key : objects.keySet() )
        scriptEngine.setVariable( key, objects.get( key ) );

      Object result = scriptEngine.run();
      return result == null ? null : result.toString();
    }
    catch( Throwable e )
    {
      log.error( "Error evaluating script", e );
      return e.getMessage();
    }
    finally
    {
      scriptEngine.clearVariables();
      scriptEnginePool.returnScriptEngine( scriptEngine );
    }
  }
View Full Code Here


      throws DispatchException
  {
    String dispatchScript = getMockOperation().getDispatchPath();
    if( StringUtils.hasContent( dispatchScript ) )
    {
      SoapUIScriptEngine scriptEngine = scriptEnginePool.getScriptEngine();

      try
      {
        WsdlMockService mockService = getMockOperation().getMockService();
        WsdlMockRunner mockRunner = mockService.getMockRunner();
        MockRunContext context = mockRunner == null ? new WsdlMockRunContext( mockService, null ) : mockRunner
            .getMockContext();

        scriptEngine.setVariable( "context", context );
        scriptEngine.setVariable( "requestContext", request == null ? null : request.getRequestContext() );
        scriptEngine.setVariable( "mockRequest", request );
        scriptEngine.setVariable( "mockOperation", getMockOperation() );
        scriptEngine.setVariable( "log", SoapUI.ensureGroovyLog() );

        scriptEngine.setScript( dispatchScript );
        Object retVal = scriptEngine.run();
        return getMockOperation().getMockResponseByName( String.valueOf( retVal ) );
      }
      catch( Throwable e )
      {
        SoapUI.logError( e );
View Full Code Here

    {
      onRequestScriptEnginePool = new ScriptEnginePool( this );
      onRequestScriptEnginePool.setScript( script );
    }

    SoapUIScriptEngine scriptEngine = onRequestScriptEnginePool.getScriptEngine();

    try
    {
      scriptEngine.setVariable( "context", runContext );
      scriptEngine.setVariable( "mockRequest", mockRequest );
      scriptEngine.setVariable( "mockRunner", runner );
      scriptEngine.setVariable( "log", SoapUI.ensureGroovyLog() );
      return scriptEngine.run();
    }
    finally
    {
      onRequestScriptEnginePool.returnScriptEngine( scriptEngine );
    }
View Full Code Here

    {
      afterRequestScriptEnginePool = new ScriptEnginePool( this );
      afterRequestScriptEnginePool.setScript( script );
    }

    SoapUIScriptEngine scriptEngine = afterRequestScriptEnginePool.getScriptEngine();

    try
    {
      scriptEngine.setVariable( "context", runContext );
      scriptEngine.setVariable( "mockResult", mockResult );
      scriptEngine.setVariable( "mockRunner", runner );
      scriptEngine.setVariable( "log", SoapUI.ensureGroovyLog() );
      return scriptEngine.run();
    }
    finally
    {
      afterRequestScriptEnginePool.returnScriptEngine( scriptEngine );
    }
View Full Code Here

    MockRunContext context = mockRunner == null ? new WsdlMockRunContext( mockService, null ) : mockRunner
        .getMockContext();

    context.setMockResponse( this );

    SoapUIScriptEngine scriptEngine = scriptEnginePool.getScriptEngine();

    try
    {
      scriptEngine.setVariable( "context", context );
      scriptEngine.setVariable( "requestContext", request == null ? null : request.getRequestContext() );
      scriptEngine.setVariable( "mockContext", context );
      scriptEngine.setVariable( "mockRequest", request );
      scriptEngine.setVariable( "mockResponse", this );
      scriptEngine.setVariable( "log", SoapUI.ensureGroovyLog() );

      scriptEngine.run();
    }
    catch( RuntimeException e )
    {
      throw new Exception( e.getMessage(), e );
    }
View Full Code Here

        MockRunContext context =
                mockRunner == null ? new WsdlMockRunContext(mockService, null) : mockRunner.getMockContext();

        context.setMockResponse(this);

        SoapUIScriptEngine scriptEngine = scriptEnginePool.getScriptEngine();

        try {
            scriptEngine.setVariable("context", context);
            scriptEngine.setVariable("requestContext", request == null ? null : request.getRequestContext());
            scriptEngine.setVariable("mockContext", context);
            scriptEngine.setVariable("mockRequest", request);
            scriptEngine.setVariable("mockResponse", this);
            scriptEngine.setVariable("log", SoapUI.ensureGroovyLog());

            scriptEngine.run();
        } catch (RuntimeException e) {
            throw new Exception(e.getMessage(), e);
        } finally {
            scriptEnginePool.returnScriptEngine(scriptEngine);
        }
View Full Code Here

        if (onRequestScriptEnginePool == null) {
            onRequestScriptEnginePool = new ScriptEnginePool(this);
            onRequestScriptEnginePool.setScript(script);
        }

        SoapUIScriptEngine scriptEngine = onRequestScriptEnginePool.getScriptEngine();

        try {
            scriptEngine.setVariable("context", runContext);
            scriptEngine.setVariable("mockRequest", mockRequest);
            scriptEngine.setVariable("mockRunner", getMockRunner());
            scriptEngine.setVariable("log", SoapUI.ensureGroovyLog());
            return scriptEngine.run();
        } finally {
            onRequestScriptEnginePool.returnScriptEngine(scriptEngine);
        }
    }
View Full Code Here

        if (afterRequestScriptEnginePool == null) {
            afterRequestScriptEnginePool = new ScriptEnginePool(this);
            afterRequestScriptEnginePool.setScript(script);
        }

        SoapUIScriptEngine scriptEngine = afterRequestScriptEnginePool.getScriptEngine();

        try {
            scriptEngine.setVariable("context", runContext);
            scriptEngine.setVariable("mockResult", mockResult);
            scriptEngine.setVariable("mockRunner", getMockRunner());
            scriptEngine.setVariable("log", SoapUI.ensureGroovyLog());
            return scriptEngine.run();
        } finally {
            afterRequestScriptEnginePool.returnScriptEngine(scriptEngine);
        }
    }
View Full Code Here

    public void supportsGroovy2() throws Exception {
        DefaultSoapUICore soapUICore = new DefaultSoapUICore();
        DefaultSoapUICore.log = mock(Logger.class);
        SoapUI.setSoapUICore(soapUICore, true);
        GroovyScriptEngineFactory scriptEngineFactory = new GroovyScriptEngineFactory();
        SoapUIScriptEngine scriptEngine = scriptEngineFactory.createScriptEngine(ModelItemFactory.makeWsdlProject());
        // binary literals are new to Groovy 2
        scriptEngine.setScript("assert 0b10 == 2");
        scriptEngine.run();

    }
View Full Code Here

    public MockResponse selectMockResponse(MockRequest request, MockResult result)
            throws DispatchException {
        String dispatchScript = getMockOperation().getScript();
        if (StringUtils.hasContent(dispatchScript)) {
            SoapUIScriptEngine scriptEngine = scriptEnginePool.getScriptEngine();

            try {
                MockService mockService = getMockOperation().getMockService();
                MockRunner mockRunner = mockService.getMockRunner();
                MockRunContext context = mockRunner == null ? new WsdlMockRunContext(mockService, null) : mockRunner
                        .getMockContext();

                scriptEngine.setVariable("context", context);
                scriptEngine.setVariable("requestContext", request == null ? null : request.getRequestContext());
                scriptEngine.setVariable("mockRequest", request);
                scriptEngine.setVariable("mockOperation", getMockOperation());
                scriptEngine.setVariable("log", SoapUI.ensureGroovyLog());

                scriptEngine.setScript(dispatchScript);
                Object retVal = scriptEngine.run();
                return getMockOperation().getMockResponseByName(String.valueOf(retVal));
            } catch (Throwable e) {
                SoapUI.logError(e);
                throw new DispatchException("Failed to dispatch using script; " + e);
            } finally {
View Full Code Here

TOP

Related Classes of com.eviware.soapui.support.scripting.SoapUIScriptEngine

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.