This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 257849 - @OnReceive doesn't work in NbBrowsers: Introduce xhr4j module
Summary: @OnReceive doesn't work in NbBrowsers: Introduce xhr4j module
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Html4j (show other bugs)
Version: 8.1
Hardware: PC Mac OS X
: P3 normal (vote)
Assignee: Jaroslav Tulach
URL:
Keywords: API_REVIEW_FAST
Depends on:
Blocks:
 
Reported: 2016-02-04 16:44 UTC by maxnitribitt
Modified: 2016-03-18 02:47 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description maxnitribitt 2016-02-04 16:44:46 UTC
When using htmlui api, the @OnReceive annotation doesn't work correctly. 

I have created an application using the DukeScript Wizard that connects to the bitbucket REST API. It works correctly in the normal client, but doesn't work when running in the "Client for NetBeans". 

Debugging showed that with KOTransfer in LoadJSON the XMLHttpRequest returns status code "0", and never gets past a request.readyState of "1".

Similar bugs (XMLHttpRequest returns status code "0") on Stackoverflow almost always are problems with CORS. Apparently it doesn't work when WebView is running inside NetBeans. I tried setting a system property for WebView as a workaround as indicated here, but without success:

http://stackoverflow.com/questions/23692746/webview-does-not-really-support-cors-in-javafx-2-2

Workaround: Using Tyrus (ko-ws-tyrus) instead of KOTransfer the application works correctly.

To use it I added a dependency on Tyrus:

        <dependency>
            <groupId>org.netbeans.html</groupId>
            <artifactId>ko-ws-tyrus</artifactId>
            <version>1.2.3</version>
            <type>jar</type>
        </dependency>

In addition to the dependency you need to register Tyrus on a position lower than 100 (otherwise KOTransfer has preference):

import org.netbeans.html.context.spi.Contexts;
import org.netbeans.html.json.spi.Transfer;
import org.openide.util.lookup.ServiceProvider;

@ServiceProvider(service = Contexts.Provider.class)
public class RegisterTransfer  implements Contexts.Provider {

    @Override
    public void fillContext(Contexts.Builder context, Class<?> requestor) {
        context.register(Transfer.class, new KOTransfer(), 10);
    }
}


That is a bit cumbersome, so I would suggest to make it easier to use Tyrus. It should probably be the default when running in NetBeans.
Comment 1 maxnitribitt 2016-02-04 17:15:34 UTC
Here's the project with the workaround:

https://bitbucket.org/DukeScript/bitbucket-plugin

To test without tyrus just comment out the registration of Provider:

// @ServiceProvider(service = Contexts.Provider.class)
Comment 2 Jaroslav Tulach 2016-02-29 04:29:11 UTC
The best way to simplify this is to provide new xhr4j module that will handle the @OnReceive request with higher priority:
http://source.apidesign.org/hg/html~html4j/rev/b547f8f663f5
I plan to add the module for HTML/Java 1.3 - e.g. NetBeans 8.2
Comment 3 Jaroslav Tulach 2016-03-01 03:40:59 UTC
The bits for HTML/Java 1.3 are staged at
https://maven.java.net/content/repositories/orgapidesign-1046/
Please give them a bit of testing.
Comment 4 Jaroslav Tulach 2016-03-04 10:32:22 UTC
2nd attempt to release HTML/Java @ 1.3 bits:
https://maven.java.net/content/repositories/orgapidesign-1049
Comment 5 Jaroslav Tulach 2016-03-15 08:04:15 UTC
I plan to release the bits of HTML/Java @ 1.3 in 24h.
Comment 7 Jaroslav Tulach 2016-03-15 22:27:08 UTC
http://hg.netbeans.org/ergonomics/rev/f528a73f5374
Comment 8 Quality Engineering 2016-03-18 02:47:51 UTC
Integrated into 'main-silver', will be available in build *201603180001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/4640e3706d9e
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #257849: Switching existing HTML/Java modules to version 1.3