在基于RESTful的应用程序中管理状态

我们正在评估用于基于Web的应用程序的技术,并且一些建议是采用基于RESTful的服务方法。 技术堆栈 1)Spring 2)Apache CXF(JAX-RS) 我的问题是 1)如何在请求之间管理状态。 例如,用户已经过身份validation,现在他正在发出一系列请求,让我们通过分页报告。 我想这会是这样的URL domain.com/reports/customreport/page/1 domain.com/reports/customreport/page/2等… a)存储用户信息和请求参数的位置,以便可以在请求之间共享。 b)让我们说结果是流式传输,Rowset存储在哪里? 是否有类似于Petclinic的完整示例应用程序可以为此类应用程序提供最佳实践。

无法使用GCS客户端库+ java将文件从GAE项目上传到Google云存储

我正在尝试使用新的Gcs客户端库从我的GAE应用程序上传图像/文件到谷歌云存储。 这是代码片段 GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder() .initialRetryDelayMillis(10) .retryMaxAttempts(10) .totalRetryPeriodMillis(15000) .build()); GcsFilename filename = new GcsFilename(BUCKETNAME, FILENAME); GcsFileOptions options = new GcsFileOptions.Builder().mimeType(“text/html”).acl(“public-read”).build(); GcsOutputChannel writeChannel = gcsService.createOrReplace(filename,options); PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, “UTF8”)); out.println(“The woods are lovely dark and deep.”); out.println(“But I have promises to keep.”); out.flush(); writeChannel.waitForOutstandingWrites(); writeChannel.write(ByteBuffer.wrap(“And miles to go before I sleep.”.getBytes())); writeChannel.close(); […]

重命名由Java Servlet流式传输的PDF

使用XSLT,XSL-FO和Apache FOP的正确组合,我可以将PDF发送到某个浏览器窗口。 实际上,我发送的文件内容如下: response.setContentType( “应用/ PDF”); response.setContentLength(out.size()); response.getOutputStream()。write(out.toByteArray()); response.getOutputStream()平齐(); 正如所料,浏览器在名为“pdf”的选项卡中显示PDF内容,如果我在本地保存文件,则名称也默认为pdf.pdf 如何强制文件名? 我尝试了以下其他不起作用的东西: response.setHeader(“Content-Disposition”,“inline; filename =”+ filename +“。pdf”); 为清楚起见,我想在浏览器中显示内容(而不是直接下载)

使用JSch拒绝权限

