Java 类javax.xml.soap.SOAPMessage 实例源码

项目:satisfy    文件:WebserviceSteps.java   
private void sendSoapMessage(String filePath) throws SOAPException, NoSuchAlgorithmException, KeyManagementException, IOException, TransformerException {
    Map<Object, Object> currentSession = Thucydides.getCurrentSession();
    String webServicesEndpointUrl = (String) currentSession.get(WEB_SERVICE_ENDPOINT_URL_KEY);
    String webServiceSoapAction = (String) currentSession.get(WEB_SERVICE_SOAP_ACTION_KEY);
    SOAPMessage soapRequest = createSOAPMessageFromFile(filePath, webServiceSoapAction);
    SOAPMessage rawSoapResponse = callWebServiceMethod(soapRequest, webServicesEndpointUrl);
    LOGGER.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>START SOAP REQUEST>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    LOGGER.debug(convertToString(soapRequest));
    LOGGER.debug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<END SOAP REQUEST<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
    LOGGER.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>START SOAP RESPONSE>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    LOGGER.debug(convertToString(rawSoapResponse));
    LOGGER.debug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<END SOAP RESPONSE<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
    Thucydides.getCurrentSession().put(RESPONSE, rawSoapResponse);
    requestResponseDetails(String.format(TABLE_2_COLUMNS, "Actual SOAP Request", "Actual SOAP Response",
            convertToString(soapRequest), convertToString(rawSoapResponse)));
}
项目:openjdk-jdk10    文件:Stubs.java   
/**
 * Creates a new {@link Dispatch} stub that connects to the given pipe.
 *
 * @param portName
 *      see {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param owner
 *      see <a href="#param">common parameters</a>
 * @param binding
 *      see <a href="#param">common parameters</a>
 * @param clazz
 *      Type of the {@link Dispatch} to be created.
 *      See {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param mode
 *      The mode of the dispatch.
 *      See {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param next
 *      see <a href="#param">common parameters</a>
 * @param epr
 *      see <a href="#param">common parameters</a>
 * TODO: are these parameters making sense?
 */
