List of usage examples for javax.xml.ws Service create
public static Service create(QName serviceName, WebServiceFeature... features)
From source file:de.intevation.test.irixservice.UploadReportTest.java
/** * Test that the webservice can be created and accepts a valid report. *//*from w ww . j a va 2s . c o m*/ @Test public void testServiceCreated() throws MalformedURLException, IOException, UploadReportException { Endpoint endpoint = Endpoint.publish("http://localhost:18913/upload-report", testObj); Assert.assertTrue(endpoint.isPublished()); Assert.assertEquals("http://schemas.xmlsoap.org/wsdl/soap/http", endpoint.getBinding().getBindingID()); URL wsdlDocumentLocation = new URL("http://localhost:18913/upload-report?wsdl"); String namespaceURI = "http://irixservice.intevation.de/"; String servicePart = "UploadReportService"; String portName = "UploadReportPort"; QName serviceQN = new QName(namespaceURI, servicePart); QName portQN = new QName(namespaceURI, portName); Service serv = Service.create(wsdlDocumentLocation, serviceQN); UploadReportInterface service = serv.getPort(portQN, UploadReportInterface.class); ReportType report = getReportFromFile(VALID_REPORT); service.uploadReport(report); String uuid = report.getIdentification().getReportUUID(); String expectedPath = testObj.outputDir + "/" + uuid + ".xml"; Assert.assertTrue(new File(expectedPath).exists()); }
From source file:io.hummer.util.ws.WebServiceClient.java
protected WebServiceClient(URL wsdlLocation, QName serviceName, QName port) { service = Service.create(wsdlLocation, serviceName); if (port != null) portName = port;/*from w w w.j a v a 2 s . co m*/ else portName = service.getPorts().next(); try { Port servicePort = (Port) getSingleWSDLService(wsdlLocation.toExternalForm()).getPorts().values() .iterator().next(); endpointURL = getAddressFromWSDLPort(servicePort); } catch (Exception e) { //e.printStackTrace(); //endpointURL = service.getServiceName().toString(); throw new RuntimeException(e); } }
From source file:egovframework.rte.itl.webservice.service.impl.EgovWebServiceClientImpl.java
@SuppressWarnings("unchecked") public EgovIntegrationMessage service(EgovIntegrationMessage requestMessage) { LOG.debug("EgovWebServiceClient service (requestMesage = " + requestMessage + ")"); synchronized (initializedLock) { if (initialized == false) { LOG.debug("Initialize Client"); // ServiceEndpointInterface Impl ? ? try { service = Service.create(wsdlURL, serviceName); client = service.getPort(portName, serviceEndpointInterfaceClass); initialized = true;//from w ww. j av a 2 s .com } catch (Throwable e) { LOG.error("Cannot create web service port", e); initialized = false; // return new EgovWebServiceMessage(new EgovWebServiceMessageHeader(requestMessage.getHeader()) { { setResultCode(ResultCode.FAIL_IN_INITIALIZING); } }); } } } LOG.debug("Create Request Message"); // get request params List<Object> params = new ArrayList<Object>(); // requestMessage? Body value object . boolean succeed = false; try { Map<String, Object> requestBody = requestMessage.getBody(); for (ServiceParamInfo paramInfo : serviceEndpointInterfaceInfo.getParamInfos()) { if (paramInfo.getMode().equals(Mode.IN) || paramInfo.getMode().equals(Mode.INOUT)) { Object valueObject = null; if (paramInfo.getType() == EgovWebServiceMessageHeader.TYPE) { LOG.debug("Insert Message Header"); LOG.debug("value = " + requestMessage.getHeader()); valueObject = requestMessage.getHeader(); } else { LOG.debug("Insert Param \"" + paramInfo.getName() + "\""); Object typedObject = requestBody.get(paramInfo.getName()); valueObject = messageConverter.convertToValueObject(typedObject, paramInfo.getType()); LOG.debug("value = " + valueObject); } if (paramInfo.getMode().equals(Mode.INOUT)) { LOG.debug("Wrapping Holder"); valueObject = new Holder(valueObject); } params.add(valueObject); } else { params.add(new Holder()); } } succeed = true; } catch (Throwable e) { LOG.error("Cannot Create Request Message", e); } if (succeed == false) { // ? return new EgovWebServiceMessage(new EgovWebServiceMessageHeader(requestMessage.getHeader()) { { setResultCode(ResultCode.FAIL_IN_CREATING_REQUEST_MESSAGE); } }); } // call method LOG.debug("Invoke method"); Object[] paramArray = params.toArray(); succeed = false; try { method.invoke(client, paramArray); succeed = true; } catch (Throwable e) { LOG.error("Fail to invoke method", e); } if (succeed == false) { // return new EgovWebServiceMessage(new EgovWebServiceMessageHeader(requestMessage.getHeader()) { { setResultCode(ResultCode.FAIL_IN_SENDING_REQUEST); } }); } // responseValueObject typed object . LOG.debug("Parse Response Message"); EgovIntegrationMessageHeader responseHeader = null; succeed = true; // response parsing? ? . Map<String, Object> responseBody = new HashMap<String, Object>(); int i = 0; for (ServiceParamInfo paramInfo : serviceEndpointInterfaceInfo.getParamInfos()) { if (paramInfo.getMode().equals(Mode.OUT) || paramInfo.getMode().equals(Mode.INOUT)) { Object valueObject = ((Holder) paramArray[i]).value; if (paramInfo.getType() == EgovWebServiceMessageHeader.TYPE) { responseHeader = (EgovWebServiceMessageHeader) valueObject; } else { try { Object typedObject = messageConverter.convertToTypedObject(valueObject, paramInfo.getType()); responseBody.put(paramInfo.getName(), typedObject); } catch (Throwable e) { LOG.error("Cannot parse response message", e); succeed = false; } } } i++; } if (succeed) { // ? ? , requestHeader ? ? if (responseHeader == null) { responseHeader = new EgovWebServiceMessageHeader(requestMessage.getHeader()); } return new EgovWebServiceMessage(responseHeader, responseBody); } else { // ? parsing if (responseHeader == null) { responseHeader = new EgovWebServiceMessageHeader(requestMessage.getHeader()); } responseHeader.setResultCode(ResultCode.FAIL_IN_PARSING_RESPONSE_MESSAGE); return new EgovWebServiceMessage(responseHeader, responseBody); } }
From source file:kms.prolog.comms.TransportServlet.java
public TransportServiceImpl getTransportModuleWebService(String transportId) throws ServiceException, MalformedURLException { if (transportId != null) { Transport transport = transportManager.findById(transportId); String wsdlURL = transport.getWsdl(); String namespace = transport.getNamespace(); String serviceName = transport.getServiceName(); String portName = transport.getPortName(); QName serviceQN = new QName(namespace, serviceName); QName portQN = new QName(namespace, portName); Service requestedService = Service.create(new URL(wsdlURL), serviceQN); TransportServiceImpl port = (TransportServiceImpl) requestedService.getPort(portQN, TransportServiceImpl.class); return port; } else {//from w w w.j av a 2s . com return null; } }
From source file:eu.planets_project.tb.impl.services.mockups.workflow.WorkflowDroidXCDLExtractorComparator.java
/** * Runs droid on a given File and returns an Array of PronomIDs * @param f1/*from w w w . j a v a 2 s .c o m*/ * @return * @throws Exception */ private String[] runDroid(File f1) throws Exception { //Step1: identify using droid - returns a status and a list of IDs URL url = null; try { url = new URL(URL_DROID); } catch (MalformedURLException e) { e.printStackTrace(); throw e; } Service service = Service.create(url, new QName(PlanetsServices.NS, Identify.NAME)); Identify droid = service.getPort(Identify.class); byte[] array = FileUtils.readFileToByteArray(f1); //invoke the service and extract results IdentifyResult identify = droid.identify(new DigitalObject.Builder(Content.byValue(array)).build(), null); List<URI> result = identify.getTypes(); String status = identify.getReport().getMessage(); if (!status.equals("Positive")) { throw new Exception("Service execution failed"); } if (result.size() < 1) { throw new Exception("The specified file type is currently not supported by this workflow"); } String[] strings = new String[result.size()]; for (int i = 0; i < result.size(); i++) { String string = result.get(i).toASCIIString(); //received 1..n Pronom IDs strings[i] = string; } return strings; }
From source file:eu.planets_project.tb.impl.services.mockups.workflow.WorkflowDroidXCDLExtractorComparator.java
/** * Runs the XCDL extractor on a given file and for a given xcel descriptor * Returns the XCDL description (UTF-8 encoded) for the provided file * @param f1/*from w w w.ja v a 2 s . c o m*/ * @param xcel * @return * @throws Exception */ private String runXCDLExtractor(File f1 /*, String xcel*/) throws Exception { URL url = null; try { url = new URL(URL_XCDLEXTRACTOR); Service service = Service.create(url, new QName(PlanetsServices.NS, Migrate.NAME)); Migrate extractor = service.getPort(Migrate.class); //the service's input byte[] array = FileUtils.readFileToByteArray(f1); //the service call and it's result DigitalObject digitalObject = extractor .migrate(new DigitalObject.Builder(Content.byValue(array)).build(), null, null, null) .getDigitalObject(); byte[] results = IOUtils.toByteArray(digitalObject.getContent().getInputStream()); String xcdl = new String(results, "UTF-8"); if (xcdl == null) { throw new Exception("XCDL extraction failed - please check service logs for details"); } return xcdl; } catch (MalformedURLException e) { e.printStackTrace(); throw e; } catch (UnsupportedEncodingException e) { //xcel file was not UTF-8 encodable e.printStackTrace(); throw e; } catch (PlanetsException e) { //error calling the web-service e.printStackTrace(); throw e; } }
From source file:eu.planets_project.tb.impl.services.mockups.workflow.WorkflowDroidXCDLExtractorComparator.java
/** * Runs the XCDLComparator on two given xcdls and returns the comparison result. * @param xcdl1//from w ww .j a v a2 s. co m * @param xcdl2 * @return * @throws Exception */ private String runXCDLComparator(String xcdl1, String xcdl2) throws Exception { URL url = null; try { url = new URL(URL_XCDLCOMPARATOR); Service service = Service.create(url, new QName(PlanetsServices.NS, Compare.NAME)); Compare comparator = service.getPort(Compare.class); //the service call and it's result DigitalObject x1 = new DigitalObject.Builder(Content.byValue(xcdl1.getBytes())).build(); DigitalObject x2 = new DigitalObject.Builder(Content.byValue(xcdl2.getBytes())).build(); List<Property> result = comparator.compare(x1, x2, null).getProperties(); if (result == null) { throw new Exception("XCDL comparison failed - please check service logs for details"); } return result.toString(); } catch (MalformedURLException e) { e.printStackTrace(); throw e; } }
From source file:com.mirth.connect.connectors.ws.WebServiceMessageDispatcher.java
private void createDispatch(MessageObject mo) throws Exception { String wsdlUrl = replacer.replaceValues(connector.getDispatcherWsdlUrl(), mo); String username = replacer.replaceValues(connector.getDispatcherUsername(), mo); String password = replacer.replaceValues(connector.getDispatcherPassword(), mo); String serviceName = replacer.replaceValues(connector.getDispatcherService(), mo); String portName = replacer.replaceValues(connector.getDispatcherPort(), mo); /*/*from w ww. ja v a 2s . com*/ * The dispatch needs to be created if it hasn't been created yet * (null). It needs to be recreated if any of the above variables are * different than what were used to create the current dispatch object. * This could happen if variables are being used for these properties. */ if (dispatch == null || !StringUtils.equals(wsdlUrl, currentWsdlUrl) || !StringUtils.equals(username, currentUsername) || !StringUtils.equals(password, currentPassword) || !StringUtils.equals(serviceName, currentServiceName) || !StringUtils.equals(portName, currentPortName)) { currentWsdlUrl = wsdlUrl; currentUsername = username; currentPassword = password; currentServiceName = serviceName; currentPortName = portName; URL endpointUrl = getWsdlUrl(wsdlUrl, username, password); QName serviceQName = QName.valueOf(serviceName); QName portQName = QName.valueOf(portName); // create the service and dispatch logger.debug("Creating web service: url=" + endpointUrl.toString() + ", service=" + serviceQName + ", port=" + portQName); Service service = Service.create(endpointUrl, serviceQName); dispatch = service.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE); } }
From source file:com.mirth.connect.connectors.ws.WebServiceDispatcher.java
private void createDispatch(WebServiceDispatcherProperties webServiceDispatcherProperties, DispatchContainer dispatchContainer) throws Exception { String wsdlUrl = webServiceDispatcherProperties.getWsdlUrl(); String username = webServiceDispatcherProperties.getUsername(); String password = webServiceDispatcherProperties.getPassword(); String serviceName = webServiceDispatcherProperties.getService(); String portName = webServiceDispatcherProperties.getPort(); /*//from w w w. j av a 2 s . co m * The dispatch needs to be created if it hasn't been created yet (null). It needs to be * recreated if any of the above variables are different than what were used to create the * current dispatch object. This could happen if variables are being used for these * properties. */ if (dispatchContainer.getDispatch() == null || !StringUtils.equals(wsdlUrl, dispatchContainer.getCurrentWsdlUrl()) || !StringUtils.equals(username, dispatchContainer.getCurrentUsername()) || !StringUtils.equals(password, dispatchContainer.getCurrentPassword()) || !StringUtils.equals(serviceName, dispatchContainer.getCurrentServiceName()) || !StringUtils.equals(portName, dispatchContainer.getCurrentPortName())) { dispatchContainer.setCurrentWsdlUrl(wsdlUrl); dispatchContainer.setCurrentUsername(username); dispatchContainer.setCurrentPassword(password); dispatchContainer.setCurrentServiceName(serviceName); dispatchContainer.setCurrentPortName(portName); URL endpointUrl = getWsdlUrl(dispatchContainer); QName serviceQName = QName.valueOf(serviceName); QName portQName = QName.valueOf(portName); // create the service and dispatch logger.debug("Creating web service: url=" + endpointUrl.toString() + ", service=" + serviceQName + ", port=" + portQName); Service service = Service.create(endpointUrl, serviceQName); Dispatch<SOAPMessage> dispatch = service.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE); if (timeout > 0) { dispatch.getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", timeout); dispatch.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", timeout); dispatch.getRequestContext().put("com.sun.xml.ws.connect.timeout", timeout); dispatch.getRequestContext().put("com.sun.xml.ws.request.timeout", timeout); } Map<String, List<String>> requestHeaders = (Map<String, List<String>>) dispatch.getRequestContext() .get(MessageContext.HTTP_REQUEST_HEADERS); if (requestHeaders == null) { requestHeaders = new HashMap<String, List<String>>(); } dispatchContainer.setDefaultRequestHeaders(requestHeaders); dispatchContainer.setDispatch(dispatch); } }
From source file:at.gv.egovernment.moa.id.protocols.stork2.attributeproviders.SignedDocAttributeRequestProvider.java
/** * Get document from DTL/*from www . j a v a 2s .com*/ * @param transferRequest The transfer request (attribute query) * @param eDtlUrl The DTL url of external DTL * @return the document data * @throws SimpleException */ private byte[] getDocumentFromDtl(String transferRequest, String eDtlUrl) throws Exception { URL url = null; try { Logger.debug("getDocumentFromDtl:" + dtlUrl); url = new URL(dtlUrl); QName qname = new QName("http://stork.eu", "DocumentService"); Service service = Service.create(url, qname); DocumentService docservice = service.getPort(DocumentService.class); BindingProvider bp = (BindingProvider) docservice; SOAPBinding binding = (SOAPBinding) bp.getBinding(); binding.setMTOMEnabled(true); if (eDtlUrl.equalsIgnoreCase(dtlUrl)) return docservice.getDocument(transferRequest, ""); else return docservice.getDocument(transferRequest, eDtlUrl); } catch (Exception e) { e.printStackTrace(); throw new Exception("Error in getDocumentFromDtl", e); } }