小编Cra*_*aig的帖子

处理带有 XML 数据的传入 SOAPMessage 时出错

我正在开发一个 Web 服务,它将两个字符串值作为输入参数。第一个标识用于导入 xml 数据的服务,第二个是 XML 数据字符串。这是 SOAP 请求的示例

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.dataexchange.xxx.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:importDataExchange>
         <ServiceID>XmlImportServiceName</ServiceID>
         <ExchangeData><?xml version="1.0" encoding="UTF-8"?><srv:exchange xmlns:cnt="Container" xmlns:core="Core" xmlns:srv="Service" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="Service http://xxx/xxx.xsd"></srv:exchange></ExchangeData>
      </web:importDataExchange>
   </soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

不幸的是,每当我尝试解析 SOAPMessage 时,都会收到以下错误:

javax.xml.bind.UnmarshalException
 - with linked exception:
[com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.
 at [row,col {unknown-source}]: [6,28]]
Run Code Online (Sandbox Code Playgroud)

这显然是因为我实现的 JAX-WS 正在尝试解组元素的内容<ExchangeData>。当然,这都可以通过将 的内容包装<ExchangeData><![CDATA[ ]]>元素中来解决,但是,我无法控制数据如何发送到服务器。因此,我需要一种方法来拦截 SOAPMessage 并将 ExchangeData 提取为字符串而不对其进行解组。或者,我需要一种方法让 Web 服务将 ExchangeData 节点的内容视为字符串,而不是 SOAPMessage 正文/有效负载中的另一个 XML 节点。

我尝试实现 SOAPHandler 和 …

java xml soap web-services

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

org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.addAnswersForStubbing 处的 java.lang.NullPointerException

例外

java.lang.NullPointerException 
    at org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.addAnswersForStubbing(PowerMockitoStubberImpl.java:67)
    at org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.when(PowerMockitoStubberImpl.java:42)
    at org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.when(PowerMockitoStubberImpl.java:105)
    at us.ny.state.ij.safeact.ask.facade.AmmoSellerKeeperFacadeBeanTest.setUp(FacadeBeanTest.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
Run Code Online (Sandbox Code Playgroud)

要模拟的代码

java.lang.NullPointerException 
    at org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.addAnswersForStubbing(PowerMockitoStubberImpl.java:67)
    at org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.when(PowerMockitoStubberImpl.java:42)
    at org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.when(PowerMockitoStubberImpl.java:105)
    at us.ny.state.ij.safeact.ask.facade.AmmoSellerKeeperFacadeBeanTest.setUp(FacadeBeanTest.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
Run Code Online (Sandbox Code Playgroud)

测试代码

BusinessServiceFactory serviceFactory = BusinessServiceFactory.getInstance();
RegBusinessServiceImpl regCreateService = 
    serviceFactory.getRegBusinessService(adrEntityManager);
Run Code Online (Sandbox Code Playgroud)

我不明白为什么我会看到异常。我将不胜感激任何建议。

mockito powermockito

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

如何将图片上传大小限制在2mb以下?

我有一个select用于上传图像的html 选项.

<div class="row smallMargin">
<div class="col-sm-6">
  Attach Image
</div>
<div class="col-sm-6">
  <input type="file" ng-model="image" accept="image/*">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

如何限制用户上传大于2MB的图像?

html javascript angularjs

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

需要使用其他类的字符串

我试图从另一个类访问一个类中的String.第一节课如下:

import java.sql.*;
import javax.swing.*;
import java.text.SimpleDateFormat;
import java.util.Date;


public class UseData {
Connection connection=null;

public void usePart1Part2(String part1, String part2, String part3, String part4) {
    SimpleDateFormat format = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
    String date = format.format(new Date());

    connection = SQliteConnectionClass.dbconnector();
    try {

        String value1 = part1;   //
        String value2 = part2;   //
        String value3 = part3;   //
        String value4 = part4;   // data need to be used in GenerateSummonPDF.java
        String Timestamp = date;
Run Code Online (Sandbox Code Playgroud)

value1到value4用于以下GenerateSummonPDF类:

public class GenerateSummonPDF {

    public static …
Run Code Online (Sandbox Code Playgroud)

java

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

标签 统计

java ×2

angularjs ×1

html ×1

javascript ×1

mockito ×1

powermockito ×1

soap ×1

web-services ×1

xml ×1