@SuppressWarnings("unchecked")
    public static <T> Dispatch<T> createDispatch(QName portName,
                                             WSService owner,
                                             WSBinding binding,
                                             Class<T> clazz, Service.Mode mode, Tube next,
                                             @Nullable WSEndpointReference epr) {
    if (clazz == SOAPMessage.class) {
        return (Dispatch<T>) createSAAJDispatch(portName, owner, binding, mode, next, epr);
    } else if (clazz == Source.class) {
        return (Dispatch<T>) createSourceDispatch(portName, owner, binding, mode, next, epr);
    } else if (clazz == DataSource.class) {
        return (Dispatch<T>) createDataSourceDispatch(portName, owner, binding, mode, next, epr);
    } else if (clazz == Message.class) {
        if(mode==Mode.MESSAGE)
            return (Dispatch<T>) createMessageDispatch(portName, owner, binding, next, epr);
        else
            throw new WebServiceException(mode+" not supported with Dispatch<Message>");
    } else if (clazz == Packet.class) {
        return (Dispatch<T>) createPacketDispatch(portName, owner, binding, next, epr);
    } else
        throw new WebServiceException("Unknown class type " + clazz.getName());
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * Subsystem level service call. No NS on request. NS prefix on response.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test19WithWrappers() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:securityServer id:objectType=\"SERVER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:serverCode>server1</id:serverCode></xrd:securityServer><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><request><data>Request data</data></request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:securityServer id:objectType=\"SERVER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:serverCode>server1</id:serverCode></xrd:securityServer><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><xxprod:getRandomResponse xmlns:xxprod=\"http://foobar.x-road.ee/producer\"><xxprod:request><xxprod:data>Request data</xxprod:data></xxprod:request><xxprod:response><xxprod:data>Response data</xxprod:data></xxprod:response></xxprod:getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    SecurityServer securityServer = new SecurityServer("FI", "GOV", "MEMBER1", "server1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setSecurityServer(securityServer);
    request.setUserId("EE1234567890");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("xxprod");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, String> response = new ServiceResponse<String, String>(request.getConsumer(), request.getProducer(), request.getId());
    response.setResponseData("Response data");

    request.setProcessingWrappers(true);
    ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:DefaultServiceRequestSerializerTest.java   
/**
 * allowedMethos : member - member level service call.
 *
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test1() throws XRd4JException, SOAPException {
    String id = MessageHelper.generateId();
    String correctRequest = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"MEMBER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:serviceCode>allowedMethods</id:serviceCode></xrd:service><xrd:userId>user</xrd:userId><xrd:id>" + id + "</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><xrd:allowedMethods/></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", Constants.META_SERVICE_ALLOWED_METHODS);
    producer.setSubsystemCode(null);
    producer.setNamespacePrefix(Constants.NS_XRD_PREFIX);
    producer.setNamespaceUrl(Constants.NS_XRD_URL);
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, id);
    request.setUserId("user");

    ServiceRequestSerializer serializer = new DefaultServiceRequestSerializer();
    SOAPMessage msg = serializer.serialize(request);

    assertEquals(correctRequest, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:ServiceRequestSerializerTest.java   
/**
 * Member level service call.
 *
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test8() throws XRd4JException, SOAPException {
    String correctRequest = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"MEMBER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><ns1:request><ns1:data>1234567890</ns1:data></ns1:request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom");
    producer.setNamespacePrefix("ns1");
    producer.setNamespaceUrl("http://consumer.x-road.ee");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setRequestData("1234567890");

    ServiceRequestSerializer serializer = new TestRequestSerializer1();
    SOAPMessage msg = serializer.serialize(request);

    assertEquals(correctRequest, SOAPHelper.toString(msg));
}
项目:OpenJSharp    文件:StreamHeader.java   
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        // TODO what about in-scope namespaces
        // Not very efficient consider implementing a stream buffer
        // processor that produces a DOM node from the buffer.
        TransformerFactory tf = XmlUtil.newTransformerFactory();
        Transformer t = tf.newTransformer();
        XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
        DOMResult result = new DOMResult();
        t.transform(source, result);
        Node d = result.getNode();
        if(d.getNodeType() == Node.DOCUMENT_NODE)
            d = d.getFirstChild();
        SOAPHeader header = saaj.getSOAPHeader();
        if(header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        Node node = header.getOwnerDocument().importNode(d, true);
        header.appendChild(node);
    } catch (Exception e) {
        throw new SOAPException(e);
    }
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * Non-technical SOAP error with empty values.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void testSOAPNonTechErr2() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>6.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><request><data>Request data</data></request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>6.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><xxprod:getRandomResponse xmlns:xxprod=\"http://foobar.x-road.ee/producer\"><xxprod:request><xxprod:data>Request data</xxprod:data></xxprod:request><xxprod:response><faultcode/><faultstring/></xxprod:response></xxprod:getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setProtocolVersion("6.0");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("xxprod");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, String> response = new ServiceResponse<String, String>(request.getConsumer(), request.getProducer(), request.getId());
    response.setResponseData("Response data");

    ErrorMessage errorMsg = new ErrorMessage("", "");
    response.setErrorMessage(errorMsg);

    ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * Subsystem level service call. Response data in a Map. NS on request.
 * NS prefix on response.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test5() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><ns1:request><ns1:data>Request data</ns1:data></ns1:request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><prod:getRandomResponse xmlns:prod=\"http://foobar.x-road.ee/producer\"><prod:request><prod:data>Request data</prod:data></prod:request><prod:response><prod:field1>Field1</prod:field1><prod:field2>Field2</prod:field2><prod:field3>Field3</prod:field3></prod:response></prod:getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("prod");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, Map> response = new ServiceResponse<String, Map>(request.getConsumer(), request.getProducer(), request.getId());
    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put("field1", "Field1");
    map.put("field2", "Field2");
    map.put("field3", "Field3");
    response.setResponseData(map);

    ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl1();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * SOAP Fault with detail null.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void testSOAPFault3() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><request><data>Request data</data></request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>Fault code</faultcode><faultstring>Fault string</faultstring><faultactor>Fault actor</faultactor></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("xxprod");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, String> response = new ServiceResponse<String, String>();
    response.setResponseData("Response data");

    ErrorMessage errorMsg = new ErrorMessage("Fault code", "Fault string", "Fault actor", null);
    response.setErrorMessage(errorMsg);

    ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:AbstractServiceResponseSerializer.java   
private void processRequestNode(final SOAPBodyElement body, final ServiceResponse response,
                                final SOAPMessage soapRequest, final SOAPEnvelope envelope) throws SOAPException {
    boolean requestFound = false;
    NodeList list = soapRequest.getSOAPBody().getElementsByTagNameNS("*", response.getProducer().getServiceCode());
    if (list.getLength() == 1) {
        // Copy request from soapRequest
        requestFound = copyRequestNode((Node) list.item(0), body, response);
    }
    // It was not possible to copy the request element, so we must create it
    if (!requestFound) {
        SOAPElement temp = body.addChildElement(envelope.createName("request"));
        if (response.isAddNamespaceToRequest()) {
            LOGGER.debug("Add provider namespace to request element.");
            SOAPHelper.addNamespace(temp, response);
        }
    }
}
项目:jdk8u-jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    childGlobalNS.addNamespaceDeclaration("", null);
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * Subsystem level service call. No NS on request. Multiple NSs prefix on
 * response.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test14() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><request><data>Request data</data></request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><xxprod:getRandomResponse xmlns:xxprod=\"http://foobar.x-road.ee/producer\"><xxprod:request><xxprod:data>Request data</xxprod:data></xxprod:request><xxprod:response><ns1:responseData xmlns:ns1=\"http://ns1.com\" xmlns:ns2=\"http://ns2.com\"><ns1:data>Response data</ns1:data><ns2:data2>Response data 2</ns2:data2></ns1:responseData></xxprod:response></xxprod:getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("xxprod");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, SOAPElement> response = new ServiceResponse<String, SOAPElement>(request.getConsumer(), request.getProducer(), request.getId());
    response.setResponseData(SOAPHelper.xmlStrToSOAPElement(
            "<ns1:responseData xmlns:ns1=\"http://ns1.com\" xmlns:ns2=\"http://ns2.com\"><ns1:data>Response data</ns1:data><ns2:data2>Response data 2</ns2:data2></ns1:responseData>"));
    response.setForceNamespaceToResponseChildren(false);

    ServiceResponseSerializer serializer = new XMLServiceResponseSerializer();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * Subsystem level service call. No NS on request. NS prefix on response.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test1WithoutWrappers() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><data>Request data</data></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><xxprod:getRandomResponse xmlns:xxprod=\"http://foobar.x-road.ee/producer\"><xxprod:data>Response data</xxprod:data></xxprod:getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("xxprod");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, String> response = new ServiceResponse<String, String>(request.getConsumer(), request.getProducer(), request.getId());
    response.setResponseData("Response data");

    request.setProcessingWrappers(false);
    ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:ServiceRequestSerializerTest.java   
/**
 * Subsystem level service call. No NS prefix.
 *
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test16WithoutWrappers() throws XRd4JException, SOAPException {
    String correctRequest = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:securityServer id:objectType=\"SERVER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:serverCode>server1</id:serverCode></xrd:securityServer><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><getRandom xmlns=\"http://consumer.x-road.ee\"><data>1234567890</data></getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    SecurityServer securityServer = new SecurityServer("FI", "GOV", "MEMBER1", "server1");
    producer.setNamespacePrefix("");
    producer.setNamespaceUrl("http://consumer.x-road.ee");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setSecurityServer(securityServer);
    request.setUserId("EE1234567890");
    request.setRequestData("1234567890");

    request.setProcessingWrappers(false);
    ServiceRequestSerializer serializer = new TestRequestSerializer();
    SOAPMessage msg = serializer.serialize(request);

    assertEquals(correctRequest, SOAPHelper.toString(msg));
}
项目:OpenJSharp    文件:Stubs.java   
/**
 * Creates a new {@link Dispatch} stub that connects to the given pipe.
 *
 * @param portName
 *      see {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param owner
 *      see <a href="#param">common parameters</a>
 * @param binding
 *      see <a href="#param">common parameters</a>
 * @param clazz
 *      Type of the {@link Dispatch} to be created.
 *      See {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param mode
 *      The mode of the dispatch.
 *      See {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param next
 *      see <a href="#param">common parameters</a>
 * @param epr
 *      see <a href="#param">common parameters</a>
 * TODO: are these parameters making sense?
 */
@SuppressWarnings("unchecked")
    public static <T> Dispatch<T> createDispatch(QName portName,
                                             WSService owner,
                                             WSBinding binding,
                                             Class<T> clazz, Service.Mode mode, Tube next,
                                             @Nullable WSEndpointReference epr) {
    if (clazz == SOAPMessage.class) {
        return (Dispatch<T>) createSAAJDispatch(portName, owner, binding, mode, next, epr);
    } else if (clazz == Source.class) {
        return (Dispatch<T>) createSourceDispatch(portName, owner, binding, mode, next, epr);
    } else if (clazz == DataSource.class) {
        return (Dispatch<T>) createDataSourceDispatch(portName, owner, binding, mode, next, epr);
    } else if (clazz == Message.class) {
        if(mode==Mode.MESSAGE)
            return (Dispatch<T>) createMessageDispatch(portName, owner, binding, next, epr);
        else
            throw new WebServiceException(mode+" not supported with Dispatch<Message>");
    } else if (clazz == Packet.class) {
        return (Dispatch<T>) createPacketDispatch(portName, owner, binding, next, epr);
    } else
        throw new WebServiceException("Unknown class type " + clazz.getName());
}
项目:xrd4j    文件:DefaultServiceRequestSerializerTest.java   
/**
 * getSecurityServerMetrics.
 *
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test5() throws XRd4JException, SOAPException {
    String id = MessageHelper.generateId();
    String correctRequest = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>client</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>service</id:subsystemCode><id:serviceCode>getSecurityServerMetrics</id:serviceCode></xrd:service><xrd:securityServer id:objectType=\"SERVER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:serverCode>server1</id:serverCode></xrd:securityServer><xrd:userId>user</xrd:userId><xrd:id>" + id + "</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><m:getSecurityServerMetrics xmlns:m=\"http://x-road.eu/xsd/monitoring\"/></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "client");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "service", Constants.ENV_MONITORING_GET_SECURITY_SERVER_METRICS);
    SecurityServer securityServer = new SecurityServer("FI", "COM", "MEMBER2", "server1");
    producer.setNamespacePrefix(Constants.NS_ENV_MONITORING_PREFIX);
    producer.setNamespaceUrl(Constants.NS_ENV_MONITORING_URL);
    ServiceRequest<String> request = new ServiceRequest<>(consumer, producer, id);
    request.setSecurityServer(securityServer);
    request.setUserId("user");

    ServiceRequestSerializer serializer = new DefaultServiceRequestSerializer();
    SOAPMessage msg = serializer.serialize(request);

    assertEquals(correctRequest, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * Subsystem level service call. No NS on request. NS prefix on response.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test19WithoutWrappers() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:securityServer id:objectType=\"SERVER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:serverCode>server1</id:serverCode></xrd:securityServer><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><data>Request data</data></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:securityServer id:objectType=\"SERVER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:serverCode>server1</id:serverCode></xrd:securityServer><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><xxprod:getRandomResponse xmlns:xxprod=\"http://foobar.x-road.ee/producer\"><xxprod:data>Response data</xxprod:data></xxprod:getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    SecurityServer securityServer = new SecurityServer("FI", "GOV", "MEMBER1", "server1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setSecurityServer(securityServer);
    request.setUserId("EE1234567890");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("xxprod");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, String> response = new ServiceResponse<String, String>(request.getConsumer(), request.getProducer(), request.getId());
    response.setResponseData("Response data");

    request.setProcessingWrappers(false);
    ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * Member level service call. No NS prefix on request. No NS prefix on
 * response, set with an empty string.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test2() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"MEMBER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.5</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><getRandom xmlns=\"http://consumer.x-road.ee\"><request><data>Request data</data></request></getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"MEMBER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.5</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><getRandomResponse xmlns=\"http://foobar.x-road.ee/producer\"><request><data>Request data</data></request><response><data>Response data</data></response></getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setProtocolVersion("4.5");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, String> response = new ServiceResponse<String, String>(request.getConsumer(), request.getProducer(), request.getId());
    response.setResponseData("Response data");

    ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:ServiceRequestDeserializerTest.java   
/**
 * Request from subsystem to service without subsystem and service version.
 *
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test5() throws XRd4JException, SOAPException {
    String soapString = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:serviceCode>getRandom</id:serviceCode></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>ID11234</xrd:id><xrd:protocolVersion>10.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://producer.x-road.ee\"><request><data>1234567890</data></request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    SOAPMessage msg = SOAPHelper.toSOAP(soapString);

    ServiceRequestDeserializer deserializer = new ServiceRequestDeserializerImpl();
    ServiceRequest<String> request = deserializer.deserialize(msg);

    assertEquals("FI", request.getConsumer().getXRoadInstance());
    assertEquals("GOV", request.getConsumer().getMemberClass());
    assertEquals("MEMBER1", request.getConsumer().getMemberCode());
    assertEquals("subsystem", request.getConsumer().getSubsystemCode());
    assertEquals(ObjectType.SUBSYSTEM, request.getConsumer().getObjectType());

    assertEquals("FI", request.getProducer().getXRoadInstance());
    assertEquals("COM", request.getProducer().getMemberClass());
    assertEquals("MEMBER2", request.getProducer().getMemberCode());
    assertEquals(null, request.getProducer().getSubsystemCode());
    assertEquals("getRandom", request.getProducer().getServiceCode());
    assertEquals(null, request.getProducer().getServiceVersion());
    assertEquals("ID11234", request.getId());
    assertEquals("EE1234567890", request.getUserId());
    assertEquals("10.0", request.getProtocolVersion());
    assertEquals(ObjectType.SERVICE, request.getProducer().getObjectType());
    assertEquals(true, request.getSoapMessage() != null);
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * Calling service without subsystem. No NS on request. No NS prefix on
 * response, set with null value.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test3() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"MEMBER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>6.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><request><data>Request data</data></request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"MEMBER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>6.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><getRandomResponse xmlns=\"http://foobar.x-road.ee/producer\"><request><data>Request data</data></request><response><data>Response data</data></response></getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "getRandom");
    producer.setServiceVersion("v1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setProtocolVersion("6.0");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix(null);
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, String> response = new ServiceResponse<String, String>(request.getConsumer(), request.getProducer(), request.getId());
    response.setResponseData("Response data");

    ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:xrd4j    文件:ListServicesResponseDeserializerTest.java   
/**
 * ListMethods: Subsystem - Service (under subsystem). Response: 0 service
 *
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test7() throws XRd4JException, SOAPException {
    String soapString = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>client</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>listMethods</id:serviceCode></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>ID-1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion><xrd:requestHash algorithmId=\"SHA-512\">ZPbWPAOcJxzE81EmSk//R3DUQtqwMcuMMF9tsccJypdNcukzICQtlhhr3a/bTmexDrn8e/BrBVyl2t0ni/cUvw==</xrd:requestHash></SOAP-ENV:Header><SOAP-ENV:Body><xrd:listMethodsResponse></xrd:listMethodsResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";

    SOAPMessage msg = SOAPHelper.toSOAP(soapString);

    ServiceResponseDeserializer deserializer = new ListServicesResponseDeserializer();
    ServiceResponse<String, List<ProducerMember>> response = deserializer.deserialize(msg);

    assertEquals("FI", response.getConsumer().getXRoadInstance());
    assertEquals("GOV", response.getConsumer().getMemberClass());
    assertEquals("MEMBER1", response.getConsumer().getMemberCode());
    assertEquals("client", response.getConsumer().getSubsystemCode());
    assertEquals(ObjectType.SUBSYSTEM, response.getConsumer().getObjectType());

    assertEquals("FI", response.getProducer().getXRoadInstance());
    assertEquals("COM", response.getProducer().getMemberClass());
    assertEquals("MEMBER2", response.getProducer().getMemberCode());
    assertEquals("subsystem", response.getProducer().getSubsystemCode());
    assertEquals("listMethods", response.getProducer().getServiceCode());
    assertEquals(null, response.getProducer().getServiceVersion());
    assertEquals("ID-1234567890", response.getId());
    assertEquals("EE1234567890", response.getUserId());
    assertEquals("4.0", response.getProtocolVersion());
    assertEquals(ObjectType.SERVICE, response.getProducer().getObjectType());
    assertEquals(null, response.getRequestData());

    assertEquals("SHA-512", response.getRequestHashAlgorithm());
    assertEquals("ZPbWPAOcJxzE81EmSk//R3DUQtqwMcuMMF9tsccJypdNcukzICQtlhhr3a/bTmexDrn8e/BrBVyl2t0ni/cUvw==", response.getRequestHash());
    assertEquals(true, response.getSoapMessage() != null);

    assertEquals(0, response.getResponseData().size());
}
项目:xrd4j    文件:ServiceRequestSerializerTest.java   
/**
 * Subsystem level service call. No NS and no prefix.
 *
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test14() throws XRd4JException, SOAPException {
    String correctRequest = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><getRandom><request><data>1234567890</data></request></getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setRequestData("1234567890");

    ServiceRequestSerializer serializer = new TestRequestSerializer();
    SOAPMessage msg = serializer.serialize(request);
    assertEquals(correctRequest, SOAPHelper.toString(msg));
}
项目:oscm    文件:UpdateAdapterTest.java   
@Before
public void setUp() throws Exception {
    adapter = new UpdateAdapter();
    context = new SOAPMessageContextStub();
    message = mock(SOAPMessage.class);
    context.setMessage(message);
}
项目:oscm    文件:ExceptionAdapterTest.java   
@Before
public void setUp() throws Exception {
    adapter = new ExceptionAdapter();
    context = new SOAPMessageContextStub();
    message = mock(SOAPMessage.class);
    context.setMessage(message);
}
项目:oscm    文件:VersionHandlerCtmg.java   
/**
 * The method is invoked for normal processing of outbound messages.
 * 
 * @param context
 *            the message context.
 * @return An indication of whether handler processing should continue for
 *         the current message. Return <code>true</code> to continue
 *         processing.
 * 
 * @throws Exception
 *             Causes the JAX-WS runtime to cease fault message processing.
 **/
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean request_p = (Boolean) context
            .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (request_p.booleanValue()) {
        try {
            SOAPMessage msg = context.getMessage();
            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
            SOAPHeader hdr = env.getHeader();
            if (hdr == null) {
                hdr = env.addHeader();
            }
            QName qname_user = new QName("http://com/auth/", "auth");
            SOAPHeaderElement helem_user = hdr.addHeaderElement(qname_user);
            helem_user.setActor(VERSION);
            if (version != null && version.trim().length() != 0) {
                helem_user.addTextNode(version);
            }

            msg.saveChanges();
            message = soapMessage2String(msg);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return true;
}
项目:xrd4j    文件:SOAPHelper.java   
/**
 * Converts the given InputStream to SOAPMessage. The stream must contain a
 * valid SOAP message, otherwise null is returned.
 *
 * @param is InputStream to be converted
 * @return SOAPMessage or null
 */
public static SOAPMessage toSOAP(InputStream is) {
    try {
        return createSOAPMessage(new MimeHeaders(), is);
    } catch (Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
        return null;
    }
}
项目:xrd4j    文件:ServiceRequestDeserializerTest.java   
/**
 * Request from subsystem to service with issue included.
 *
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test8() throws XRd4JException, SOAPException {
    String soapString = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>ID11234</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion><xrd:issue>issue</xrd:issue></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://producer.x-road.ee\"><request><data>1234567890</data></request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    SOAPMessage msg = SOAPHelper.toSOAP(soapString);

    ServiceRequestDeserializer deserializer = new ServiceRequestDeserializerImpl();
    ServiceRequest<String> request = deserializer.deserialize(msg);

    assertEquals("FI", request.getConsumer().getXRoadInstance());
    assertEquals("GOV", request.getConsumer().getMemberClass());
    assertEquals("MEMBER1", request.getConsumer().getMemberCode());
    assertEquals("subsystem", request.getConsumer().getSubsystemCode());
    assertEquals(ObjectType.SUBSYSTEM, request.getConsumer().getObjectType());

    assertEquals("FI", request.getProducer().getXRoadInstance());
    assertEquals("COM", request.getProducer().getMemberClass());
    assertEquals("MEMBER2", request.getProducer().getMemberCode());
    assertEquals("subsystem", request.getProducer().getSubsystemCode());
    assertEquals("getRandom", request.getProducer().getServiceCode());
    assertEquals("v1", request.getProducer().getServiceVersion());
    assertEquals("ID11234", request.getId());
    assertEquals("EE1234567890", request.getUserId());
    assertEquals("issue", request.getIssue());
    assertEquals("4.0", request.getProtocolVersion());
    assertEquals(ObjectType.SERVICE, request.getProducer().getObjectType());
    assertEquals(true, request.getSoapMessage() != null);
}
项目:xrd4j    文件:ServiceResponseDeserializerTest.java   
protected String deserializeResponseData(Node responseNode, SOAPMessage message) throws SOAPException {
    for (int i = 0; i < responseNode.getChildNodes().getLength(); i++) {
        if (responseNode.getChildNodes().item(i).getNodeType() == Node.ELEMENT_NODE
                && responseNode.getChildNodes().item(i).getLocalName().equals("data")) {
            return responseNode.getChildNodes().item(i).getTextContent();
        }
    }
    return null;
}
项目:onvifjava    文件:SoapClient.java   
protected void addSoapHeader(SOAPMessage soapMessage) throws SOAPException, NoSuchAlgorithmException {
    onvifDevice.createNonce();
    String encrypedPassword = onvifDevice.getEncryptedPassword();
    if (encrypedPassword != null && onvifDevice.getUsername() != null) {

        SOAPPart sp = soapMessage.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPHeader header = soapMessage.getSOAPHeader();
        se.addNamespaceDeclaration("wsse",
                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
        se.addNamespaceDeclaration("wsu",
                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");

        SOAPElement securityElem = header.addChildElement("Security", "wsse");
        // securityElem.setAttribute("SOAP-ENV:mustUnderstand", "1");

        SOAPElement usernameTokenElem = securityElem.addChildElement("UsernameToken", "wsse");

        SOAPElement usernameElem = usernameTokenElem.addChildElement("Username", "wsse");
        usernameElem.setTextContent(onvifDevice.getUsername());

        SOAPElement passwordElem = usernameTokenElem.addChildElement("Password", "wsse");
        passwordElem.setAttribute("Type",
                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
        passwordElem.setTextContent(encrypedPassword);

        SOAPElement nonceElem = usernameTokenElem.addChildElement("Nonce", "wsse");
        nonceElem.setAttribute("EncodingType",
                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
        nonceElem.setTextContent(onvifDevice.getEncryptedNonce());

        SOAPElement createdElem = usernameTokenElem.addChildElement("Created", "wsu");
        createdElem.setTextContent(onvifDevice.getLastUTCTime());
    }
}
项目:onvifjava    文件:CameraDiscovery.java   
private void parseSoapResponseForUrls(byte[] data) {
//          System.out.println(new String(data));
            try {
                MessageFactory factory= MessageFactory.newInstance(WS_DISCOVERY_SOAP_VERSION);
                final MimeHeaders headers = new MimeHeaders();
//              headers.addHeader("Content-type", WS_DISCOVERY_CONTENT_TYPE);
                SOAPMessage message = factory.createMessage(headers, new ByteArrayInputStream(data));
                SOAPPart part=message.getSOAPPart();
                SOAPEnvelope env=part.getEnvelope();
                SOAPBody body=message.getSOAPBody();
                NodeList list=body.getElementsByTagNameNS("http://schemas.xmlsoap.org/ws/2005/04/discovery", "XAddrs");
                int items=list.getLength();
                if(items<1)return;
                for (int i = 0; i < items; i++) {
                    Node n=list.item(i);
                    String raw=n.getTextContent();
                    //may contain several
                    String []addrArray=raw.split(" ");
                    for (String string : addrArray) {
                        URL url=new URL(string);
                        discovered.add(url);                        
                    }
                }
            } catch (Exception e) {
                System.out.println("Parse failed");
                e.printStackTrace();
            }

        }
项目:xrd4j    文件:ServiceResponseDeserializerTest.java   
/**
 * Response to subsystem -> service level service call. Erroneous Producer
 * namespace URI parameter used.
 *
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test10() throws XRd4JException, SOAPException {
    String soapString = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>ID-1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion><xrd:requestHash algorithmId=\"SHA-512\">ZPbWPAOcJxzE81EmSk//R3DUQtqwMcuMMF9tsccJypdNcukzICQtlhhr3a/bTmexDrn8e/BrBVyl2t0ni/cUvw==</xrd:requestHash></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandomResponse xmlns:ns1=\"http://producer.x-road.ee\"><request><data>1234567890</data></request>  <response>    <data>9876543210</data>    </response>  </ns1:getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    SOAPMessage msg = SOAPHelper.toSOAP(soapString);

    ServiceResponseDeserializer deserializer = new TestResponseDeserializer();
    ServiceResponse<String, String> response = deserializer.deserialize(msg, "http://test.com");

    assertEquals("FI", response.getConsumer().getXRoadInstance());
    assertEquals("GOV", response.getConsumer().getMemberClass());
    assertEquals("MEMBER1", response.getConsumer().getMemberCode());
    assertEquals("subsystem", response.getConsumer().getSubsystemCode());
    assertEquals(ObjectType.SUBSYSTEM, response.getConsumer().getObjectType());

    assertEquals("FI", response.getProducer().getXRoadInstance());
    assertEquals("COM", response.getProducer().getMemberClass());
    assertEquals("MEMBER2", response.getProducer().getMemberCode());
    assertEquals("subsystem", response.getProducer().getSubsystemCode());
    assertEquals("getRandom", response.getProducer().getServiceCode());
    assertEquals("v1", response.getProducer().getServiceVersion());
    assertEquals("ID-1234567890", response.getId());
    assertEquals("EE1234567890", response.getUserId());
    assertEquals("4.0", response.getProtocolVersion());
    assertEquals(ObjectType.SERVICE, response.getProducer().getObjectType());
    assertEquals(null, response.getRequestData());
    assertEquals(null, response.getResponseData());

    assertEquals("SHA-512", response.getRequestHashAlgorithm());
    assertEquals("ZPbWPAOcJxzE81EmSk//R3DUQtqwMcuMMF9tsccJypdNcukzICQtlhhr3a/bTmexDrn8e/BrBVyl2t0ni/cUvw==", response.getRequestHash());
    assertEquals(false, response.hasError());
    assertEquals(true, response.getSoapMessage() != null);
    assertEquals(true, response.getSecurityServer() == null);
}
项目:xrd4j    文件:ServiceResponseDeserializerTest.java   
/**
 * Response to subsystem -> service level service call. Request and response
 * with namespace prefix.
 *
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test2() throws XRd4JException, SOAPException {
    String soapString = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>ID-1234567890</xrd:id><xrd:protocolVersion>4.5</xrd:protocolVersion><xrd:requestHash algorithmId=\"SHA-512\">ZPbWPAOcJxzE81EmSk//R3DUQtqwMcuMMF9tsccJypdNcukzICQtlhhr3a/bTmexDrn8e/BrBVyl2t0ni/cUvw==</xrd:requestHash></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandomResponse xmlns:ns1=\"http://producer.x-road.ee\"><ns1:request><ns1:data>1234567890</ns1:data></ns1:request><ns1:response><ns1:data>9876543210</ns1:data></ns1:response></ns1:getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    SOAPMessage msg = SOAPHelper.toSOAP(soapString);

    ServiceResponseDeserializer deserializer = new TestResponseDeserializer();
    ServiceResponse<String, String> response = deserializer.deserialize(msg);

    assertEquals("FI", response.getConsumer().getXRoadInstance());
    assertEquals("GOV", response.getConsumer().getMemberClass());
    assertEquals("MEMBER1", response.getConsumer().getMemberCode());
    assertEquals("subsystem", response.getConsumer().getSubsystemCode());
    assertEquals(ObjectType.SUBSYSTEM, response.getConsumer().getObjectType());

    assertEquals("FI", response.getProducer().getXRoadInstance());
    assertEquals("COM", response.getProducer().getMemberClass());
    assertEquals("MEMBER2", response.getProducer().getMemberCode());
    assertEquals("subsystem", response.getProducer().getSubsystemCode());
    assertEquals("getRandom", response.getProducer().getServiceCode());
    assertEquals("v1", response.getProducer().getServiceVersion());
    assertEquals("ID-1234567890", response.getId());
    assertEquals("EE1234567890", response.getUserId());
    assertEquals("4.5", response.getProtocolVersion());
    assertEquals(ObjectType.SERVICE, response.getProducer().getObjectType());
    assertEquals("1234567890", response.getRequestData());
    assertEquals("9876543210", response.getResponseData());

    assertEquals("SHA-512", response.getRequestHashAlgorithm());
    assertEquals("ZPbWPAOcJxzE81EmSk//R3DUQtqwMcuMMF9tsccJypdNcukzICQtlhhr3a/bTmexDrn8e/BrBVyl2t0ni/cUvw==", response.getRequestHash());
    assertEquals(true, response.getSoapMessage() != null);
    assertEquals(true, response.getSecurityServer() == null);
}
项目:jdk8u-jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNsNoDeclarations() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:xrd4j    文件:AbstractAdapterServlet.java   
/**
 * Writes the given SOAP response to output stream. Sets the necessary HTTP
 * headers according to the content of the response.
 *
 * @param soapResponse SOAP response
 * @param response servlet response
 */
private void writeResponse(SOAPMessage soapResponse, HttpServletResponse response) {
    PrintWriter out = null;
    try {
        LOGGER.debug("Send response.");
        // SOAPMessage to String
        String responseStr = SOAPHelper.toString(soapResponse);
        // Set response headers
        if (responseStr != null && soapResponse != null && soapResponse.getAttachments().hasNext()) {
            // Get MIME boundary from SOAP message
            String boundary = AdapterUtils.getMIMEBoundary(responseStr);
            response.setContentType(Constants.MULTIPART_RELATED + "; type=\"text/xml\"; boundary=\"" + boundary + "\"; charset=UTF-8");
        } else {
            response.setContentType(Constants.TEXT_XML + "; charset=UTF-8");
        }
        LOGGER.debug("Response content type : \"{}\".", response.getContentType());
        // Get writer
        out = response.getWriter();
        // Send response
        if (responseStr != null) {
            out.println(responseStr);
            LOGGER.trace("SOAP response : \"{}\"", responseStr);
        } else {
            out.println(this.errInternalServerErrStr);
            LOGGER.warn("Internal serveri error. Message processing failed.");
            LOGGER.trace("SOAP response : \"{}\"", this.errInternalServerErrStr);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        if (out != null) {
            out.println(this.errInternalServerErrStr);
        }
    } finally {
        if (out != null) {
            out.close();
        }
        LOGGER.debug("Request was succesfully processed.");
    }
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * Subsystem level service call. Response data in a Map. NS on request.
 * No NS prefix on response.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test4() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:serviceCode>getRandom</id:serviceCode></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.5</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><ns1:request><ns1:data>Request data</ns1:data></ns1:request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:serviceCode>getRandom</id:serviceCode></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.5</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><getRandomResponse xmlns=\"http://foobar.x-road.ee/producer\"><request><data>Request data</data></request><response><field1>Field1</field1><field2>Field2</field2><field3>Field3</field3></response></getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "getRandom");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setProtocolVersion("4.5");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, Map> response = new ServiceResponse<String, Map>(request.getConsumer(), request.getProducer(), request.getId());
    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put("field1", "Field1");
    map.put("field2", "Field2");
    map.put("field3", "Field3");
    response.setResponseData(map);

    ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl1();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:openjdk-jdk10    文件:SOAPProviderArgumentBuilder.java   
static ProviderArgumentsBuilder create(ProviderEndpointModel model, SOAPVersion soapVersion) {
    if (model.mode == Service.Mode.PAYLOAD) {
        return new PayloadSource(soapVersion);
    } else {
        if(model.datatype==Source.class)
            return new MessageSource(soapVersion);
        if(model.datatype==SOAPMessage.class)
            return new SOAPMessageParameter(soapVersion);
        if(model.datatype==Message.class)
            return new MessageProviderArgumentBuilder(soapVersion);
        throw new WebServiceException(ServerMessages.PROVIDER_INVALID_PARAMETER_TYPE(model.implClass,model.datatype));
    }
}
项目:OpenJSharp    文件:StringHeader.java   
public void writeTo(SOAPMessage saaj) throws SOAPException {
    SOAPHeader header = saaj.getSOAPHeader();
    if(header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
    SOAPHeaderElement she = header.addHeaderElement(name);
    if(mustUnderstand) {
        she.setMustUnderstand(true);
    }
    she.addTextNode(value);
}
项目:OpenJSharp    文件:ProblemActionHeader.java   
public void writeTo(SOAPMessage saaj) throws SOAPException {
    SOAPHeader header = saaj.getSOAPHeader();
    if(header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
    SOAPHeaderElement she = header.addHeaderElement(new QName(getNamespaceURI(), getLocalPart()));
    she.addChildElement(actionLocalName);
    she.addTextNode(action);
    if (soapAction != null) {
        she.addChildElement(soapActionLocalName);
        she.addTextNode(soapAction);
    }
}
项目:OpenJSharp    文件:JAXBHeader.java   
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        SOAPHeader header = saaj.getSOAPHeader();
        if (header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        bridge.marshal(jaxbObject,header);
    } catch (JAXBException e) {
        throw new SOAPException(e);
    }
}
项目:xrd4j    文件:ServiceResponseSerializerTest.java   
/**
 * SOAP Fault with complex detail element.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void testSOAPFault4() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><request><data>Request data</data></request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>Fault code</faultcode><faultstring>Fault string</faultstring><faultactor>Fault actor</faultactor><detail><field1>Field1</field1><field2>Field2</field2></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("xxprod");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, String> response = new ServiceResponse<String, String>();
    response.setResponseData("Response data");

    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put("field1", "Field1");
    map.put("field2", "Field2");
    ErrorMessage errorMsg = new ErrorMessage("Fault code", "Fault string", "Fault actor", map);
    response.setErrorMessage(errorMsg);

    ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl2();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}