Search in sources :

Example 26 with Path

use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.

the class PageTester method runComponentEventRequest.

private TestableResponse runComponentEventRequest() {
    while (true) {
        response.clear();
        try {
            boolean handled = requestHandler.service(request, response);
            if (!handled)
                throw new RuntimeException(String.format("Request for path '%s' was not handled by Tapestry.", request.getPath()));
            Link link = response.getRedirectLink();
            if (link != null) {
                setupRequestFromLink(link);
                continue;
            }
            return response;
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        } finally {
            registry.cleanupThread();
        }
    }
}
Also used : IOException(java.io.IOException) Link(org.apache.tapestry5.http.Link)

Example 27 with Path

use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.

the class AbstractPropertyOutputTest method test_null_pointer_exception_message.

@Test
public // Tests TAPESTRY-2182.
void test_null_pointer_exception_message() {
    final PropertyConduit conduit = mockPropertyConduit();
    final PropertyModel model = mockPropertyModel();
    final Object object = new Object();
    ComponentResources resources = mockComponentResources();
    Location location = mockLocation();
    propertyOutputFixture.inject(model, object, resources);
    expect(model.getConduit()).andReturn(conduit);
    expect(conduit.get(object)).andThrow(new NullPointerException());
    expect(model.getPropertyName()).andReturn("wilma.occupation.address");
    expect(resources.getLocation()).andReturn(location);
    replay();
    try {
        propertyOutputFixture.readPropertyForObject();
        fail("Expected a NullPointerException to be thrown.");
    } catch (final TapestryException ex) {
        assertEquals(ex.getMessage(), "Property 'wilma.occupation.address' contains a null value in the path.");
        assertSame(ex.getLocation(), location);
        assertTrue(ex.getCause() instanceof NullPointerException);
    }
    verify();
}
Also used : PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 28 with Path

use of org.apache.tapestry5.annotations.Path in project fabric8 by jboss-fuse.

the class FactoryMethodProducer method produce.

