小编mah*_*454的帖子

akka http编译错误

我是akka框架的新手,现在尝试用这个框架设置简单的webservice.
写一个简单的akka​​-http应用程序:

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer

import scala.io.StdIn

object MainRunner extends App {

  implicit val system = ActorSystem("mySystem")
  implicit val materializer = ActorMaterializer
  implicit val ec = system.dispatcher

  val route =
    path("hello") {
      get {
        complete("Congratulation , this is your response")
      }
    }

  val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)

  println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
  StdIn.readLine() // let it run until user presses return
  bindingFuture
    .flatMap(_.unbind()) // trigger unbinding from the port
    .onComplete(_ => system.terminate()) …
Run Code Online (Sandbox Code Playgroud)

scala akka akka-http

8
推荐指数
1
解决办法
2032
查看次数

Hibernate 6 SchemaExport 类未找到

我使用类似导出 JPA 实体架构 DDL 的代码:

import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;

public class HibernateQueryGenerator {
    public static void main(String[] args) {
//        createSchema();
        updateSchema();
    }

    private static void addEntityClass(MetadataSources metadata) {
        // Scan entity packages and use : 
        // metadata.addAnnotatedClass(...);
    }

    private static void updateSchema() {
        MetadataSources metadata = getMetadataSources();
        SchemaUpdate schemaUpdate = new SchemaUpdate();
        schemaUpdate.setHaltOnError(true);
        schemaUpdate.setFormat(false);
        schemaUpdate.setDelimiter(";");
        schemaUpdate.execute(EnumSet.of(TargetType.STDOUT), metadata.buildMetadata());
    }

    private static void createSchema() {
        MetadataSources metadata = getMetadataSources();
        SchemaExport schemaExport = new SchemaExport();
        schemaExport.setHaltOnError(true);
        schemaExport.setFormat(false);
        schemaExport.setDelimiter(";");
        schemaExport.execute(EnumSet.of(TargetType.STDOUT), SchemaExport.Action.CREATE, metadata.buildMetadata());
    } …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa

7
推荐指数
1
解决办法
1794
查看次数

Akka-Http加载css和js资源

我想使用类似http服务器的akka​​-http(例如tomcat或nginx服务器).
使用这个简单的代码可以从Web浏览器加载html源代码,但无法加载链接在html文件上的其他源代码.

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer

import scala.io.StdIn

object MainRunner extends App {

  implicit val system = ActorSystem("mySystem")
  implicit val materializer = ActorMaterializer()
  implicit val ec = system.dispatcher

  val staticResources =
    get {
        path("admin") {
          getFromResource("admin/index.html")
        } ~ pathPrefix("admin") {
        getFromResourceDirectory("admin")
      }
    }

  val bindingFuture = Http().bindAndHandle(staticResources, "localhost", 8080)

  println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
  StdIn.readLine() // let it run until user presses return
  bindingFuture
    .flatMap(_.unbind()) // trigger unbinding from the port
    .onComplete(_ => system.terminate()) …
Run Code Online (Sandbox Code Playgroud)

sca akka akka-http

5
推荐指数
1
解决办法
2200
查看次数

未定义光滑列

我是scala slick的新手。
为什么在slick v3.1.1中找不到列和O,
请查看以下示例代码:

import slick.driver.PostgresDriver
import slick.lifted.Tag
import slick.model.Table ;

case class Person(id:Int,name:String)

class Persons(tag: Tag) extends Table[Person](tag , "PERSONS") {
    def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
    def name = column[String]("name", O.NotNull)
}    
Run Code Online (Sandbox Code Playgroud)

更新:
我使用此文档:http : //slick.lightbend.com/doc/3.1.1/gettingstarted.html#schema

scala slick

5
推荐指数
1
解决办法
667
查看次数

Java 和打字稿生成差异 PBKDF2 哈希

我想使用加密的 AES-GCM 数据(用于密码的 PBKDF2 哈希)在 java 和 typescript 之间进行通信。
我为 pbkdf2 使用了随机字节:

randomBytes(Base64): wqzowTahVBaxuxcN8vKAEUBEo0wOfcg4e6u4M9tPDFk=   
Run Code Online (Sandbox Code Playgroud)

这是我的 java PBKDF2 代码:

