Search in sources :

Example 36 with Scriptable

use of org.mozilla.javascript.Scriptable in project cxf by apache.

the class DocLitBareClientTest method portObjectCaller.

private Void portObjectCaller(Context context) {
    LOG.info("About to call portObjectTest " + getAddress());
    Notifier notifier = testUtilities.rhinoCallConvert("portObjectTest", Notifier.class);
    boolean notified = notifier.waitForJavascript(1000 * 10);
    assertTrue(notified);
    Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
    assertNull(errorStatus);
    String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
    assertNull(errorText);
    // This method returns a String
    Scriptable response = (Scriptable) testUtilities.rhinoEvaluate("globalResponseObject");
    String item = testUtilities.rhinoCallMethodConvert(String.class, response, "getStringItem");
    assertEquals("horsefeathers", item);
    return null;
}
Also used : Scriptable(org.mozilla.javascript.Scriptable) Notifier(org.apache.cxf.javascript.JavascriptTestUtilities.Notifier)

Example 37 with Scriptable

use of org.mozilla.javascript.Scriptable in project cxf by apache.

the class DocLitBareClientTest method beanFunctionCaller.

private Void beanFunctionCaller(Context context) {
    TestBean1 b1 = new TestBean1();
    b1.stringItem = "strung";
    TestBean1[] beans = new TestBean1[3];
    beans[0] = new TestBean1();
    beans[0].stringItem = "zerobean";
    beans[0].beanTwoNotRequiredItem = new TestBean2("bean2");
    beans[1] = null;
    beans[2] = new TestBean1();
    beans[2].stringItem = "twobean";
    beans[2].optionalIntArrayItem = new int[2];
    beans[2].optionalIntArrayItem[0] = 4;
    beans[2].optionalIntArrayItem[1] = 6;
    Object[] jsBeans = new Object[3];
    jsBeans[0] = testBean1ToJS(testUtilities, context, beans[0]);
    jsBeans[1] = null;
    jsBeans[2] = testBean1ToJS(testUtilities, context, beans[2]);
    Scriptable jsBean1 = testBean1ToJS(testUtilities, context, b1);
    Scriptable jsBeanArray = context.newArray(testUtilities.getRhinoScope(), jsBeans);
    LOG.info("About to call beanFunctionTest " + getAddress());
    Notifier notifier = testUtilities.rhinoCallConvert("beanFunctionTest", Notifier.class, testUtilities.javaToJS(getAddress()), jsBean1, jsBeanArray);
    boolean notified = notifier.waitForJavascript(1000 * 10);
    assertTrue(notified);
    Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
    assertNull(errorStatus);
    String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
    assertNull(errorText);
    // this method returns void.
    Scriptable responseObject = (Scriptable) testUtilities.rhinoEvaluate("globalResponseObject");
    // there is no response, this thing returns 'void'
    assertNull(responseObject);
    SimpleDocLitBareImpl impl = (SimpleDocLitBareImpl) rawImplementor;
    TestBean1 b1returned = impl.getLastBean1();
    assertEquals(b1, b1returned);
    // assertArrayEquals(beans, beansReturned);
    return null;
}
Also used : TestBean1(org.apache.cxf.javascript.fortest.TestBean1) SimpleDocLitBareImpl(org.apache.cxf.javascript.fortest.SimpleDocLitBareImpl) TestBean2(org.apache.cxf.javascript.fortest.TestBean2) Scriptable(org.mozilla.javascript.Scriptable) Notifier(org.apache.cxf.javascript.JavascriptTestUtilities.Notifier)

Example 38 with Scriptable

use of org.mozilla.javascript.Scriptable in project cxf by apache.

the class DocLitBareClientTest method testBean1ToJS.

