Search in sources :

Example 1 with Pre

use of com.vaadin.flow.component.html.Pre in project sapl-demos by heutelbeck.

the class Utilities method getInfoText.

public static HorizontalLayout getInfoText(String infoText) {
    Pre infoTextPre = new Pre(infoText);
    infoTextPre.getStyle().set("white-space", "pre-wrap").set("margin", "auto").set("font-size", "medium").set("padding-left", "5px").set("padding-right", "5px");
    Icon infoIcon = new Icon(VaadinIcon.INFO_CIRCLE);
    return new HorizontalLayout(infoIcon, infoTextPre);
}
Also used : Pre(com.vaadin.flow.component.html.Pre) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) Icon(com.vaadin.flow.component.icon.Icon) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 2 with Pre

use of com.vaadin.flow.component.html.Pre in project alibaba-rsocket-broker by alibaba.

the class ServiceTestingView method callRSocketService.

public void callRSocketService(String service, String method, @Nullable String jsonData, Pre response) {
    Integer handlerId = this.routingSelector.findHandler(ServiceLocator.serviceHashCode(service));
    if (handlerId != null) {
        RSocketBrokerResponderHandler handler = handlerRegistry.findById(handlerId);
        if (handler != null) {
            // composite metadata for health check
            RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(new GSVRoutingMetadata(null, service, method, null), new MessageMimeTypeMetadata(RSocketMimeType.Json));
            ByteBuf payLoadData;
            if (jsonData == null || jsonData.isEmpty()) {
                payLoadData = Unpooled.EMPTY_BUFFER;
            } else {
                payLoadData = Unpooled.wrappedBuffer(jsonData.getBytes(StandardCharsets.UTF_8));
            }
            Payload requestPayload = ByteBufPayload.create(payLoadData, compositeMetadata.getContent());
            handler.getPeerRsocket().requestResponse(requestPayload).doOnError(throwable -> getUI().ifPresent(ui -> ui.access(() -> {
                response.setText(throwable.getMessage());
            }))).subscribe(payload -> getUI().ifPresent(ui -> ui.access(() -> {
                response.setText(payload.getDataUtf8());
            })));
        } else {
            this.serviceNameFiled.setInvalid(true);
            this.serviceNameFiled.setErrorMessage("No Service Provider!");
        }
    } else {
        this.serviceNameFiled.setInvalid(true);
        this.serviceNameFiled.setErrorMessage("Service not found!");
    }
}
Also used : RSocketBrokerResponderHandler(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler) RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) TextArea(com.vaadin.flow.component.textfield.TextArea) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Autowired(org.springframework.beans.factory.annotation.Autowired) RSocketBrokerHandlerRegistry(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerHandlerRegistry) Route(com.vaadin.flow.router.Route) Unpooled(io.netty.buffer.Unpooled) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata) ByteBuf(io.netty.buffer.ByteBuf) RSocketBrokerResponderHandler(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler) TextField(com.vaadin.flow.component.textfield.TextField) ByteBufPayload(io.rsocket.util.ByteBufPayload) RSocketMimeType(com.alibaba.rsocket.metadata.RSocketMimeType) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H3(com.vaadin.flow.component.html.H3) ServiceRoutingSelector(com.alibaba.spring.boot.rsocket.broker.route.ServiceRoutingSelector) H4(com.vaadin.flow.component.html.H4) RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) StandardCharsets(java.nio.charset.StandardCharsets) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) Nullable(org.jetbrains.annotations.Nullable) Button(com.vaadin.flow.component.button.Button) Payload(io.rsocket.Payload) NAV(com.alibaba.rsocket.broker.web.ui.ServiceTestingView.NAV) Pre(com.vaadin.flow.component.html.Pre) ServiceLocator(com.alibaba.rsocket.ServiceLocator) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata) ByteBufPayload(io.rsocket.util.ByteBufPayload) Payload(io.rsocket.Payload) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with Pre

use of com.vaadin.flow.component.html.Pre in project alibaba-rsocket-broker by alibaba.

the class ServiceTestingView method makeServiceCallForm.

