List of usage examples for javax.xml.soap SOAPMessage getSOAPBody
public SOAPBody getSOAPBody() throws SOAPException
From source file:org.libreplan.importers.TimSoapClient.java
/** * Sends soap request to the SOAP server. Receives and unmarshals the * response/*from ww w . j a va 2 s. c o m*/ * * @param url * the SOAP server url(endpoint) * @param userName * the user * @param password * the password * @param request * the request object * @param response * the response class * @return the expected object or null */ public static <T, U> T sendRequestReceiveResponse(String url, String userName, String password, U request, Class<T> response) { try { SOAPMessage requestMsg = createRequest(request, userName, password); SOAPMessage responseMsg = sendRequest(url, requestMsg); return unmarshal(response, responseMsg.getSOAPBody()); } catch (SOAPException soapExp) { LOG.error("SOAPException: ", soapExp); } catch (JAXBException jaxbExp) { LOG.error("JAXBException: ", jaxbExp); } return null; }
From source file:org.mule.modules.paypal.util.PayPalAPIHelper.java
public static void getPalDetails(@NotNull String url, @NotNull String username, @NotNull String password, @NotNull String appId, String signature) throws Exception { SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // Send SOAP Message to SOAP Server SOAPMessage soapResponse; try {/*from w ww .j ava 2 s . c o m*/ soapResponse = soapConnection.call(createGetPalDetailsSOAPRequest(username, password, appId, signature), url); } catch (Exception e) { throw new org.mule.api.ConnectionException(ConnectionExceptionCode.UNKNOWN_HOST, "", "PayPal SOAP Endpoint not reachable.", e); } if (soapResponse.getSOAPBody().hasFault()) { Exception e = processException(soapResponse); throw e; } NodeList palList = soapResponse.getSOAPBody().getElementsByTagName("Pal"); if (palList == null || (palList != null && palList.getLength() == 0)) { Exception e = processException(soapResponse); throw e; } String pal = soapResponse.getSOAPBody().getElementsByTagName("Pal").item(0).getTextContent(); if (StringUtils.isEmpty(pal)) { Exception e = processException(soapResponse); throw e; } soapConnection.close(); }
From source file:org.mule.modules.paypal.util.PayPalAPIHelper.java
private static Exception processException(@NotNull SOAPMessage soapResponse) { Exception exception;/* w w w . j a v a 2 s . com*/ try { String errorLngMsg = soapResponse.getSOAPBody().getElementsByTagName("LongMessage").item(0) .getTextContent(); String errorCode = soapResponse.getSOAPBody().getElementsByTagName("ErrorCode").item(0) .getTextContent(); exception = new PayPalConnectionException(ConnectionExceptionCode.INCORRECT_CREDENTIALS, errorCode, errorLngMsg); } catch (SOAPException e) { exception = e; } return exception; }
From source file:org.openhab.binding.fritzboxtr064.internal.Tr064Comm.java
/** * Fetches the values for the given item configurations from the FritzBox. Calls * the FritzBox SOAP services delivering the values for the item configurations. * The resulting map contains the values of all item configurations returned by * the invoked services. This can be more items than were given as parameter. * * @param request/* w w w .j a va 2 s .c om*/ * string from config including the command and optional parameters * @return Parsed values for all item configurations returned by the invoked * services. */ public Map<ItemConfiguration, String> getTr064Values(Collection<ItemConfiguration> itemConfigurations) { Map<ItemConfiguration, String> values = new HashMap<>(); for (ItemConfiguration itemConfiguration : itemConfigurations) { String itemCommand = itemConfiguration.getItemCommand(); if (values.containsKey(itemCommand)) { // item value already read by earlier MultiItemMap continue; } // search for proper item Mapping ItemMap itemMap = determineItemMappingByItemCommand(itemCommand); if (itemMap == null) { logger.warn("No item mapping found for {}. Function not implemented by your FritzBox (?)", itemConfiguration); continue; } // determine which url etc. to connect to for accessing required value Tr064Service tr064service = determineServiceByItemMapping(itemMap); // construct soap Body which is added to soap msg later SOAPBodyElement bodyData = null; // holds data to be sent to fbox try { MessageFactory mf = MessageFactory.newInstance(); SOAPMessage msg = mf.createMessage(); // empty message SOAPBody body = msg.getSOAPBody(); // std. SAOP body QName bodyName = new QName(tr064service.getServiceType(), itemMap.getReadServiceCommand(), "u"); // header // for // body // element bodyData = body.addBodyElement(bodyName); // only if input parameter is present if (itemMap instanceof ParametrizedItemMap) { for (InputArgument inputArgument : ((ParametrizedItemMap) itemMap) .getConfigInputArguments(itemConfiguration)) { String dataInName = inputArgument.getName(); String dataInValue = inputArgument.getValue(); QName dataNode = new QName(dataInName); SOAPElement beDataNode = bodyData.addChildElement(dataNode); // if input is mac address, replace "-" with ":" as fbox wants if (itemConfiguration.getItemCommand().equals("maconline")) { dataInValue = dataInValue.replaceAll("-", ":"); } beDataNode.addTextNode(dataInValue); // add data which should be requested from fbox for this // service } } logger.trace("Raw SOAP Request to be sent to FritzBox: {}", soapToString(msg)); } catch (Exception e) { logger.warn("Error constructing request SOAP msg for getting parameter. {}", e.getMessage()); logger.debug("Request was: {}", itemConfiguration); } if (bodyData == null) { logger.warn("Could not determine data to be sent to FritzBox!"); return null; } SOAPMessage smTr064Request = constructTr064Msg(bodyData); // construct entire msg with body element String soapActionHeader = tr064service.getServiceType() + "#" + itemMap.getReadServiceCommand(); // needed // to be // sent // with // request // (not // in body // -> // header) SOAPMessage response = readSoapResponse(soapActionHeader, smTr064Request, _url + tr064service.getControlUrl()); logger.trace("Raw SOAP Response from FritzBox: {}", soapToString(response)); if (response == null) { logger.warn("Error retrieving SOAP response from FritzBox"); continue; } values.putAll( itemMap.getSoapValueParser().parseValuesFromSoapMessage(response, itemMap, itemConfiguration)); } return values; }
From source file:org.openhab.binding.fritzboxtr064.internal.Tr064Comm.java
/** * Sets a parameter in fbox. Called from event bus. * * @param request// w w w .j ava2 s. c o m * config string from itemconfig * @param cmd * command to set */ public void setTr064Value(ItemConfiguration request, Command cmd) { String itemCommand = request.getItemCommand(); // search for proper item Mapping ItemMap itemMapForCommand = determineItemMappingByItemCommand(itemCommand); if (!(itemMapForCommand instanceof WritableItemMap)) { logger.warn("Item command {} does not support setting values", itemCommand); return; } WritableItemMap itemMap = (WritableItemMap) itemMapForCommand; Tr064Service tr064service = determineServiceByItemMapping(itemMap); // determine which url etc. to connect to for accessing required value // construct soap Body which is added to soap msg later SOAPBodyElement bodyData = null; // holds data to be sent to fbox try { MessageFactory mf = MessageFactory.newInstance(); SOAPMessage msg = mf.createMessage(); // empty message SOAPBody body = msg.getSOAPBody(); // std. SAOP body QName bodyName = new QName(tr064service.getServiceType(), itemMap.getWriteServiceCommand(), "u"); // header // for // body // element bodyData = body.addBodyElement(bodyName); List<InputArgument> writeInputArguments = new ArrayList<>(); writeInputArguments.add(itemMap.getWriteInputArgument(cmd)); if (itemMap instanceof ParametrizedItemMap) { writeInputArguments.addAll(((ParametrizedItemMap) itemMap).getConfigInputArguments(request)); } for (InputArgument inputArgument : writeInputArguments) { QName dataNode = new QName(inputArgument.getName()); SOAPElement beDataNode = bodyData.addChildElement(dataNode); beDataNode.addTextNode(inputArgument.getValue()); } logger.debug("SOAP Msg to send to FritzBox for setting data: {}", soapToString(msg)); } catch (Exception e) { logger.error("Error constructing request SOAP msg for setting parameter. {}", e.getMessage()); logger.debug("Request was: {}. Command was: {}.", request, cmd.toString()); } if (bodyData == null) { logger.error("Could not determine data to be sent to FritzBox!"); return; } SOAPMessage smTr064Request = constructTr064Msg(bodyData); // construct entire msg with body element String soapActionHeader = tr064service.getServiceType() + "#" + itemMap.getWriteServiceCommand(); // needed to // be sent // with // request // (not in // body -> // header) SOAPMessage response = readSoapResponse(soapActionHeader, smTr064Request, _url + tr064service.getControlUrl()); if (response == null) { logger.error("Error retrieving SOAP response from FritzBox"); return; } logger.debug("SOAP response from FritzBox: {}", soapToString(response)); // Check if error received try { if (response.getSOAPBody().getFault() != null) { logger.error("Error received from FritzBox while trying to set parameter"); logger.debug("Soap Response was: {}", soapToString(response)); } } catch (SOAPException e) { logger.error("Could not parse soap response from FritzBox while setting parameter. {}", e.getMessage()); logger.debug("Soap Response was: {}", soapToString(response)); } }
From source file:org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMappingTest.java
@Test public void invoke() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage request = messageFactory.createMessage(); request.getSOAPBody().addBodyElement(QName.valueOf("{http://springframework.org/spring-ws}Request")); MessageContext messageContext = new DefaultMessageContext(new SaajSoapMessage(request), new SaajSoapMessageFactory(messageFactory)); DefaultMethodEndpointAdapter adapter = new DefaultMethodEndpointAdapter(); adapter.afterPropertiesSet();//from ww w . j ava 2 s . c o m MessageDispatcher messageDispatcher = new SoapMessageDispatcher(); messageDispatcher.setApplicationContext(applicationContext); messageDispatcher.setEndpointMappings(Collections.<EndpointMapping>singletonList(mapping)); messageDispatcher.setEndpointAdapters(Collections.<EndpointAdapter>singletonList(adapter)); messageDispatcher.receive(messageContext); MyEndpoint endpoint = applicationContext.getBean("endpoint", MyEndpoint.class); assertTrue("doIt() not invoked on endpoint", endpoint.isDoItInvoked()); LogAspect aspect = (LogAspect) applicationContext.getBean("logAspect"); assertTrue("log() not invoked on aspect", aspect.isLogInvoked()); }
From source file:org.springframework.ws.soap.saaj.support.SaajUtils.java
/** * Checks whether we can find a SAAJ 1.2 implementation, being aware of the broken WebLogic 9 SAAJ implementation. * <p/>/*from w w w.j a v a 2 s . c om*/ * WebLogic 9 does implement SAAJ 1.2, but throws UnsupportedOperationExceptions when a SAAJ 1.2 method is called. */ private static boolean isSaaj12() { if (Element.class.isAssignableFrom(SOAPElement.class)) { // see if we are dealing with WebLogic 9 try { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage message = messageFactory.createMessage(); try { message.getSOAPBody(); return true; } catch (UnsupportedOperationException ex) { return false; } } catch (SOAPException e) { return false; } } else { return false; } }
From source file:org.wso2.carbon.identity.provisioning.connector.InweboUserManager.java
/** * Method to create SOAP connection/*from ww w . j a v a2 s . co m*/ */ public static String invokeSOAP(InweboUser user, String operation) throws IdentityProvisioningException { String provisionedId = null; SOAPConnectionFactory soapConnectionFactory = null; SOAPConnection soapConnection = null; try { Properties inweboProperties = new Properties(); String resourceName = InweboConnectorConstants.PROPERTIES_FILE; ClassLoader loader = Thread.currentThread().getContextClassLoader(); InputStream resourceStream = loader.getResourceAsStream(resourceName); try { inweboProperties.load(resourceStream); } catch (IOException e) { throw new IdentityProvisioningException("Unable to load the properties file", e); } SOAPMessage soapMessage = null; soapConnectionFactory = SOAPConnectionFactory.newInstance(); soapConnection = soapConnectionFactory.createConnection(); String url = inweboProperties.getProperty(InweboConnectorConstants.INWEBO_URL); if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_POST)) { soapMessage = createUserSOAPMessage(inweboProperties, user); } else if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_PUT)) { soapMessage = updateUserSOAPMessage(inweboProperties, user); } else if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_DELETE)) { soapMessage = deleteUserSOAPMessage(inweboProperties, user.getLoginId(), user.getUserId(), user.getServiceId()); } SOAPMessage soapResponse = soapConnection.call(soapMessage, url); if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_POST)) { if (soapResponse.getSOAPBody().getElementsByTagName("id").getLength() != 0) { provisionedId = soapResponse.getSOAPBody().getElementsByTagName("id").item(0).getTextContent() .toString(); if (StringUtils.isEmpty(provisionedId) || "0".equals(provisionedId)) { String error = soapResponse.getSOAPBody().getElementsByTagName("loginCreateReturn").item(0) .getTextContent().toString(); throw new IdentityProvisioningException( "Error occurred while creating the user in InWebo:" + error); } } else { throw new IdentityProvisioningException("Unable to find the provisioning ID"); } } else if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_PUT)) { if (soapResponse.getSOAPBody().getElementsByTagName("loginUpdateReturn").getLength() != 0) { String updationStatus = soapResponse.getSOAPBody().getElementsByTagName("loginUpdateReturn") .item(0).getTextContent().toString(); boolean processStatus = StringUtils.equals("OK", updationStatus); if (!processStatus) { String error = soapResponse.getSOAPBody().getElementsByTagName("loginUpdateReturn").item(0) .getTextContent().toString(); throw new IdentityProvisioningException( "Error occurred while updating the user in InWebo:" + error); } } else { throw new IdentityProvisioningException("Unable to get the updation status"); } } else if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_DELETE)) { if (soapResponse.getSOAPBody().getElementsByTagName("loginDeleteReturn").getLength() != 0) { String deletionStatus = soapResponse.getSOAPBody().getElementsByTagName("loginDeleteReturn") .item(0).getTextContent().toString(); boolean processStatus = StringUtils.equals("OK", deletionStatus); if (!processStatus) { String error = soapResponse.getSOAPBody().getElementsByTagName("loginDeleteReturn").item(0) .getTextContent().toString(); throw new IdentityProvisioningException( "Error occurred while deleting the user from InWebo:" + error); } } else { throw new IdentityProvisioningException("Unable to get the operation status"); } } } catch (SOAPException e) { throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e); } finally { try { if (soapConnection != null) { soapConnection.close(); } } catch (SOAPException e) { log.error("Error while closing the SOAP connection", e); } } return provisionedId; }
From source file:org.wso2.carbon.identity.provisioning.connector.UserCreation.java
/** * Method for create SOAP connection//from w w w . j ava 2s .c om */ public static String invokeSOAP(String userId, String serviceId, String login, String firstName, String name, String mail, String phone, String status, String role, String access, String codeType, String language, String extraFields) throws IdentityProvisioningException { String provisionedId = null; try { SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); String url = InweboConnectorConstants.INWEBO_URL; SOAPMessage soapResponse = soapConnection.call(createUser(userId, serviceId, login, firstName, name, mail, phone, status, role, access, codeType, language, extraFields), url); provisionedId = soapResponse.getSOAPBody().getElementsByTagName("id").item(0).getTextContent() .toString(); soapConnection.close(); if (StringUtils.isEmpty(provisionedId) || provisionedId.equals("0")) { String error = soapResponse.getSOAPBody().getElementsByTagName("loginCreateReturn").item(0) .getTextContent().toString(); throw new IdentityProvisioningException( "Error occurred while creating the user in InWebo:" + error); } } catch (SOAPException e) { throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e); } catch (IdentityProvisioningException e) { throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e); } return provisionedId; }
From source file:org.wso2.carbon.identity.provisioning.connector.UserDeletion.java
public boolean deleteUser(String loginId, String userId, String serviceId) throws IdentityProvisioningException { try {/*from ww w .j a va 2s . c o m*/ SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); String url = InweboConnectorConstants.INWEBO_URL; SOAPMessage soapResponse = soapConnection.call(deleteUsers(loginId, userId, serviceId), url); String deletionStatus = soapResponse.getSOAPBody().getElementsByTagName("loginDeleteReturn").item(0) .getTextContent().toString(); soapConnection.close(); boolean processStatus = StringUtils.equals("OK", deletionStatus); if (!processStatus) { String error = soapResponse.getSOAPBody().getElementsByTagName("loginDeleteReturn").item(0) .getTextContent().toString(); throw new IdentityProvisioningException( "Error occurred while deleting the user from InWebo:" + error); } return processStatus; } catch (SOAPException e) { throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e); } catch (IdentityProvisioningException e) { throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e); } }