@Override
public T produce(CreationalContext<T> ctx) {
    List<Object> arguments = new ArrayList<>();
    for (AnnotatedParameter<X> parameter : factoryMethod.getParameters()) {
        Type type = parameter.getBaseType();
        ServiceName parameterServiceName = parameter.getAnnotation(ServiceName.class);
        Protocol parameterProtocol = parameter.getAnnotation(Protocol.class);
        PortName parameterPortName = parameter.getAnnotation(PortName.class);
        Path parameterPath = parameter.getAnnotation(Path.class);
        Endpoint paramEndpoint = parameter.getAnnotation(Endpoint.class);
        External paramExternal = parameter.getAnnotation(External.class);
        Configuration configuration = parameter.getAnnotation(Configuration.class);
        // A point without @ServiceName is invalid.
        // Even if method defines @ServiceName, the annotation on the injection point takes precedence
        String serviceName = pointName;
        String serviceProtocol = or(pointProtocol, parameterProtocol != null ? parameterProtocol.value() : null);
        String servicePort = or(pointPort, parameterPortName != null ? parameterPortName.value() : null);
        String servicePath = or(pointPath, parameterPath != null ? parameterPath.value() : null);
        Boolean serviceEndpoint = paramEndpoint != null ? paramEndpoint.value() : false;
        Boolean serviceExternal = paramExternal != null ? paramExternal.value() : false;
        // If the @ServiceName exists on the current String property
        if (parameterServiceName != null && String.class.equals(type)) {
            try {
                String serviceUrl = getServiceUrl(serviceName, serviceProtocol, servicePort, servicePath, serviceEndpoint, serviceExternal, ctx);
                arguments.add(serviceUrl);
            } catch (Throwable t) {
                throw new RuntimeException(String.format(SERVICE_LOOKUP_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), serviceName), t);
            }
        } else // If the @ServiceName exists on the current List property
        if (parameterServiceName != null && List.class.equals(Types.asClass(type))) {
            try {
                List<String> endpointList = getEndpointList(serviceName, serviceProtocol, servicePort, servicePath, serviceExternal, ctx);
                arguments.add(endpointList);
            } catch (Throwable t) {
                throw new RuntimeException(String.format(SERVICE_LOOKUP_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), serviceName), t);
            }
        } else // If the @ServiceName exists on the current List property
        if (parameterServiceName != null && Set.class.equals(Types.asClass(type))) {
            try {
                List<String> endpointList = getEndpointList(serviceName, serviceProtocol, servicePort, servicePath, serviceExternal, ctx);
                arguments.add(new HashSet<>(endpointList));
            } catch (Throwable t) {
                throw new RuntimeException(String.format(SERVICE_LOOKUP_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), serviceName), t);
            }
        } else // If the @ServiceName exists on the current property which is a non-String
        if (parameterServiceName != null && !String.class.equals(type)) {
            try {
                Object serviceBean = getServiceBean(serviceName, serviceProtocol, servicePort, servicePath, serviceEndpoint, serviceExternal, type, ctx);
                arguments.add(serviceBean);
            } catch (Throwable t) {
                throw new RuntimeException(String.format(BEAN_LOOKUP_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), type, serviceName), t);
            }
        } else // If the current parameter is annotated with @Configuration
        if (configuration != null) {
            try {
                Object config = getConfiguration(serviceName, (Class<Object>) type, ctx);
                arguments.add(config);
            } catch (Throwable t) {
                throw new RuntimeException(String.format(CONF_LOOKUP_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), serviceName), t);
            }
        } else {
            try {
                Object other = BeanProvider.getContextualReference(Types.asClass(type), true);
                arguments.add(other);
            } catch (Throwable t) {
                throw new RuntimeException(String.format(PARAMETER_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), parameter.getPosition()), t);
            }
        }
    }
    try {
        return (T) factoryMethod.getJavaMember().invoke(bean.create(ctx), arguments.toArray());
    } catch (Throwable t) {
        throw new RuntimeException(String.format(INVOCATION_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), arguments), t);
    }
}
Also used : Path(io.fabric8.annotations.Path) HashSet(java.util.HashSet) Set(java.util.Set) Configuration(io.fabric8.annotations.Configuration) ArrayList(java.util.ArrayList) PortName(io.fabric8.annotations.PortName) Type(java.lang.reflect.Type) Endpoint(io.fabric8.annotations.Endpoint) ServiceName(io.fabric8.annotations.ServiceName) External(io.fabric8.annotations.External) ArrayList(java.util.ArrayList) List(java.util.List) Protocol(io.fabric8.annotations.Protocol)

Example 29 with Path

use of org.apache.tapestry5.annotations.Path in project fabric8 by jboss-fuse.

the class Utils method getFactoryMethodPath.

static String getFactoryMethodPath(Method method) {
    for (Annotation[] annotations : method.getParameterAnnotations()) {
        Boolean hasServiceName = false;
        String path = null;
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().equals(ServiceName.class)) {
                hasServiceName = true;
            } else if (annotation.annotationType().equals(Path.class)) {
                path = readAnnotationValue(annotation.toString());
            }
            if (hasServiceName && path != null) {
                return path;
            }
        }
    }
    return null;
}
Also used : Path(io.fabric8.annotations.Path) Annotation(java.lang.annotation.Annotation)

Example 30 with Path

use of org.apache.tapestry5.annotations.Path in project fabric8 by fabric8io.

the class Fabric8Extension method onInjectionPoint.