我正在尝试使用JSch从sftp服务器检索一些文件,但我收到以下错误。 3: Permission denied at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846) at com.jcraft.jsch.ChannelSftp._realpath(ChannelSftp.java:2340) at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:342) at com.company.common.sftp.impl.managedFile.moveFiles(managedFile.java:712) 这是代码: private List moveFiles(String prefixFileName, String path) { Session session = getSession(); Channel channel = connect(session); ChannelSftp channelSftp = null; try { channelSftp = (ChannelSftp)channel; channelSftp.cd(_workingDir); … } … finally { channel.disconnect(); session.disconnect(); } } public Session getSession() { Session session = null; […]

从Storm bolt中将行插入HBase

我希望能够从分布式(非本地)Storm拓扑中将新条目写入HBase。 存在一些GitHub项目,它们提供HBase Mappers或预先制作的Storm bolt来将元组写入HBase。 这些项目提供了在LocalCluster上执行样本的说明。 我遇到这两个项目并直接从bolt中访问HBase API的问题是它们都需要将HBase-site.xml文件包含在类路径中。 使用直接API方法,也可能使用GitHub方法,当您执行HBaseConfiguration.create(); 它将尝试从类路径上的条目中查找所需的信息。 如何修改storm bolt的类路径以包含Hbase配置文件? 更新:使用danehammer的答案,这就是我的工作方式 将以下文件复制到〜/ .storm目录中: HBase的-共0.98.0.2.1.2.0-402-hadoop2.jar HBase的-site.xml中 storm.yaml:注意:如果你没有将storm.yaml复制到该目录中,那么storm jar命令将不会在类路径中使用该目录(请参阅storm.py python脚本以查看自己的逻辑 – 如果这被记录在案) 接下来,在拓扑类的main方法中获取HBase配置并对其进行序列化: final Configuration hbaseConfig = HBaseConfiguration.create(); final DataOutputBuffer databufHbaseConfig = new DataOutputBuffer(); hbaseConfig.write(databufHbaseConfig); final byte[] baHbaseConfigSerialized = databufHbaseConfig.getData(); 通过构造函数将字节数组传递给spout类。 spout类将此字节数组保存到字段中(不要在构造函数中反序列化。我发现如果spout有一个Configuration字段,你将在运行拓扑时得到一个无法序列化的exception) 在spout的open方法中,反序列化配置并访问hbase表: Configuration hBaseConfiguration = new Configuration(); ByteArrayInputStream bas = new ByteArrayInputStream(baHbaseConfigSerialized); hBaseConfiguration.readFields(new DataInputStream(bas)); HTable […]

具有多个数据源Oracle和H2的Spring Boot

我为我的角项目开发了一个Spring Boot RestController并遇到了问题。 在我的rest服务逻辑中,我使用了两个不同的数据库来获取数据。 在这里您可以看到数据源配置: [application.properties] #datasource1 spring.datasource.url=[url] spring.datasource.username=[username] spring.datasource.password=[password] spring.datasource.driverClassName=org.h2.Driver #datasource2 spring.secondDatasource.url=[url] spring.secondDatasource.username=[username] spring.secondDatasource.password=[password] spring.secondDatasource.driverClassName=oracle.jdbc.OracleDriver [DatasourceConfig.java] @Bean @Primary @ConfigurationProperties(prefix=”spring.datasource”) public DataSource h2DataSource() { return DataSourceBuilder.create().build(); } @Bean @ConfigurationProperties(prefix=”spring.secondDatasource”) public DataSource oracleDataSource() { return DataSourceBuilder.create().build(); } 记录输出:(此问题不会引发exception) … 2016-11-22 13:20:25.853 [INFO ] 1 [main] dbsApplication : Started Application in 7.757 seconds (JVM running for 12.515) […]

使用JBOSS和java以编程方式创建子域

现在我正在使用JSF,SEAM和Primefaces在JBOSS 7.1上开发一个应用程序。 该应用程序提供用户注册。 我需要的是当用户注册昵称的帐户,例如“andrew”时,他的个人资料将被公开访问为andrew.mysite.com。 我该如何以编程方式实现它。 提前致谢, 伊利亚西多罗维奇

块中java变量的范围是什么?

我知道在c ++变量中有块作用域,例如,下面的代码在C ++中有效 void foo(){ int a = 0; for(int i = 0; i < 10; ++i){ int a = 1; //re-define a here. } } 但是这个片段在java中不起作用,它报告“重复的局部变量a”,它是否意味着java变量没有BLOCK范围?

拖动JPanel

我在尝试拖动JPanel时遇到了问题。 如果我纯粹在MouseDragged中实现它: public void mouseDragged(MouseEvent me) { me.getSource().setLocation(me.getX(), me.getY()); } 我得到了移动物体一直在两个位置之间弹跳的奇怪效果(产生更多“拖动”事件)。 如果我按照这篇文章中描述的方式进行,但是: public void mouseDragged(MouseEvent me) { if (draggedElement == null) return; me.translatePoint(this.draggedXAdjust, this.draggedYAdjust); draggedElement.setLocation(me.getX(), me.getY()); } 我得到的元素弹跳效果要少得多,但它仍然可见,元素只移动鼠标指针的一半。 为什么会发生这种情况/如何解决这种情况?

Web Developer希望学习桌面编程

我是一名Web开发人员(Java和ColdFusion),他想学习编写一些简单的桌面应用程序。 其中大部分都适用于Windows,但在可以跨平台的程序中进行编程会很酷。 我从来没有真正想过用Java编写桌面编程,尽管我愿意再给它一次。 关于什么可能是开始的好地方的任何建议?