    private String salt = "1234";
    private static final String KEY_ALGORITHM = "AES";
    private Key generateKey(byte[] randomBytes) throws Exception {
        var randomPassword = new String(randomBytes);
        KeySpec keySpec = new PBEKeySpec(randomPassword.toCharArray(), salt.getBytes(), 10000, 256);
        SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
        var kdf2SecurePassword = secretKeyFactory.generateSecret(keySpec).getEncoded();
        return new SecretKeySpec(kdf2SecurePassword, KEY_ALGORITHM);
    }   
Run Code Online (Sandbox Code Playgroud)

这是打字稿代码:

  private static importKey(randomBytes: ArrayBuffer) {
    return crypto.subtle.importKey(
      'raw',
      randomBytes,
      {name: 'PBKDF2', length: 256},
      true,
      ['deriveKey']
    ); …
Run Code Online (Sandbox Code Playgroud)

javascript java typescript angular java-11

5
推荐指数
1
解决办法
557
查看次数

自由激活@MessageDriven

我想在 Liberty 应用程序服务器上激活自定义消息侦听器。

这是我的代码:

@MessageDriven(name = "Receiver")
public class Receiver implements InboundListener {

    @Override
    public void receiveMessage(String message) {
        System.out.println("Message Received : " + message);
    }
}      
Run Code Online (Sandbox Code Playgroud)

这是 server.xml :

<?xml version="1.0" encoding="UTF-8"?>
<server description="Dandelion IOT server">
    <featureManager>
        <feature>cdi-2.0</feature>
        <feature>beanValidation-2.0</feature>
        <feature>appSecurity-3.0</feature>
        <feature>jpa-2.2</feature>
        <feature>jaxrs-2.1</feature>
        <feature>jsonb-1.0</feature>
        <feature>jsonp-1.1</feature>
        <feature>managedBeans-1.0</feature>
        <feature>websocket-1.1</feature>
        <feature>ejbLite-3.2</feature>
        <feature>jca-1.7</feature>
        <feature>jndi-1.0</feature>
        <feature>mdb-3.2</feature>
        <feature>localConnector-1.0</feature>
    </featureManager>
    <library id="DandelionLibs">
        <fileset dir="/etc/dandelion/lib" includes="*.jar"/>
    </library>
    <jdbcDriver id="database-driver" libraryRef="DandelionLibs"/>
    <dataSource jndiName="JTA-DataSource" transactional="true" jdbcDriverRef="database-driver">
        <properties databaseName="${database.name}" serverName="${database.hostname}" portNumber="${database.port}"
                    user="${database.username}" password="${database.password}"/>
    </dataSource>

    <resourceAdapter id="dra" autoStart="true" location="/etc/dandelion/lib/RA.rar"/>

    <connectionFactory jndiName="h5/sampleConnection">
        <properties.dra/> …
Run Code Online (Sandbox Code Playgroud)

jca websphere-liberty open-liberty java-ee-8 jakarta-ee

5
推荐指数
1
解决办法
259
查看次数

Google Protobuf 处理空值

有人解释我如何处理 google protobuf 中的空值。
我有这样的结构:

syntax = "proto3";
import "google/protobuf/wrappers.proto";
message Person {
  google.protobuf.DoubleValue age = 4;
}     
Run Code Online (Sandbox Code Playgroud)

和java代码:

DoubleValue myAge = null;
Person build = Person.newBuilder()
                .setAge(myAge)  // <- NPE
                .build();
Run Code Online (Sandbox Code Playgroud)

此代码导致.setAge(myAge)在线出现空指针异常。
那么 protobuf DoubleValue 的用例是什么?我以为它是用来管理空值的。但仍然收到 NullPointerException 。

您使用这样的代码来处理这个问题吗?

DoubleValue a = null;
Person.Builder builder = Person.newBuilder();
if (a != null) {
    builder.setAge(a);
}

Person build = builder.build();     
Run Code Online (Sandbox Code Playgroud)

更新:
这是 protoc 命令生成的代码的一部分:

/**
* <code>.google.protobuf.DoubleValue age = 9;</code>
*/
public Builder setAge(com.google.protobuf.DoubleValue value) {
if (ageBuilder_ == …
Run Code Online (Sandbox Code Playgroud)

java protocol-buffers

5
推荐指数
1
解决办法
8463
查看次数

Scala空类,对象,特征

我想学习scala语言.
在许多文档或视频教程中,我看到scala开发人员创建空类或对象,并在另一个类上使用它作为参数或实现空特征!
例如 :

object Controller {
  sealed trait Controller
  case object Login extends Controller
  case object Logout extends Controller
}
Run Code Online (Sandbox Code Playgroud)

或这个 :

sealed trait Expression
case class Number(num: Int) extends Expression
case class Plus(a: Expression, b: Expression) extends Expression
case class Minus(a: Expression, b: Expression) extends Expression

object ExpressionEvaluate {
  def value(expression: Expression): Int = expression match {
    case Number(value) => value
    case Plus(a, b) => value(a) + value(b)
    case Minus(a, b) => value(a) - value(b)
  }
}
Run Code Online (Sandbox Code Playgroud)

我想知道这种模式是什么? …

scala

4
推荐指数
1
解决办法
1114
查看次数

Crypto-JS 总是返回新的哈希值

我想在我的 angular 8 应用程序上使用crypto-js
这是我的示例代码:

import {Injectable} from '@angular/core';
import * as CryptoJS from 'crypto-js';

@Injectable()
export class HprotoService {

  public enc(msg: string): string {
    return CryptoJS.AES.encrypt(msg, '1234').toString();
  }

  public dec(encMsg: string): string {
    return CryptoJS.AES.decrypt(encMsg, '1234').toString(CryptoJS.enc.Utf8);
  }
}
Run Code Online (Sandbox Code Playgroud)

和我的组件:

import {Component} from '@angular/core';
import {HprotoService} from './hproto.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  private hproto: HprotoService;

  constructor(hproto: HprotoService) {
    this.hproto = hproto;
  }

  public encrypt() {
    console.log(this.hproto.enc('Hello dear !!!'));
  }
} …
Run Code Online (Sandbox Code Playgroud)

javascript cryptojs angular

4
推荐指数
1
解决办法
996
查看次数

Java 8流计算在整个列表上

我在youtube(venkat subramaniam)上看到了让我们变得懒惰:探索流的真正力量。(约26-30分钟)

在示例中,一个for循环:

List<Integer> numbers = Arrays.asList(1, 2, 3, 5, 4, 6, 7, 8, 9, 10);
int result = 0;
for(int e: values){
  if(e > 3 && e % 2 == 0){
    result = e * 2;
    break;
  }
}  
Run Code Online (Sandbox Code Playgroud)

有8个“单位操作”

根据他的例子:

public class MainClass {
    public static void main(String[] args) {

        List<Integer> numbers = Arrays.asList(1, 2, 3, 5, 4, 6, 7, 8, 9, 10);

        System.out.println(
                numbers.stream()
                        .filter(e -> e > 3)
                        .filter(e -> e % 2 == …
Run Code Online (Sandbox Code Playgroud)

java stream java-8 java-stream

3
推荐指数
1
解决办法
105
查看次数

ConstraintValidator 两次调用 isValid() 方法

任何 Body 解释我为什么 ConstraintValidator 类的 isValid() 方法被调用两次?
例如,这是我的示例代码:

@POST
@Path("/json/dog")
@Produces("application/json")
@Consumes("application/json")
public Response getDogByJson(@ValidAnimal JsonObject jsonObject) {
      return Response.ok("ok").build();
}



@Constraint(validatedBy = {AnimalValidation.class})
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface ValidAnimal {

    String message() default "This is not valid !";

    Class<?>[] groups() default { };

    Class<? extends Payload>[] payload() default { };
}   



public class AnimalValidation implements ConstraintValidator<ValidAnimal, JsonObject> {

    @Override
    public void initialize(ValidAnimal constraintAnnotation) {

    }

    @Override
    public boolean isValid(JsonObject jsonObject, ConstraintValidatorContext context) {
        System.out.println(">>>>>> : " + jsonObject);
        return true; …
Run Code Online (Sandbox Code Playgroud)

jax-rs jersey open-liberty java-ee-8 jakarta-ee

2
推荐指数
1
解决办法
352
查看次数

Scala实现多种泛型类型

请查看此类:

class MainClass(firstName:String) extends GenericClass[(Int,String,Long)](firstName,"David")
class GenericClass[T](str1: String, str2: String)    
Run Code Online (Sandbox Code Playgroud)

Scala如何实现并将多个类型映射到单个泛型类型?
我的意思是GenericClass仅具有一个Single类型,GenericClass[T]但MainClass对此进行了扩展并实现了多个类型GenericClass[(Int,String,Long)]

我在光滑的orm上学习了这段代码:

class Suppliers(tag: Tag) extends Table[(Int, String, String, String, String, String)](tag, "SUPPLIERS") { ... }
Run Code Online (Sandbox Code Playgroud)

可以用Java语言做到这一点吗?

scala

2
推荐指数
1
解决办法
46
查看次数