VerticalLayout makeServiceCallForm() {
    VerticalLayout content = new VerticalLayout();
    this.serviceNameFiled = new TextField("Service Name");
    serviceNameFiled.setWidth("300px");
    this.methodNameField = new TextField("Method Name");
    methodNameField.setWidth("300px");
    TextArea jsonDataTextArea = new TextArea("JSON Data");
    jsonDataTextArea.setWidth("600px");
    jsonDataTextArea.setHeight("200px");
    Pre responsePre = new Pre();
    HorizontalLayout buttons = new HorizontalLayout();
    Button callButton = new Button("Invoke", buttonClickEvent -> {
        String serviceName = serviceNameFiled.getValue();
        String methodName = methodNameField.getValue();
        String jsonData = jsonDataTextArea.getValue();
        if (serviceName == null || serviceName.isEmpty()) {
            serviceNameFiled.setErrorMessage("Please input service name");
        }
        if (methodName == null || methodName.isEmpty()) {
            methodNameField.setErrorMessage("Please input service name");
        }
        if (jsonData != null) {
            jsonData = jsonData.trim();
            if (!jsonData.isEmpty() && !jsonData.startsWith("[")) {
                jsonData = "[" + jsonData + "]";
            }
        }
        callRSocketService(serviceName, methodName, jsonData, responsePre);
    });
    content.add(new H3("RSocket Service Testing"));
    content.add(serviceNameFiled);
    content.add(methodNameField);
    content.add(jsonDataTextArea);
    content.add(new H4("Response"));
    content.add(responsePre);
    buttons.add(callButton);
    buttons.add(new Button("Clear", buttonClickEvent -> {
        serviceNameFiled.clear();
        serviceNameFiled.setInvalid(false);
        methodNameField.clear();
        jsonDataTextArea.clear();
        responsePre.setText("");
    }));
    content.add(buttons);
    return content;
}
Also used : TextArea(com.vaadin.flow.component.textfield.TextArea) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Autowired(org.springframework.beans.factory.annotation.Autowired) RSocketBrokerHandlerRegistry(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerHandlerRegistry) Route(com.vaadin.flow.router.Route) Unpooled(io.netty.buffer.Unpooled) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata) ByteBuf(io.netty.buffer.ByteBuf) RSocketBrokerResponderHandler(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler) TextField(com.vaadin.flow.component.textfield.TextField) ByteBufPayload(io.rsocket.util.ByteBufPayload) RSocketMimeType(com.alibaba.rsocket.metadata.RSocketMimeType) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H3(com.vaadin.flow.component.html.H3) ServiceRoutingSelector(com.alibaba.spring.boot.rsocket.broker.route.ServiceRoutingSelector) H4(com.vaadin.flow.component.html.H4) RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) StandardCharsets(java.nio.charset.StandardCharsets) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) Nullable(org.jetbrains.annotations.Nullable) Button(com.vaadin.flow.component.button.Button) Payload(io.rsocket.Payload) NAV(com.alibaba.rsocket.broker.web.ui.ServiceTestingView.NAV) Pre(com.vaadin.flow.component.html.Pre) ServiceLocator(com.alibaba.rsocket.ServiceLocator) Pre(com.vaadin.flow.component.html.Pre) TextArea(com.vaadin.flow.component.textfield.TextArea) Button(com.vaadin.flow.component.button.Button) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) TextField(com.vaadin.flow.component.textfield.TextField) H3(com.vaadin.flow.component.html.H3) H4(com.vaadin.flow.component.html.H4) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Aggregations

Pre (com.vaadin.flow.component.html.Pre)3 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)3 ServiceLocator (com.alibaba.rsocket.ServiceLocator)2 NAV (com.alibaba.rsocket.broker.web.ui.ServiceTestingView.NAV)2 GSVRoutingMetadata (com.alibaba.rsocket.metadata.GSVRoutingMetadata)2 MessageMimeTypeMetadata (com.alibaba.rsocket.metadata.MessageMimeTypeMetadata)2 RSocketCompositeMetadata (com.alibaba.rsocket.metadata.RSocketCompositeMetadata)2 RSocketMimeType (com.alibaba.rsocket.metadata.RSocketMimeType)2 RSocketBrokerHandlerRegistry (com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerHandlerRegistry)2 RSocketBrokerResponderHandler (com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler)2 ServiceRoutingSelector (com.alibaba.spring.boot.rsocket.broker.route.ServiceRoutingSelector)2 Button (com.vaadin.flow.component.button.Button)2 H3 (com.vaadin.flow.component.html.H3)2 H4 (com.vaadin.flow.component.html.H4)2 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)2 TextArea (com.vaadin.flow.component.textfield.TextArea)2 TextField (com.vaadin.flow.component.textfield.TextField)2 Route (com.vaadin.flow.router.Route)2 ByteBuf (io.netty.buffer.ByteBuf)2 Unpooled (io.netty.buffer.Unpooled)2