List of usage examples for javax.xml.ws Service getPort
public <T> T getPort(Class<T> serviceEndpointInterface)
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 om * @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.pp.plato.services.action.planets.PlanetsMigrationService.java
/** * Performs the preservation action.// w w w . j a va 2 s . c o m * * For Planets migration services url in {@link PreservationActionDefinition} carries the wsdl location of the migration service. */ public boolean perform(PreservationActionDefinition action, SampleObject sampleObject) throws PlatoServiceException { URL wsdlLocation; try { wsdlLocation = new URL(action.getUrl()); } catch (MalformedURLException e1) { e1.printStackTrace(); return false; } Service service = null; try { service = Service.create(wsdlLocation, Migrate.QNAME); } catch (WebServiceException e) { throw new PlatoServiceException("Error creating web service.", e); } Migrate m = (Migrate) service.getPort(Migrate.class); // create digital object that contains our sample object DigitalObject dob = new DigitalObject.Builder(Content.byValue(sampleObject.getData().getData())) .title("data").build(); FormatRegistry formatRegistry = FormatRegistryFactory.getFormatRegistry(); // create Planets URI from extension URI sourceFormat = formatRegistry.createExtensionUri(sampleObject.getFormatInfo().getDefaultExtension()); URI targetFormat; try { targetFormat = new URI(action.getTargetFormat()); } catch (URISyntaxException e) { throw new PlatoServiceException("Error in target format.", e); } List<Parameter> serviceParams = getParameters(action.getParamByName("settings")); if (serviceParams.size() <= 0) { serviceParams = null; } // perform migration MigrateResult result = m.migrate(dob, sourceFormat, targetFormat, serviceParams); MigrationResult migrationResult = new MigrationResult(); migrationResult.setSuccessful((result != null) && (result.getDigitalObject() != null)); if (migrationResult.isSuccessful()) { migrationResult.setReport(String.format("Service %s successfully migrated object.", wsdlLocation)); } else { migrationResult.setReport(String.format( "Service %s failed migrating object. " + ((result == null) ? "" : result.getReport()), wsdlLocation)); lastResult = migrationResult; return true; } InputStream in = result.getDigitalObject().getContent().getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] b = new byte[1024]; try { while ((in.read(b)) != -1) { out.write(b); } } catch (IOException e) { throw new PlatoServiceException("Unable to read result data from service response.", e); } migrationResult.getMigratedObject().getData().setData(out.toByteArray()); String fullName = sampleObject.getFullname(); String ext; try { ext = formatRegistry.getFirstExtension(new URI(action.getTargetFormat())); } catch (URISyntaxException e) { ext = ""; } // if we find an extension, cut if off ... if (fullName.lastIndexOf('.') > 0) { fullName = fullName.substring(0, fullName.lastIndexOf('.')); } // ... so we can append the new one. if (!"".equals(ext)) { fullName += ("." + ext); } migrationResult.getMigratedObject().setFullname(fullName); lastResult = migrationResult; return true; }
From source file:at.gv.egovernment.moa.id.protocols.stork2.attributeproviders.SignedDocAttributeRequestProvider.java
/** * Get mime type of document from DTL//from w w w . ja va2 s . c o m * @param docId The document id * @param dtlUrl The url of dtl * @return The mime type */ private String getDocumentMimeFromDtl(String docId, String eDtlUrl) throws Exception { URL url = null; try { 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.getDocumentMime(docId, ""); else return docservice.getDocumentMime(docId, eDtlUrl); } catch (Exception e) { e.printStackTrace(); throw new Exception("Error in getDocumentFromDtl", e); } }
From source file:at.gv.egovernment.moa.id.protocols.stork2.attributeproviders.SignedDocAttributeRequestProvider.java
/** * Update document in DTL/*from w w w. j ava 2 s.co m*/ * @param docData The docment data * @param docId The document ID * @param signResponse The signature response * @return True if successful * @throws SimpleException */ private boolean updateDocumentInDtl(byte[] docData, String docId, String signResponse) throws Exception { boolean success = false; URL url = null; try { 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); success = docservice.updateDocument(docId, signResponse, docData); } catch (Exception e) { e.printStackTrace(); throw new Exception("Error in updateDocumentInDtl", e); } return success; }
From source file:at.gv.egovernment.moa.id.protocols.stork2.attributeproviders.SignedDocAttributeRequestProvider.java
/** * Get document from DTL//from w w w . java 2s. c o m * @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); } }
From source file:at.gv.egovernment.moa.id.auth.servlet.PEPSConnectorServlet.java
/** * Get document from DTL/*from ww w. ja va 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:'" + dtlUrl + "' eDtlUrl:'" + eDtlUrl + "'"); 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); } }
From source file:com.moss.rpcutil.proxy.jaxws.JAXWSProxyProvider.java
public synchronized <T> T getProxy(Class<T> iface, String url) { QName type = registry.get(iface); if (type == null) { throw new RuntimeException("Service type not registered: " + iface); }// w w w.j a va2s . com T proxy = (T) cache.get(url); if (proxy == null) { Service service; try { String wsdlLocation = url; if (!wsdlLocation.endsWith("?wsdl")) { wsdlLocation += "?wsdl"; } service = Service.create(new URL(wsdlLocation), type); } catch (Exception ex) { throw new RuntimeException(ex); } if (log.isDebugEnabled()) { // SOAP LOGGING STUFF service.setHandlerResolver(new HandlerResolver() { public List<Handler> getHandlerChain(PortInfo arg0) { List<Handler> handlers = new LinkedList<Handler>(); handlers.add(new SOAPLoggingHandler(log)); return handlers; } }); } proxy = service.getPort(iface); // BindingProvider bp = (BindingProvider) proxy; // // bp.getRequestContext().put( // MessageContext.HTTP_REQUEST_HEADERS, // Collections.singletonMap("Content-Type", Arrays.asList(new String[]{"application/soap+xml", "charset=utf-8"})) // ); cache.put(url, proxy); } return proxy; }
From source file:org.apache.cxf.systest.jaxrs.JAXRSSoapBookTest.java
@Test public void testHelloSoap() throws Exception { final QName serviceName = new QName("http://hello.com", "HelloWorld"); final QName portName = new QName("http://hello.com", "HelloWorldPort"); final String address = "http://localhost:" + PORT + "/test/services/hello-soap"; Service service = Service.create(serviceName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address); HelloWorld hw = service.getPort(HelloWorld.class); useHelloService(hw);// w w w. ja va 2 s. co m }
From source file:org.apache.cxf.systest.jaxrs.JAXRSSoapBookTest.java
private void doTestHelloSoapCustomDataBinding(String address) throws Exception { final QName serviceName = new QName("http://hello.com", "HelloWorld"); final QName portName = new QName("http://hello.com", "HelloWorldPort"); Service service = Service.create(serviceName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address); HelloWorld hw = service.getPort(HelloWorld.class); Client cl = ClientProxy.getClient(hw); HTTPConduit http = (HTTPConduit) cl.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(0); httpClientPolicy.setReceiveTimeout(0); http.setClient(httpClientPolicy);//from w w w . j a v a 2 s.c om User user = new UserImpl("Barry"); User user2 = hw.echoUser(user); assertNotSame(user, user2); assertEquals("Barry", user2.getName()); }
From source file:org.apache.axis2.jaxws.description.impl.EndpointDescriptionImpl.java
public Port getWSDLPort() { javax.wsdl.Service service = getWSDLService(); if (service != null) { return service.getPort(getPortQName().getLocalPart()); } else {//w w w . ja v a 2 s. c o m return null; } }