public static Scriptable testBean1ToJS(JavascriptTestUtilities testUtilities, Context context, TestBean1 b1) {
    if (b1 == null) {
        // black is always in fashion. (Really, we can be called with a null).
        return null;
    }
    Scriptable rv = context.newObject(testUtilities.getRhinoScope(), "org_apache_cxf_javascript_testns_testBean1");
    testUtilities.rhinoCallMethod(rv, "setStringItem", testUtilities.javaToJS(b1.stringItem));
    testUtilities.rhinoCallMethod(rv, "setIntItem", testUtilities.javaToJS(b1.intItem));
    testUtilities.rhinoCallMethod(rv, "setLongItem", testUtilities.javaToJS(b1.longItem));
    testUtilities.rhinoCallMethod(rv, "setBase64Item", testUtilities.javaToJS(b1.base64Item));
    testUtilities.rhinoCallMethod(rv, "setOptionalIntItem", testUtilities.javaToJS(b1.optionalIntItem));
    testUtilities.rhinoCallMethod(rv, "setOptionalIntArrayItem", testUtilities.javaToJS(b1.optionalIntArrayItem));
    testUtilities.rhinoCallMethod(rv, "setDoubleItem", testUtilities.javaToJS(b1.doubleItem));
    testUtilities.rhinoCallMethod(rv, "setBeanTwoItem", testBean2ToJS(testUtilities, context, b1.beanTwoItem));
    testUtilities.rhinoCallMethod(rv, "setBeanTwoNotRequiredItem", testBean2ToJS(testUtilities, context, b1.beanTwoNotRequiredItem));
    return rv;
}
Also used : Scriptable(org.mozilla.javascript.Scriptable)

Example 39 with Scriptable

use of org.mozilla.javascript.Scriptable in project cxf by apache.

the class DocLitWrappedClientTest method beanFunctionCaller.

private Void beanFunctionCaller(Context context, boolean useWrapper) {
    TestBean1 b1 = new TestBean1();
    b1.stringItem = "strung";
    TestBean1[] beans = new TestBean1[3];
    beans[0] = new TestBean1();
    beans[0].beanTwoNotRequiredItem = new TestBean2("bean2");
    if (useWrapper) {
        beans[1] = null;
    } else {
        // without a wrapper, it can't be null, so put something in there.
        beans[1] = new TestBean1();
    }
    beans[2] = new TestBean1();
    beans[2].optionalIntArrayItem = new int[2];
    beans[2].optionalIntArrayItem[0] = 4;
    beans[2].optionalIntArrayItem[1] = 6;
    Object[] jsBeans = new Object[3];
    jsBeans[0] = testBean1ToJS(testUtilities, context, beans[0]);
    jsBeans[1] = testBean1ToJS(testUtilities, context, beans[1]);
    jsBeans[2] = testBean1ToJS(testUtilities, context, beans[2]);
    Scriptable jsBean1 = testBean1ToJS(testUtilities, context, b1);
    Scriptable jsBeanArray = context.newArray(testUtilities.getRhinoScope(), jsBeans);
    LOG.info("About to call test4 " + getAddress());
    Notifier notifier = testUtilities.rhinoCallConvert("test4", Notifier.class, testUtilities.javaToJS(getAddress()), testUtilities.javaToJS(Boolean.valueOf(useWrapper)), jsBean1, jsBeanArray);
    boolean notified = notifier.waitForJavascript(1000 * 10);
    assertTrue(notified);
    Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
    assertNull(errorStatus);
    String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
    assertNull(errorText);
    // This method returns void, which translated into a Javascript object with no properties.
    // really. Void.
    Object responseObject = testUtilities.rhinoEvaluate("globalResponseObject");
    assertNotNull(responseObject);
    assertEquals(Context.getUndefinedValue(), responseObject);
    SimpleDocLitWrappedImpl impl = (SimpleDocLitWrappedImpl) rawImplementor;
    TestBean1 b1returned = impl.getLastBean1();
    assertEquals(b1, b1returned);
    TestBean1[] beansReturned = impl.getLastBean1Array();
    assertArrayEquals(beans, beansReturned);
    return null;
}
Also used : TestBean1(org.apache.cxf.javascript.fortest.TestBean1) SimpleDocLitWrappedImpl(org.apache.cxf.javascript.fortest.SimpleDocLitWrappedImpl) TestBean2(org.apache.cxf.javascript.fortest.TestBean2) Scriptable(org.mozilla.javascript.Scriptable) Notifier(org.apache.cxf.javascript.JavascriptTestUtilities.Notifier)

