2016-05-24 24 views
0

我試圖發送一個信息的web服務SECURITE但我有以下錯誤,當他要告訴我答案錯誤壁壘接收

[錯誤]預計加密部分缺失 org.apache。 axis2.AxisFault:預期缺少 在org.apache.rampart.handler.RampartReceiver.setFaultCodeAndThrowAxisFault(RampartReceiver.java:186) 加密部分在org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:99) 在org.apache.axis2.engine.Phase.invokeHandler(Phase.java:335) 在org.apache.axis2.engine.Phase.invoke(Phase.java:308) org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:250) 在org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:156) 在org.apache.axis2.description。 OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:357) 在org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:414) 在org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225) 在org.apache.axis2.client.OperationClient.execute(OperationClient.java:150) 在tutorial.somar.Soma001SNAPSHOTStub.add(Soma001SNAPSHOTStub.java:190) 在tutorial.somar.teste2.main(teste2.java: 65) 引起:org.apache.rampart.RampartException:預期加密部分缺少一個 噸org.apache.rampart.PolicyBasedResultsValidator.validateEncrSig(PolicyBasedResultsValidator.java:276) 在org.apache.rampart.PolicyBasedResultsValidator.validate(PolicyBasedResultsValidator.java:153) 在org.apache.rampart.RampartEngine.process(RampartEngine.java :280) at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92) ... 10更多 線程「main」中的異常org.apache.axis2.AxisFault:預期的加密部分丟失 at org.apache.rampart.handler.RampartReceiver.setFaultCodeAndThrowAxisFault(RampartReceiver.java:186) at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:99) at org.apache.axis2.engine.Phase。 invokeHandler(Phase.java:335) at org.apache.ax is2.engine.Phase.invoke(Phase.java:308) 在org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:250) 在org.apache.axis2.engine.AxisEngine.receive(AxisEngine。的java:156) 在org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:357) 在org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:414) 在org.apache。 axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225) 在org.apache.axis2.client.OperationClient.execute(OperationClient.java:150) 在tutorial.somar.Soma001SNAPSHOTStub.add(Soma001SNAPSHOTStub.java:190) 在tutorial.somar.teste2.main(teste2.java:65) 所致:org.apache.rampart.RampartException :預期缺少 在org.apache.rampart.PolicyBasedResultsValidator.validateEncrSig(PolicyBasedResultsValidator.java:276) 加密部在org.apache.rampart.PolicyBasedResultsValidator.validate(PolicyBasedResultsValidator.java:153) 在org.apache.rampart.RampartEngine .process(RampartEngine.java:280) 在org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92) ...... 10多個

我在服務器上使用Maven的:

這裏的服務。XML

<module ref="rampart"/> 

<parameter name="ServiceClass" locked="false">tutorial.somar.SecureService</parameter> 

<operation name="add"> 
    <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> 
</operation> 

<sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> 
       <wsp:Policy> 
         <sp:MustSupportRefKeyIdentifier/> 
         <sp:MustSupportRefIssuerSerial/> 
       </wsp:Policy> 
      </sp:Wss10> 

    <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> 
    <sp:Body/> 
    </sp:SignedParts> 
    <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> 
    <sp:Body/> 
    </sp:EncryptedParts> 

    <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> 
    <ramp:user>serverkey</ramp:user> 
    <ramp:encryptionUser>clientkey</ramp:encryptionUser> 
    <ramp:passwordCallbackClass>tutorial.somar.PWCBHandler</ramp:passwordCallbackClass> 

    <ramp:signatureCrypto> 
     <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin"> 
     <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.type">JKS</ramp:property> 
     <ramp:property name="org.apache.ws.security.crypto.merlin.file">server.keystore</ramp:property> 
     <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">nosecret</ramp:property> 
     </ramp:crypto> 
    </ramp:signatureCrypto> 

    <ramp:encryptionCrypto> 
     <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin"> 
     <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.type">JKS</ramp:property> 
     <ramp:property name="org.apache.ws.security.crypto.merlin.file">server.keystore</ramp:property> 
     <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">nosecret</ramp:property> 
     </ramp:crypto> 
    </ramp:encryptionCrypto> 

    </ramp:RampartConfig> 

</wsp:All> 

和SecureService.java

public int add(int a, int b) { 
    System.out.println(a+b); 
    return a+b; 
} 

我的WS-的客戶是這樣的:

public class teste2 { 
private static Policy loadPolicy(String name) throws XMLStreamException{ 
    ClassLoader loader = teste2.class.getClassLoader(); 
    InputStream resource = loader.getResourceAsStream(name); 
    StAXOMBuilder builder = new StAXOMBuilder(resource); 
    return PolicyEngine.getPolicy(builder.getDocumentElement()); 
} 

public static void main (String[] args) throws XMLStreamException, RemoteException{ 
    /*if(args.length < 4){ 
     System.out.println("Usage:\n java " + 
       "com.sosnoski.ws.library.adb.WebServiceClient protocol host port path"); 
     System.exit(1); 
    }*/ 

    //String target = args[0] + "://" + args[1] + ":" + args[2] + args[3]; 
    String target = "http://localhost:8070/axis2/services/soma-0.0.1-SNAPSHOT"; 
    System.out.println("Connecting to " + target); 

    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("client-repo", null); 

    Soma001SNAPSHOTStub stub = new Soma001SNAPSHOTStub(ctx ,target); 
    //FacebookStub stub = new FacebookStub(target); 

    ServiceClient client = stub._getServiceClient(); 
    Options options = client.getOptions(); 

    Policy policy = loadPolicy("signencr-policy-client.xml"); 
    //Policy policy = loadPolicy("policy.xml"); 
    //Policy policy = loadPolicy("sign-policy-client.xml"); 
    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy); 
    options.setUserName("libuser"); 
    options.setPassword("books"); 
    client.engageModule("rampart"); 


    int a = 4; 
    int b = 4; 
    Add n = new Add(); 

    n.setA(a); 
    n.setB(b); 
    AddResponse result = stub.add(n); 

    System.out.println(a + " + " + b + " = " + result.get_return()); 
} 

}

我使用Axis2 1.7.1,1.7.0壘

回答

0

我解決了這個問題......我只是換了那條線

<sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never"/> 

<sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never"> 
       <wsp:Policy> 
       <sp:RequireThumbprintReference/> 
      </wsp:Policy> 
      </sp:X509Token> 

和平。