/** * Returns error type. Error type is an identifier of a group of errors. * * @return error type. */ public int errorType() { if (!isError()) { throw new IllegalStateException("Message is not an error"); } try { return Integer.parseInt(Qualifier.getQualifierAction(qualifier())); } catch (NumberFormatException e) { throw new IllegalStateException("Error type must be a number"); } }
/** * Builds error qualifier. * * @param action qualifier action. * @return constructed qualifier string. */ public static String asError(int action) { return asString(ERROR_NAMESPACE, Integer.toString(action)); }
private ClientMessage toMessage(HttpClientResponse httpResponse, ByteBuf content) { int httpCode = httpResponse.status().code(); String qualifier = isError(httpCode) ? Qualifier.asError(httpCode) : httpResponse.uri(); Builder builder = ClientMessage.builder().qualifier(qualifier).data(content); // prepare response headers httpResponse .responseHeaders() .entries() .forEach(entry -> builder.header(entry.getKey(), entry.getValue())); ClientMessage message = builder.build(); LOGGER.debug("Received response {}", message); return message; }
/** * Instantiates new message with error qualifier for given error type and specified error code and * message. * * @param errorType the error type to be used in message qualifier. * @param errorCode the error code. * @param errorMessage the error message. * @return builder. */ public static ServiceMessage error(int errorType, int errorCode, String errorMessage) { return ServiceMessage.builder() .qualifier(Qualifier.asError(errorType)) .data(new ErrorData(errorCode, errorMessage)) .build(); }
/** * Returns error type. Error type is an identifier of a group of errors. * * @return error type. */ public int errorType() { if (!isError()) { throw new IllegalStateException("Message is not an error"); } try { return Integer.parseInt(Qualifier.getQualifierAction(qualifier())); } catch (NumberFormatException e) { throw new IllegalStateException("Error type must be a number"); } }
/** * Create a new service info. * * @param serviceName the name of the service * @param methodName the name of the methof * @param parameterizedReturnType the return type (with generics support) * @param communicationMode the directions of the method * @param parameterCount amount of parameters * @param requestType the type of the request */ public MethodInfo( String serviceName, String methodName, Class<?> parameterizedReturnType, CommunicationMode communicationMode, int parameterCount, Class<?> requestType) { this.parameterizedReturnType = parameterizedReturnType; this.communicationMode = communicationMode; this.serviceName = serviceName; this.methodName = methodName; this.qualifier = Qualifier.asString(serviceName, methodName); this.parameterCount = parameterCount; this.requestType = requestType; }
private Mono<Void> error(HttpServerResponse httpResponse, ServiceMessage response) { int code = Integer.parseInt(Qualifier.getQualifierAction(response.qualifier())); HttpResponseStatus status = HttpResponseStatus.valueOf(code); ByteBuf content = response.hasData(ErrorData.class) ? encodeData(response.data(), response.dataFormatOrDefault()) : response.data(); return httpResponse.status(status).sendObject(content).then(); }
public Builder qualifier(String serviceName, String methodName) { return qualifier(Qualifier.asString(serviceName, methodName)); }
public static String qualifier(Class<?> serviceInterface, Method method) { return Qualifier.asString(serviceName(serviceInterface), methodName(method)); }
public static String qualifier(Class<?> serviceInterface, Method method) { return Qualifier.asString(serviceName(serviceInterface), methodName(method)); }
/** * Constructor for service reference. * * @param serviceMethodDefinition service method info * @param serviceRegistration service registration * @param serviceEndpoint service node info */ public ServiceReference( ServiceMethodDefinition serviceMethodDefinition, ServiceRegistration serviceRegistration, ServiceEndpoint serviceEndpoint) { this.endpointId = serviceEndpoint.id(); this.host = serviceEndpoint.host(); this.port = serviceEndpoint.port(); this.namespace = serviceRegistration.namespace(); this.contentTypes = Collections.unmodifiableSet(serviceEndpoint.contentTypes()); this.tags = mergeTags(serviceMethodDefinition, serviceRegistration, serviceEndpoint); this.action = serviceMethodDefinition.getAction(); this.mode = serviceMethodDefinition.getCommunicationMode(); this.qualifier = Qualifier.asString(namespace, action); this.address = Address.create(this.host(), this.port()); }