Example 40 with Scriptable

use of org.mozilla.javascript.Scriptable in project cxf by apache.

the class ProviderFactory method publishImpl.

private void publishImpl(File f, String epAddr, boolean isBase) throws Exception {
    if (!f.exists()) {
        throw new Exception(f.getPath() + NO_SUCH_FILE);
    }
    boolean isE4X = f.getName().endsWith(".jsx");
    StringBuilder sb = new StringBuilder();
    try (BufferedReader bufrd = new BufferedReader(new FileReader(f))) {
        String line = null;
        for (; ; ) {
            line = bufrd.readLine();
            if (line == null) {
                break;
            }
            sb.append(line).append("\n");
        }
    }
    String scriptStr = sb.toString();
    Context cx = ContextFactory.getGlobal().enterContext();
    boolean providerFound = false;
    try {
        Scriptable scriptScope = cx.initStandardObjects(null, true);
        Object[] ids = compileScript(cx, scriptStr, scriptScope, f);
        if (ids.length > 0) {
            Service.Mode mode = Service.Mode.PAYLOAD;
            for (Object idObj : ids) {
                if (!(idObj instanceof String)) {
                    continue;
                }
                String id = (String) idObj;
                if (!id.startsWith("WebServiceProvider")) {
                    continue;
                }
                Object obj = scriptScope.get(id, scriptScope);
                if (!(obj instanceof Scriptable)) {
                    continue;
                }
                Scriptable wspVar = (Scriptable) obj;
                providerFound = true;
                obj = wspVar.get("ServiceMode", wspVar);
                if (obj != Scriptable.NOT_FOUND) {
                    if (obj instanceof String) {
                        String value = (String) obj;
                        if ("PAYLOAD".equalsIgnoreCase(value)) {
                            mode = Service.Mode.PAYLOAD;
                        } else if ("MESSAGE".equalsIgnoreCase(value)) {
                            mode = Service.Mode.MESSAGE;
                        } else {
                            throw new Exception(f.getPath() + ILLEGAL_SVCMD_MODE + value);
                        }
                    } else {
                        throw new Exception(f.getPath() + ILLEGAL_SVCMD_TYPE);
                    }
                }
                AbstractDOMProvider provider = createProvider(mode, scriptScope, wspVar, epAddr, isBase, isE4X);
                try {
                    provider.publish();
                    providers.add(provider);
                } catch (AbstractDOMProvider.JSDOMProviderException ex) {
                    StringBuilder msg = new StringBuilder(f.getPath());
                    msg.append(": ").append(ex.getMessage());
                    throw new Exception(msg.toString());
                }
            }
        }
    } finally {
        Context.exit();
    }
    if (!providerFound) {
        throw new Exception(f.getPath() + NO_PROVIDER);
    }
}
Also used : Context(org.mozilla.javascript.Context) Service(javax.xml.ws.Service) Scriptable(org.mozilla.javascript.Scriptable) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Aggregations

Scriptable (org.mozilla.javascript.Scriptable)151 Context (org.mozilla.javascript.Context)67 ScriptableObject (org.mozilla.javascript.ScriptableObject)47 Test (org.junit.Test)17 ContextAction (org.mozilla.javascript.ContextAction)12 Script (org.mozilla.javascript.Script)10 Function (org.mozilla.javascript.Function)9 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)9 ArrayList (java.util.ArrayList)8 NativeObject (org.mozilla.javascript.NativeObject)8 Date (java.util.Date)7 RhinoException (org.mozilla.javascript.RhinoException)7 IOException (java.io.IOException)6 Map (java.util.Map)6 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)5 Notifier (org.apache.cxf.javascript.JavascriptTestUtilities.Notifier)5 KettleException (org.pentaho.di.core.exception.KettleException)5 File (java.io.File)4 InputStreamReader (java.io.InputStreamReader)4 EvaluatorException (org.mozilla.javascript.EvaluatorException)4