我正在尝试将基于Spring MVC的REST应用程序迁移到Jboss 7.1.0.在启动时,Jboss初始化显示一切都已正确启动,所有war文件都已成功部署.
我在Spring MVN和Jboss的RestEasy服务之间进行集成时遇到了很多问题,我想知道这是否是jboss resteasy与Spring MVN之间的另一个冲突.
当我向REST服务发出请求时,我收到以下错误:
12:52:31,541 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-5) Root WebApplicationContext: initialization completed in 3035 ms
12:52:31,845 INFO [org.jboss.web] (MSC service thread 1-5) JBAS018210: Registering web context: /MyRestService
12:52:31,875 INFO [org.jboss.as] (MSC service thread 1-5) JBAS015874: JBoss AS 7.1.0.Final "Thunder" started in 53526ms - Started 390 of 468 services (72 services are passive or on-demand)
12:52:32,034 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "MyRestService.war"
12:54:10,117 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MyRestService]] (http--127.0.0.1-8080-1) StandardWrapper.Throwable: java.lang.RuntimeException: Unable to find a …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用特定的命名空间构建XML文档.我想要生成的最终文档看起来像这样:
<m:documentObject xmlns:m="http://www.myschema.com">
<sender>token</sender>
<receiver>token</receiver>
<payload>token</payload>
</m:documentObject>
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所拥有的.
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element requestElement = document.createElementNS("http://www.myschema.com", "documentObject");
document.appendChild(requestElement);
Element sender = document.createElement("sender");
requestElement.appendChild(sender);
Text senderText = document.createTextNode("Xmlsender");
sender.appendChild(senderText);
Element receiver = document.createElement("receiver");
requestElement.appendChild(receiver);
Text receiverText = document.createTextNode("Xmlreceiver");
receiver.appendChild(receiverText);
Element payload = document.createElement("payload");
requestElement.appendChild(payload);
Text payloadText = document.createTextNode("Xmlpayload");
payload.appendChild(payloadText);
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(requestElement);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
transformer.transform(source, result);
String xmlString = sw.toString();
System.out.println(xmlString) …Run Code Online (Sandbox Code Playgroud) 我正在处理一个我需要根据分隔符进行拆分的文件.
以下代码显示为我正在处理的文件定义的分隔符
private static final String component = Character.toString((char) 31);
private static final String data = Character.toString((char) 29);
private static final String segment = Character.toString((char) 28);
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下这些特定分隔符的意义吗?
查看ASCII代码,这些分隔符是文件,组和单元分隔符.我真的不明白这意味着什么.
我正在尝试从Oracle 10G(在UNIX上)连接到SQL Server数据库(在Windows上).我查看了手册,我承认我发现文档很难遵循.似乎有几个选项可供使用,但没有一个文档描述每个选项的工作原理.
作为一个例子,我已经获得了有关我需要连接的数据库的以下信息(即SQL Server数据库)
为了连接上面我做了以下更改
HS_FDS_CONNECT_INFO = data_extract
HS_FDS_TRACE_LEVEL = 0
Run Code Online (Sandbox Code Playgroud)
sqlserver.db =
(DESCRIPTION =
(ADDRESS = (protocol=tcp)(host=10.10.10.10)(port=49400))
(connect_data = (sid=data_extract))
(hs=ok)
)
Run Code Online (Sandbox Code Playgroud)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = merlin)(PORT = 1525))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u/app/oracle/product/10.2.0/db)
(PROGRAM = …Run Code Online (Sandbox Code Playgroud) 使用Spring-WS时,配置非常小,因为我一直在使用注释.最近我一直试图测试如何在SOAP响应中包含附件并使其工作我最终得到了以下配置.
<bean id="messageReceiver"
class="org.springframework.ws.soap.server.SoapMessageDispatcher">
<property name="endpointAdapters">
<list>
<ref bean="defaultMethodEndpointAdapter" />
</list>
</property>
</bean>
<bean id="defaultMethodEndpointAdapter"
class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
<property name="methodArgumentResolvers">
<list>
<!-- Be careful here! You might need to add more processors if you do
more than webservices! -->
<ref bean="marshallingPayloadMethodProcessor" />
</list>
</property>
<property name="methodReturnValueHandlers">
<list>
<ref bean="marshallingPayloadMethodProcessor" />
</list>
</property>
</bean>
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.mypackage.ws" />
<property name="mtomEnabled" value="true" />
</bean>
<bean id="marshallingPayloadMethodProcessor"
class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
<constructor-arg ref="marshaller" />
<constructor-arg ref="marshaller" />
</bean>
Run Code Online (Sandbox Code Playgroud)
通过上面的内容,我可以生成带附件的SOAP响应.问题是我真的不明白发生了什么.(即上述配置是做什么的,可以启用MTOM附件.
要启用附件:
为什么我需要配置JAXB marshaller?没有此配置,所有不使用附件的Web服务都可以正常工作.我所要做的就是使用@EndPoint注释.非附件Web服务的请求/响应对象也是基于JAXB的,所以这表明我可能没有做到这一点(即使它有效).
上面配置中显示的messageReceiver和defaultmethodEndpointAdapter bean的用途是什么?没有这些,非附件端点工作正常.
最后是否可以注释上述任何配置而不是XML?我注意到JAX-WS有一个@MTOM注释但是找不到Spring-WS的等价物 …
有人可以在对象锁定的上下文中解释这两个例子之间的区别:
public void method1(){
synchronized(this){
....
}
}
Run Code Online (Sandbox Code Playgroud)
和
StringBuffer aStringBufferObject = new StringBuffer("A");
public void method2(){
synchronized(aStringBufferObject){
....
}
}
Run Code Online (Sandbox Code Playgroud)
我知道第一个示例将获取this实例上的锁,第二个示例将获取aStringBufferObject实例的锁.但我真的不明白两者的影响或区别.
例如,在第二个示例中,线程是否仍然能够执行synchronized块内的代码,因为锁与'this'实例无关?
我知道同步一个方法或一个代码块会阻止多个线程同时访问该块/方法,但指定要锁定的对象的目的是什么,以及指定对象的方式有何不同上面的例子?
扩展和装箱Java原语.
我知道不可能将包装类从一个扩展到另一个,因为它们不是来自同一个继承树.为什么不能将原语扩展到另一个原始类型并自动放大加宽的原语?
鉴于可以将一个byte参数传递给一个需要int的方法,为什么以下示例中的字节不能扩展为int然后装箱为Integer?
class ScjpTest{
static void goInteger(Integer x){
System.out.println("Going with an Integer");
}
static void goInt(int x){
System.out.println("Going with an int");
}
public static void main(String args[]){
byte b = 5;
goInt(b);
goInteger(b);
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,goInt(b)编译器接受但goInteger(b)被拒绝.
在以下示例中:
class Base {
int x=10;
Base() {
show();
}
void show() {
System.out.print ("Base Show " +x + " ");
}
}
class Child extends Base {
int x=20;
Child() {
show();
}
void show() {
System.out.print("Child Show " + x +" ") ;
}
public static void main( String s[ ] ) {
Base obj = new Child();
}
}
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)Child Show 0 Child Show 20
我认为这里发生的是超级构造函数调用子的show()方法,因为这个方法在Child中被重写.因为它已被覆盖,但为什么x 0的值和为什么它能够在超级构造函数完成之前访问此方法?
我正在尝试创建一个简单的Spring Web服务,在调用时返回文件附件作为SOAP响应的一部分.Enpoint类如下所示:
最后是终点
@PayloadRoot(namespace="http://ws.mypackage.com", localPart="downloadMessageRequest")
@ResponsePayload
public JAXBElement<DownloadResponseType> invoke(@RequestPayload DownloadMessageRequest req) throws Exception {
DownloadResponseType response = new DownloadResponseType();
DownloadResponseType.PayLoad payload = new DownloadResponseType.PayLoad();
javax.activation.DataHandler dataHandler = new javax.activation.DataHandler(new FileDataSource("c:\\temp\\maven-feather.png"));
payload.setMessagePayLoad(dataHandler);
response.setPayLoad(payload);
return objectFactory.createDownloadMessageResponse(response);
}
Run Code Online (Sandbox Code Playgroud)
我希望响应将文件包含为类似于以下响应的附件:
Content-Type: multipart/related; boundary=MIMEBoundary4A7AE55984E7438034;
type="application/xop+xml"; start="<0.09BC7F4BE2E4D3EF1B@apache.org>";
start-info="text/xml; charset=utf-8"
--MIMEBoundary4A7AE55984E7438034
content-type: application/xop+xml; charset=utf-8; type="application/soap+xml;"
content-transfer-encoding: binary
content-id: <0.09BC7F4BE2E4D3EF1B@apache.org>
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="...."....>
........
<xop:Include href="cid:1.A91D6D2E3D7AC4D580@apache.org"
xmlns:xop="http://www.w3.org/2004/08/xop/include">
</xop:Include>
........
</soapenv:Envelope>
--MIMEBoundary4A7AE55984E7438034
content-type: application/octet-stream
content-transfer-encoding: binary
content-id: <1.A91D6D2E3D7AC4D580@apache.org>
Binary Data.....
--MIMEBoundary4A7AE55984E7438034--
Run Code Online (Sandbox Code Playgroud)
我试图遵循spring-ws示例中的文档和示例代码,由于某种原因,我得到的输出总是这样(即base64数据不是附件.
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1 …Run Code Online (Sandbox Code Playgroud) 我需要得到上周一和周五的日期.为此,我将获得本周一的日期并减去7天.这给了我上周一的星期一.
为了得到星期五的日期,我必须加上4.这让我感到困惑,因为出于某种原因,一周的第一天是星期日,而不是星期一在英国.
无论如何,这是我如何得到日期.
// Get the dates for last MON & FRI
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
cal.add(Calendar.DAY_OF_WEEK, -7);
cal.set(Calendar.HOUR_OF_DAY,0);
cal.set(Calendar.MINUTE,0);
cal.set(Calendar.SECOND,0);
cal.set(Calendar.MILLISECOND,0);
// Get the date on Friday
cal.add(Calendar.DAY_OF_WEEK, 4);
cal.set(Calendar.HOUR_OF_DAY,23);
cal.set(Calendar.MINUTE,59);
cal.set(Calendar.SECOND,59);
cal.set(Calendar.MILLISECOND,0);
Run Code Online (Sandbox Code Playgroud)
上述工作,但我感兴趣,如果逻辑有任何问题.即它适用于Februarys,闰年等.
随意建议更好的解决方案/方法.
谢谢