public <T, X> void onInjectionPoint(@Observes ProcessInjectionPoint<T, X> event, BeanManager beanManager) {
    final InjectionPoint injectionPoint = event.getInjectionPoint();
    if (isServiceInjectionPoint(injectionPoint)) {
        Annotated annotated = injectionPoint.getAnnotated();
        ServiceName name = annotated.getAnnotation(ServiceName.class);
        Protocol protocol = annotated.getAnnotation(Protocol.class);
        PortName port = annotated.getAnnotation(PortName.class);
        Path path = annotated.getAnnotation(Path.class);
        Alias alias = annotated.getAnnotation(Alias.class);
        Endpoint endpoint = annotated.getAnnotation(Endpoint.class);
        External external = annotated.getAnnotation(External.class);
        String serviceName = name.value();
        String serviceProtocol = protocol != null ? protocol.value() : null;
        String servicePort = port != null ? port.value() : null;
        String servicePath = path != null ? path.value() : null;
        String serviceAlias = alias != null ? alias.value() : null;
        Boolean serviceExternal = external != null ? external.value() : false;
        Boolean serviceEndpoint = endpoint != null ? endpoint.value() : false;
        Type type = annotated.getBaseType();
        if (type instanceof ParameterizedType && Instance.class.equals(((ParameterizedType) type).getRawType())) {
            type = ((ParameterizedType) type).getActualTypeArguments()[0];
        }
        if (type.equals(String.class)) {
            ServiceUrlBean.getBean(serviceName, serviceProtocol, servicePort, servicePath, serviceAlias, serviceEndpoint, serviceExternal);
        } else if (isGenericOf(type, List.class, String.class)) {
            ServiceUrlCollectionBean.getBean(serviceName, serviceProtocol, servicePort, servicePath, serviceAlias, serviceEndpoint, serviceExternal, Types.LIST_OF_STRINGS);
        } else if (isGenericOf(type, List.class, null)) {
        // TODO: Integrate with Factories(?)
        } else if (isGenericOf(type, Set.class, String.class)) {
            ServiceUrlCollectionBean.getBean(serviceName, serviceProtocol, servicePort, servicePath, serviceAlias, serviceEndpoint, serviceExternal, Types.SET_OF_STRINGS);
        } else if (isGenericOf(type, Set.class, null)) {
        // TODO: Integrate with Factories(?)
        } else if (type instanceof Class) {
            ServiceBean.getBean(serviceName, serviceProtocol, servicePort, servicePath, serviceAlias, serviceEndpoint, serviceExternal, type);
        } else {
            throw new RuntimeException(String.format(INJECTION_POINT_UNKNOWN_TYPE, injectionPoint.getBean().getBeanClass(), type));
        }
        if (protocol == null) {
            setDefaultProtocol(event);
        }
        if (port == null) {
            setDefaultPort(event);
        }
        if (path == null) {
            setDefaultPath(event);
        }
        if (endpoint == null) {
            setDefaultEndpoint(event);
        }
        if (external == null) {
            setDefaultExternal(event);
        }
    } else if (isConfigurationInjectionPoint(injectionPoint)) {
        Annotated annotated = injectionPoint.getAnnotated();
        Configuration configuration = annotated.getAnnotation(Configuration.class);
        Type type = injectionPoint.getType();
        String configurationId = configuration.value();
        ConfigurationBean.getBean(configurationId, type);
    }
}
Also used : Path(io.fabric8.annotations.Path) Utils.getFactoryMethodPath(io.fabric8.cdi.Utils.getFactoryMethodPath) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Configuration(io.fabric8.annotations.Configuration) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) Instance(javax.enterprise.inject.Instance) PortName(io.fabric8.annotations.PortName) ParameterizedType(java.lang.reflect.ParameterizedType) Annotated(javax.enterprise.inject.spi.Annotated) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Endpoint(io.fabric8.annotations.Endpoint) ServiceName(io.fabric8.annotations.ServiceName) Alias(io.fabric8.annotations.Alias) External(io.fabric8.annotations.External) ArrayList(java.util.ArrayList) List(java.util.List) Utils.getFactoryMethodProtocol(io.fabric8.cdi.Utils.getFactoryMethodProtocol) Protocol(io.fabric8.annotations.Protocol)

Aggregations

Test (org.testng.annotations.Test)22 Request (org.apache.tapestry5.http.services.Request)14 Context (org.apache.tapestry5.http.services.Context)9 Resource (org.apache.tapestry5.commons.Resource)8 Path (io.fabric8.annotations.Path)6 IOException (java.io.IOException)6 URL (java.net.URL)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)5 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)5 Response (org.apache.tapestry5.http.services.Response)5 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)5 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)5 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)5 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)5 Configuration (io.fabric8.annotations.Configuration)4 Endpoint (io.fabric8.annotations.Endpoint)4 External (io.fabric8.annotations.External)4 PortName (io.fabric8.annotations.PortName)4 Protocol (io.fabric8.annotations.Protocol)4